Skip to content

Commit 19f82c4

Browse files
committed
all good
1 parent 21ee9e7 commit 19f82c4

File tree

6 files changed

+278
-208
lines changed

6 files changed

+278
-208
lines changed

apps/api/src/error-dto.ts

+10-26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ApiProperty } from '@nestjs/swagger'; // Ensure you have the correct import for ApiProperty
1+
import { ApiExtraModels, ApiProperty, getSchemaPath } from '@nestjs/swagger'; // Ensure you have the correct import for ApiProperty
22
import { ConstraintValidation } from '@novu/application-generic';
33

44
export class ErrorDto {
@@ -49,36 +49,13 @@ export class ErrorDto {
4949
})
5050
errorId?: string;
5151
}
52-
52+
@ApiExtraModels(ConstraintValidation)
5353
export class ValidationErrorDto extends ErrorDto {
5454
@ApiProperty({
5555
description: 'A record of validation errors keyed by field name',
5656
type: 'object',
5757
additionalProperties: {
58-
type: 'object',
59-
properties: {
60-
messages: {
61-
type: 'array',
62-
items: { type: 'string' },
63-
},
64-
value: {
65-
oneOf: [
66-
{
67-
type: 'string',
68-
nullable: true, // Allows value to be null
69-
},
70-
{ type: 'number' },
71-
{ type: 'boolean' },
72-
{ type: 'object', additionalProperties: true },
73-
{ type: 'array', items: { type: 'object', additionalProperties: true } },
74-
],
75-
},
76-
},
77-
required: ['messages', 'value'],
78-
example: {
79-
messages: ['Field is required', 'Invalid format'],
80-
value: 'xx xx xx ',
81-
},
58+
$ref: getSchemaPath(ConstraintValidation),
8259
},
8360
example: {
8461
fieldName1: {
@@ -97,6 +74,13 @@ export class ValidationErrorDto extends ErrorDto {
9774
messages: ['Must be a valid object'],
9875
value: { key: 'value' },
9976
},
77+
fieldName5: {
78+
messages: ['Field is missing'],
79+
value: null,
80+
},
81+
fieldName6: {
82+
messages: ['Undefined value'],
83+
},
10084
},
10185
})
10286
errors: Record<string, ConstraintValidation>;

libs/application-generic/src/commands/base.command.ts

+31-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { plainToInstance } from 'class-transformer';
22
import { validateSync, ValidationError } from 'class-validator';
33
import { BadRequestException } from '@nestjs/common';
4+
import { ApiProperty } from '@nestjs/swagger';
45

56
export abstract class BaseCommand {
6-
static create<T extends BaseCommand>(
7-
this: new (...args: unknown[]) => T,
8-
data: T,
9-
): T {
7+
static create<T extends BaseCommand>(this: new (...args: unknown[]) => T, data: T): T {
108
const convertedObject = plainToInstance<T, unknown>(this, {
119
...data,
1210
});
@@ -22,14 +20,36 @@ export abstract class BaseCommand {
2220
}
2321

2422
export class ConstraintValidation {
23+
@ApiProperty({
24+
type: 'array',
25+
items: { type: 'string' },
26+
description: 'List of validation error messages',
27+
example: ['Field is required', 'Invalid format'],
28+
})
2529
messages: string[];
26-
value: any;
27-
}
2830

29-
function flattenErrors(
30-
errors: ValidationError[],
31-
prefix: string = '',
32-
): Record<string, ConstraintValidation> {
31+
@ApiProperty({
32+
required: false,
33+
description: 'Value that failed validation',
34+
oneOf: [
35+
{ type: 'string', nullable: true },
36+
{ type: 'number' },
37+
{ type: 'boolean' },
38+
{ type: 'object' },
39+
{
40+
type: 'array',
41+
items: {
42+
type: 'object',
43+
additionalProperties: true,
44+
},
45+
},
46+
],
47+
example: 'xx xx xx ',
48+
nullable: true,
49+
})
50+
value?: string | number | boolean | object | object[] | null;
51+
}
52+
function flattenErrors(errors: ValidationError[], prefix: string = ''): Record<string, ConstraintValidation> {
3353
const result: Record<string, ConstraintValidation> = {};
3454

3555
for (const error of errors) {
@@ -59,7 +79,7 @@ function flattenErrors(
5979
export class CommandValidationException extends BadRequestException {
6080
constructor(
6181
public className: string,
62-
public constraintsViolated: Record<string, ConstraintValidation>,
82+
public constraintsViolated: Record<string, ConstraintValidation>
6383
) {
6484
super({ message: 'Validation failed', className, constraintsViolated });
6585
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
/*
2+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3+
*/
4+
5+
import * as z from "zod";
6+
import { safeParse } from "../../lib/schemas.js";
7+
import { Result as SafeParseResult } from "../../types/fp.js";
8+
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
9+
10+
export type Four = {};
11+
12+
/**
13+
* Value that failed validation
14+
*/
15+
export type Value =
16+
| Four
17+
| string
18+
| number
19+
| boolean
20+
| Array<{ [k: string]: any }>;
21+
22+
export type ConstraintValidation = {
23+
/**
24+
* List of validation error messages
25+
*/
26+
messages: Array<string>;
27+
/**
28+
* Value that failed validation
29+
*/
30+
value?:
31+
| Four
32+
| string
33+
| number
34+
| boolean
35+
| Array<{ [k: string]: any }>
36+
| null
37+
| undefined;
38+
};
39+
40+
/** @internal */
41+
export const Four$inboundSchema: z.ZodType<Four, z.ZodTypeDef, unknown> = z
42+
.object({});
43+
44+
/** @internal */
45+
export type Four$Outbound = {};
46+
47+
/** @internal */
48+
export const Four$outboundSchema: z.ZodType<Four$Outbound, z.ZodTypeDef, Four> =
49+
z.object({});
50+
51+
/**
52+
* @internal
53+
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
54+
*/
55+
export namespace Four$ {
56+
/** @deprecated use `Four$inboundSchema` instead. */
57+
export const inboundSchema = Four$inboundSchema;
58+
/** @deprecated use `Four$outboundSchema` instead. */
59+
export const outboundSchema = Four$outboundSchema;
60+
/** @deprecated use `Four$Outbound` instead. */
61+
export type Outbound = Four$Outbound;
62+
}
63+
64+
export function fourToJSON(four: Four): string {
65+
return JSON.stringify(Four$outboundSchema.parse(four));
66+
}
67+
68+
export function fourFromJSON(
69+
jsonString: string,
70+
): SafeParseResult<Four, SDKValidationError> {
71+
return safeParse(
72+
jsonString,
73+
(x) => Four$inboundSchema.parse(JSON.parse(x)),
74+
`Failed to parse 'Four' from JSON`,
75+
);
76+
}
77+
78+
/** @internal */
79+
export const Value$inboundSchema: z.ZodType<Value, z.ZodTypeDef, unknown> = z
80+
.union([
81+
z.lazy(() => Four$inboundSchema),
82+
z.string(),
83+
z.number(),
84+
z.boolean(),
85+
z.array(z.record(z.any())),
86+
]);
87+
88+
/** @internal */
89+
export type Value$Outbound =
90+
| Four$Outbound
91+
| string
92+
| number
93+
| boolean
94+
| Array<{ [k: string]: any }>;
95+
96+
/** @internal */
97+
export const Value$outboundSchema: z.ZodType<
98+
Value$Outbound,
99+
z.ZodTypeDef,
100+
Value
101+
> = z.union([
102+
z.lazy(() => Four$outboundSchema),
103+
z.string(),
104+
z.number(),
105+
z.boolean(),
106+
z.array(z.record(z.any())),
107+
]);
108+
109+
/**
110+
* @internal
111+
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
112+
*/
113+
export namespace Value$ {
114+
/** @deprecated use `Value$inboundSchema` instead. */
115+
export const inboundSchema = Value$inboundSchema;
116+
/** @deprecated use `Value$outboundSchema` instead. */
117+
export const outboundSchema = Value$outboundSchema;
118+
/** @deprecated use `Value$Outbound` instead. */
119+
export type Outbound = Value$Outbound;
120+
}
121+
122+
export function valueToJSON(value: Value): string {
123+
return JSON.stringify(Value$outboundSchema.parse(value));
124+
}
125+
126+
export function valueFromJSON(
127+
jsonString: string,
128+
): SafeParseResult<Value, SDKValidationError> {
129+
return safeParse(
130+
jsonString,
131+
(x) => Value$inboundSchema.parse(JSON.parse(x)),
132+
`Failed to parse 'Value' from JSON`,
133+
);
134+
}
135+
136+
/** @internal */
137+
export const ConstraintValidation$inboundSchema: z.ZodType<
138+
ConstraintValidation,
139+
z.ZodTypeDef,
140+
unknown
141+
> = z.object({
142+
messages: z.array(z.string()),
143+
value: z.nullable(
144+
z.union([
145+
z.lazy(() => Four$inboundSchema),
146+
z.string(),
147+
z.number(),
148+
z.boolean(),
149+
z.array(z.record(z.any())),
150+
]),
151+
).optional(),
152+
});
153+
154+
/** @internal */
155+
export type ConstraintValidation$Outbound = {
156+
messages: Array<string>;
157+
value?:
158+
| Four$Outbound
159+
| string
160+
| number
161+
| boolean
162+
| Array<{ [k: string]: any }>
163+
| null
164+
| undefined;
165+
};
166+
167+
/** @internal */
168+
export const ConstraintValidation$outboundSchema: z.ZodType<
169+
ConstraintValidation$Outbound,
170+
z.ZodTypeDef,
171+
ConstraintValidation
172+
> = z.object({
173+
messages: z.array(z.string()),
174+
value: z.nullable(
175+
z.union([
176+
z.lazy(() => Four$outboundSchema),
177+
z.string(),
178+
z.number(),
179+
z.boolean(),
180+
z.array(z.record(z.any())),
181+
]),
182+
).optional(),
183+
});
184+
185+
/**
186+
* @internal
187+
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
188+
*/
189+
export namespace ConstraintValidation$ {
190+
/** @deprecated use `ConstraintValidation$inboundSchema` instead. */
191+
export const inboundSchema = ConstraintValidation$inboundSchema;
192+
/** @deprecated use `ConstraintValidation$outboundSchema` instead. */
193+
export const outboundSchema = ConstraintValidation$outboundSchema;
194+
/** @deprecated use `ConstraintValidation$Outbound` instead. */
195+
export type Outbound = ConstraintValidation$Outbound;
196+
}
197+
198+
export function constraintValidationToJSON(
199+
constraintValidation: ConstraintValidation,
200+
): string {
201+
return JSON.stringify(
202+
ConstraintValidation$outboundSchema.parse(constraintValidation),
203+
);
204+
}
205+
206+
export function constraintValidationFromJSON(
207+
jsonString: string,
208+
): SafeParseResult<ConstraintValidation, SDKValidationError> {
209+
return safeParse(
210+
jsonString,
211+
(x) => ConstraintValidation$inboundSchema.parse(JSON.parse(x)),
212+
`Failed to parse 'ConstraintValidation' from JSON`,
213+
);
214+
}

libs/internal-sdk/src/models/components/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export * from "./channelsettingsdto.js";
3030
export * from "./channeltypeenum.js";
3131
export * from "./chatorpushproviderenum.js";
3232
export * from "./chatrenderoutput.js";
33+
export * from "./constraintvalidation.js";
3334
export * from "./controlsmetadata.js";
3435
export * from "./createdsubscriberdto.js";
3536
export * from "./createenvironmentrequestdto.js";

0 commit comments

Comments
 (0)