mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-19 11:52:20 -06:00
feat(template): add edit/delete endpoints, DTOs and validation"
This commit is contained in:
35
src/validate/templateEdit.schema.ts
Normal file
35
src/validate/templateEdit.schema.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { JSONSchema7 } from 'json-schema';
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
|
||||
const properties: Record<string, unknown> = {};
|
||||
propertyNames.forEach(
|
||||
(property) =>
|
||||
(properties[property] = {
|
||||
minLength: 1,
|
||||
description: `The "${property}" cannot be empty`,
|
||||
}),
|
||||
);
|
||||
return {
|
||||
if: {
|
||||
propertyNames: {
|
||||
enum: [...propertyNames],
|
||||
},
|
||||
},
|
||||
then: { properties },
|
||||
} as JSONSchema7;
|
||||
};
|
||||
|
||||
export const templateEditSchema: JSONSchema7 = {
|
||||
$id: v4(),
|
||||
type: 'object',
|
||||
properties: {
|
||||
templateId: { type: 'string' },
|
||||
category: { type: 'string', enum: ['AUTHENTICATION', 'MARKETING', 'UTILITY'] },
|
||||
allowCategoryChange: { type: 'boolean' },
|
||||
ttl: { type: 'number' },
|
||||
components: { type: 'array' },
|
||||
},
|
||||
required: ['templateId'],
|
||||
...isNotEmpty('templateId'),
|
||||
};
|
||||
Reference in New Issue
Block a user