mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-11 02:13:48 +00:00
refactor: add presets to refetch list
This commit is contained in:
committed by
Carlos Valente
parent
1ed08df198
commit
1695b4dc68
@@ -1,9 +1,10 @@
|
||||
import express from 'express';
|
||||
import type { Request, Response } from 'express';
|
||||
import type { ErrorResponse, URLPreset } from 'ontime-types';
|
||||
import { RefetchKey, type ErrorResponse, type URLPreset } from 'ontime-types';
|
||||
import { getErrorMessage } from 'ontime-utils';
|
||||
import { getDataProvider } from '../../classes/data-provider/DataProvider.js';
|
||||
import { validateNewPreset, validatePresetParam, validateUpdatePreset } from './urlPresets.validation.js';
|
||||
import { sendRefetch } from '../../adapters/WebsocketAdapter.js';
|
||||
|
||||
export const router = express.Router();
|
||||
|
||||
@@ -23,13 +24,14 @@ router.post('/', validateNewPreset, async (req: Request, res: Response<URLPreset
|
||||
|
||||
const currentPresets = getDataProvider().getUrlPresets();
|
||||
if (currentPresets.some((preset) => preset.alias === newPreset.alias)) {
|
||||
throw new Error(`Preset with alias "${newPreset.alias}" already exists.`);
|
||||
throw new Error(`Preset with alias ${newPreset.alias} already exists.`);
|
||||
}
|
||||
|
||||
const newPresets = [...currentPresets, newPreset];
|
||||
|
||||
// Update the URL presets in the data provider
|
||||
await getDataProvider().setUrlPresets(newPresets);
|
||||
sendRefetch(RefetchKey.UrlPresets);
|
||||
res.status(201).send(newPresets);
|
||||
} catch (error) {
|
||||
const message = getErrorMessage(error);
|
||||
@@ -56,6 +58,7 @@ router.put('/:alias', validateUpdatePreset, async (req: Request, res: Response<U
|
||||
|
||||
// Update the URL presets in the data provider
|
||||
await getDataProvider().setUrlPresets(newPresets);
|
||||
sendRefetch(RefetchKey.UrlPresets);
|
||||
res.status(200).send(newPresets);
|
||||
} catch (error) {
|
||||
const message = getErrorMessage(error);
|
||||
@@ -71,6 +74,7 @@ router.delete('/:alias', validatePresetParam, async (req: Request, res: Response
|
||||
|
||||
// Update the URL presets in the data provider
|
||||
await getDataProvider().setUrlPresets(newPresets);
|
||||
sendRefetch(RefetchKey.UrlPresets);
|
||||
res.status(200).send(newPresets);
|
||||
} catch (error) {
|
||||
const message = getErrorMessage(error);
|
||||
|
||||
Reference in New Issue
Block a user