mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-09 17:33:55 +00:00
c5870452e3
* remove custom field lowercasing * don't allow custom field form to submit duplicate field * remove unused * update custom field tests * also keep upper case when editing * show key in UI * also kep upper case when creating a new field * fix test * allow old forced case keys to stay as is * allow space * add extension to import * supply initial key to CustomFieldForm * refactor: improve element contrast * refactor: style and composition * consistent use of `customFieldLabelToKey` * fix CopyTag * remove log --------- Co-authored-by: arc-alex <ac@omnivox.dk> Co-authored-by: Carlos Valente <carlosvalente@pm.me>
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { isAlphanumericWithSpace } from 'ontime-utils';
|
|
|
|
import { Request, Response, NextFunction } from 'express';
|
|
import { body, param, validationResult } from 'express-validator';
|
|
|
|
export const validateCustomField = [
|
|
body('label')
|
|
.exists()
|
|
.isString()
|
|
.trim()
|
|
.custom((value) => {
|
|
return isAlphanumericWithSpace(value);
|
|
}),
|
|
body('type').exists().isString().trim(),
|
|
body('colour').exists().isString().trim(),
|
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
const errors = validationResult(req);
|
|
if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });
|
|
next();
|
|
},
|
|
];
|
|
|
|
export const validateEditCustomField = [
|
|
param('label').exists().isString().trim(),
|
|
body('label').exists().isString().trim(),
|
|
body('type').exists().isString().trim(),
|
|
body('colour').exists().isString().trim(),
|
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
const errors = validationResult(req);
|
|
if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });
|
|
next();
|
|
},
|
|
];
|
|
|
|
export const validateDeleteCustomField = [
|
|
param('label').exists().isString(),
|
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
const errors = validationResult(req);
|
|
if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });
|
|
next();
|
|
},
|
|
];
|