MCPcopy Create free account
hub / github.com/evolution-foundation/evolution-api / dataValidate

Function dataValidate

src/api/abstract/abstract.router.ts:29–63  ·  view source on GitHub ↗
(args: DataValidate<T>)

Source from the content-addressed store, hash-verified

27 }
28
29 public async dataValidate<T>(args: DataValidate<T>) {
30 const { request, schema, ClassRef, execute } = args;
31
32 const ref = new ClassRef();
33 const body = request.body;
34 const instance = request.params as unknown as InstanceDto;
35
36 if (request?.query && Object.keys(request.query).length > 0) {
37 Object.assign(instance, request.query);
38 }
39
40 if (request.originalUrl.includes('/instance/create')) {
41 Object.assign(instance, body);
42 }
43
44 Object.assign(ref, body);
45
46 const v = schema ? validate(ref, schema) : { valid: true, errors: [] };
47
48 if (!v.valid) {
49 const message: any[] = v.errors.map(({ stack, schema }) => {
50 let message: string;
51 if (schema['description']) {
52 message = schema['description'];
53 } else {
54 message = stack.replace('instance.', '');
55 }
56 return message;
57 });
58 logger.error(message);
59 throw new BadRequestException(message);
60 }
61
62 return await execute(instance, ref);
63 }
64
65 public async groupNoValidate<T>(args: DataValidate<T>) {
66 const { request, ClassRef, schema, execute } = args;

Callers

nothing calls this directly

Calls 2

errorMethod · 0.80
keysMethod · 0.65

Tested by

no test coverage detected