mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-04 15:08:01 +00:00
aebf949883
* refactor: create transaction system and apply to adding entry * refactor: migrate edit mutations to transaction * refactor: migrate delete mutation to transaction * refactor: migrate reorder mutation to transaction * refactor: migrate apply delay to transaction * refactor: migrate swapEvents to transaction * refactor: migrate clone to transaction * refactor: migrate group/ungroup transactions * refactor: simplify mutations * refactor: migrate getters * chore: add tests to processRundown()
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import { CustomField, CustomFields, ErrorResponse } from 'ontime-types';
|
|
|
|
import type { Request, Response } from 'express';
|
|
|
|
import { getErrorMessage } from 'ontime-utils';
|
|
|
|
import { createCustomField, editCustomField, removeCustomField } from '../../services/rundown-service/rundownCache.js';
|
|
|
|
import { getProjectCustomFields } from '../rundown/rundown.dao.js';
|
|
|
|
export async function getCustomFields(_req: Request, res: Response<CustomFields>) {
|
|
const customFields = getProjectCustomFields();
|
|
res.json(customFields);
|
|
}
|
|
|
|
export async function postCustomField(req: Request, res: Response<CustomFields | ErrorResponse>) {
|
|
try {
|
|
const newField = req.body as CustomField;
|
|
const allFields = await createCustomField(newField);
|
|
res.status(201).send(allFields);
|
|
} catch (error) {
|
|
const message = getErrorMessage(error);
|
|
res.status(400).send({ message });
|
|
}
|
|
}
|
|
|
|
export async function putCustomField(req: Request, res: Response<CustomFields | ErrorResponse>) {
|
|
try {
|
|
const oldLabel = req.params.label;
|
|
const { colour, type, label } = req.body;
|
|
const newFields = await editCustomField(oldLabel, { label, colour, type });
|
|
res.status(200).send(newFields);
|
|
} catch (error) {
|
|
const message = getErrorMessage(error);
|
|
res.status(400).send({ message });
|
|
}
|
|
}
|
|
|
|
// Expects { label: <label> }
|
|
export async function deleteCustomField(req: Request, res: Response<CustomFields | ErrorResponse>) {
|
|
try {
|
|
const fieldToDelete = req.params.label;
|
|
await removeCustomField(fieldToDelete);
|
|
res.sendStatus(204);
|
|
} catch (error) {
|
|
const message = getErrorMessage(error);
|
|
res.status(400).send({ message });
|
|
}
|
|
}
|