@cofondateurauchomage/libs 1.1.128 → 1.1.131
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/api.validate.js
CHANGED
|
@@ -6,12 +6,18 @@ const zod_1 = require("zod");
|
|
|
6
6
|
const const_1 = require("./const");
|
|
7
7
|
const regex_1 = require("./regex");
|
|
8
8
|
const utils_1 = require("./utils");
|
|
9
|
+
const withNeverMind = (a) => [...a, 'never_mind'];
|
|
9
10
|
const zSkill = zod_1.z.enum(const_1.SKILLS);
|
|
10
11
|
const zProjectStatus = zod_1.z.enum(const_1.PROJECT_STATUS);
|
|
12
|
+
const zProjectStatusWithNeverMind = zod_1.z.enum(withNeverMind(const_1.PROJECT_STATUS));
|
|
11
13
|
const zAmbition = zod_1.z.enum(const_1.AMBITIONS);
|
|
14
|
+
const zAmbitionWithNeverMind = zod_1.z.enum(withNeverMind(const_1.AMBITIONS));
|
|
12
15
|
const zProductType = zod_1.z.enum(const_1.PRODUCT_TYPES);
|
|
16
|
+
const zProductTypeWithNeverMind = zod_1.z.enum(withNeverMind(const_1.PRODUCT_TYPES));
|
|
13
17
|
const zIndustry = zod_1.z.enum(const_1.INDUSTRIES);
|
|
18
|
+
const zIndustryWithNeverMind = zod_1.z.enum(withNeverMind(const_1.INDUSTRIES));
|
|
14
19
|
const zAvailability = zod_1.z.enum(const_1.AVAILABILITY);
|
|
20
|
+
const zAvailabilityWithNeverMind = zod_1.z.enum(withNeverMind(const_1.AVAILABILITY));
|
|
15
21
|
const zVisibility = zod_1.z.enum(const_1.VISIBILITIES);
|
|
16
22
|
const zName = zod_1.z.string().regex(regex_1.RGX.Name.regex);
|
|
17
23
|
const zStrMax50 = zod_1.z.string().max(50);
|
|
@@ -46,7 +52,7 @@ const projectBody = {
|
|
|
46
52
|
industries: zod_1.z.array(zIndustry).optional(),
|
|
47
53
|
skills: zSkillsRequired,
|
|
48
54
|
yearsOfExperience: zod_1.z.number().min(0).max(100).optional(),
|
|
49
|
-
availability:
|
|
55
|
+
availability: zAvailabilityWithNeverMind.optional(),
|
|
50
56
|
city: zName,
|
|
51
57
|
invest: zod_1.z.number().min(0).max(1_000_000).optional(),
|
|
52
58
|
partner: zStrMax1000.optional(),
|
|
@@ -64,10 +70,10 @@ const userBody = {
|
|
|
64
70
|
partner: zStrMax1000.optional(),
|
|
65
71
|
business: zStrMax1000.optional(),
|
|
66
72
|
bestStrength: zStrMax1000.optional(),
|
|
67
|
-
projectStatus: zod_1.z.array(
|
|
68
|
-
ambitions: zod_1.z.array(
|
|
69
|
-
productTypes: zod_1.z.array(
|
|
70
|
-
industries: zod_1.z.array(
|
|
73
|
+
projectStatus: zod_1.z.array(zProjectStatusWithNeverMind).optional(),
|
|
74
|
+
ambitions: zod_1.z.array(zAmbitionWithNeverMind).optional(),
|
|
75
|
+
productTypes: zod_1.z.array(zProductTypeWithNeverMind).optional(),
|
|
76
|
+
industries: zod_1.z.array(zIndustryWithNeverMind).optional(),
|
|
71
77
|
photo: zod_1.z.string().optional(),
|
|
72
78
|
};
|
|
73
79
|
function throwFromZodError(error) {
|
|
@@ -142,12 +148,12 @@ const schemasForAllRoutes = {
|
|
|
142
148
|
status: zProjectStatus.optional(),
|
|
143
149
|
status_detail: zStrMax1000.optional(),
|
|
144
150
|
turnover: zod_1.z.number().min(0).optional(),
|
|
145
|
-
ambitions: zod_1.z.array(
|
|
146
|
-
productTypes: zod_1.z.array(
|
|
147
|
-
industries: zod_1.z.array(
|
|
151
|
+
ambitions: zod_1.z.array(zAmbitionWithNeverMind).optional(),
|
|
152
|
+
productTypes: zod_1.z.array(zProductTypeWithNeverMind).optional(),
|
|
153
|
+
industries: zod_1.z.array(zIndustryWithNeverMind).optional(),
|
|
148
154
|
skills: zSkillsOptional,
|
|
149
155
|
yearsOfExperience: zod_1.z.number().min(0).max(100).optional(),
|
|
150
|
-
availability:
|
|
156
|
+
availability: zAvailabilityWithNeverMind.optional(),
|
|
151
157
|
city: zName.optional(),
|
|
152
158
|
invest: zod_1.z.number().min(0).max(1_000_000).optional(),
|
|
153
159
|
partner: zStrMax1000.optional(),
|
|
@@ -156,7 +162,7 @@ const schemasForAllRoutes = {
|
|
|
156
162
|
motivations: zStrMax1000.optional(),
|
|
157
163
|
business: zStrMax1000.optional(),
|
|
158
164
|
bestStrength: zStrMax1000.optional(),
|
|
159
|
-
projectStatus: zod_1.z.array(
|
|
165
|
+
projectStatus: zod_1.z.array(zProjectStatusWithNeverMind).optional(),
|
|
160
166
|
email: zod_1.z.string(),
|
|
161
167
|
tel: zTel.optional(),
|
|
162
168
|
linkedin: zLinkedin.optional(),
|
|
@@ -206,7 +212,7 @@ function validateBodyForO(route, body) {
|
|
|
206
212
|
if (typeof body !== "object" || body === null) {
|
|
207
213
|
throw new ValidationError(400, "Le payload est requis");
|
|
208
214
|
}
|
|
209
|
-
const cleanedBody = (0, utils_1.cleanObject)(body, { keepNull: true });
|
|
215
|
+
const cleanedBody = (0, utils_1.cleanObject)(body, { keepNull: true, keepEmptyArrays: true });
|
|
210
216
|
const schema = schemasForAllRoutes[route];
|
|
211
217
|
const parsed = schema.safeParse(cleanedBody);
|
|
212
218
|
if (!parsed.success) {
|
|
@@ -21,6 +21,7 @@ type Cleaned<T> = {
|
|
|
21
21
|
export declare function cleanObject<T extends object>(obj: T, options?: {
|
|
22
22
|
recursive?: boolean;
|
|
23
23
|
keepNull?: boolean;
|
|
24
|
+
keepEmptyArrays?: boolean;
|
|
24
25
|
}): Cleaned<T>;
|
|
25
26
|
export declare function deepEqual<T>(obj1: T, obj2: T): boolean;
|
|
26
27
|
export {};
|
|
@@ -48,7 +48,7 @@ function cleanObject(obj, options) {
|
|
|
48
48
|
if (cleanedValue !== "" &&
|
|
49
49
|
cleanedValue !== undefined &&
|
|
50
50
|
(options?.keepNull || cleanedValue !== null) &&
|
|
51
|
-
(!Array.isArray(cleanedValue) || (0, arrayUtils_1.compact)(cleanedValue).length > 0) &&
|
|
51
|
+
(options?.keepEmptyArrays || !Array.isArray(cleanedValue) || (0, arrayUtils_1.compact)(cleanedValue).length > 0) &&
|
|
52
52
|
(!isObject(cleanedValue) || Object.keys(cleanedValue).length > 0)) {
|
|
53
53
|
result[key] = cleanedValue;
|
|
54
54
|
}
|