@cofondateurauchomage/libs 1.1.114 → 1.1.115

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.
@@ -197,12 +197,13 @@ function validateBodyForO(route, body) {
197
197
  if (typeof body !== "object" || body === null) {
198
198
  throw new ValidationError(400, "Le payload est requis");
199
199
  }
200
+ const cleanedBody = (0, utils_1.cleanObject)(body, { keepNull: true });
200
201
  const schema = schemasForAllRoutes[route];
201
- const parsed = schema.safeParse(body);
202
+ const parsed = schema.safeParse(cleanedBody);
202
203
  if (!parsed.success) {
203
204
  throwFromZodError(parsed.error);
204
205
  }
205
- const input = body;
206
+ const input = cleanedBody;
206
207
  const result = {};
207
208
  for (const key of Object.keys(schema.shape)) {
208
209
  if (input[key] !== undefined) {
@@ -20,6 +20,7 @@ type Cleaned<T> = {
20
20
  */
21
21
  export declare function cleanObject<T extends object>(obj: T, options?: {
22
22
  recursive?: boolean;
23
+ keepNull?: boolean;
23
24
  }): Cleaned<T>;
24
25
  export declare function deepEqual<T>(obj1: T, obj2: T): boolean;
25
26
  export {};
@@ -43,13 +43,13 @@ function cleanObject(obj, options) {
43
43
  const result = {};
44
44
  for (const [key, value] of typedObjectEntries(obj)) {
45
45
  const cleanedValue = isObject(value) && options?.recursive
46
- ? cleanObject(value, { recursive: true })
46
+ ? cleanObject(value, options)
47
47
  : value;
48
48
  if (cleanedValue !== "" &&
49
49
  cleanedValue !== undefined &&
50
- cleanedValue !== null &&
50
+ (options?.keepNull || cleanedValue !== null) &&
51
51
  (!Array.isArray(cleanedValue) || (0, arrayUtils_1.compact)(cleanedValue).length > 0) &&
52
- (!isObject(value) || Object.keys(cleanedValue).length > 0)) {
52
+ (!isObject(cleanedValue) || Object.keys(cleanedValue).length > 0)) {
53
53
  result[key] = cleanedValue;
54
54
  }
55
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cofondateurauchomage/libs",
3
- "version": "1.1.114",
3
+ "version": "1.1.115",
4
4
  "description": "",
5
5
  "main": "build/index",
6
6
  "scripts": {