@nest-extended/decorators 0.0.2-beta-12 → 0.0.2-beta-13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nest-extended/decorators",
3
- "version": "0.0.2-beta-12",
3
+ "version": "0.0.2-beta-13",
4
4
  "private": false,
5
5
  "contributors": [
6
6
  {
@@ -1,7 +1,8 @@
1
1
  import { Request as ExRequest } from 'express-serve-static-core';
2
- export declare type RequestBody = {
3
- user: any;
4
- } & ExRequest;
5
- export declare type ModifyBodyFn = (request: RequestBody) => RequestBody;
2
+ export type RequestBody<TBody extends Record<string, any> = Record<string, any>, TUser = any> = Omit<ExRequest, 'body' | 'user'> & {
3
+ user: TUser;
4
+ body: TBody;
5
+ };
6
+ export type ModifyBodyFn<TBody extends Record<string, any> = Record<string, any>, TUser = any> = (request: RequestBody<TBody, TUser>) => RequestBody<TBody, TUser>;
6
7
  export declare const setCreatedBy: (key?: string) => ModifyBodyFn;
7
- export declare const ModifyBody: (...dataOrPipes: (ModifyBodyFn | ModifyBodyFn[] | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>> | undefined)[]) => ParameterDecorator;
8
+ export declare const ModifyBody: (...fns: Array<ModifyBodyFn<any, any> | undefined>) => ParameterDecorator;
@@ -3,18 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ModifyBody = exports.setCreatedBy = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const setCreatedBy = (key = 'createdBy') => (request) => {
6
- request.body[key] = request.user._id;
6
+ var _a;
7
+ request.body[key] = (_a = request.user) === null || _a === void 0 ? void 0 : _a._id;
7
8
  return request;
8
9
  };
9
10
  exports.setCreatedBy = setCreatedBy;
10
- exports.ModifyBody = (0, common_1.createParamDecorator)((fn, ctx) => {
11
+ const ModifyBodyInner = (0, common_1.createParamDecorator)((fns, ctx) => {
11
12
  const request = ctx.switchToHttp().getRequest();
12
- if (Array.isArray(fn)) {
13
- fn.forEach((f) => f === null || f === void 0 ? void 0 : f(request));
13
+ if (Array.isArray(fns)) {
14
+ fns.forEach((f) => f === null || f === void 0 ? void 0 : f(request));
14
15
  }
15
16
  else {
16
- fn === null || fn === void 0 ? void 0 : fn(request);
17
+ // Fallback in case it's not an array, though our wrapper ensures it is
18
+ fns === null || fns === void 0 ? void 0 : fns(request);
17
19
  }
18
20
  return request.body;
19
21
  });
22
+ const ModifyBody = (...fns) => ModifyBodyInner(fns);
23
+ exports.ModifyBody = ModifyBody;
20
24
  //# sourceMappingURL=ModifyBody.decorator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ModifyBody.decorator.js","sourceRoot":"","sources":["../../../../packages/decorators/src/ModifyBody.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwE;AASjE,MAAM,YAAY,GACvB,CAAC,GAAG,GAAG,WAAW,EAAgB,EAAE,CACpC,CAAC,OAAoB,EAAE,EAAE;IACvB,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;IACrC,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AALS,QAAA,YAAY,gBAKrB;AAES,QAAA,UAAU,GAAG,IAAA,6BAAoB,EAC1C,CAAC,EAA6C,EAAE,GAAqB,EAAE,EAAE;IACrE,MAAM,OAAO,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;IAChD,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;QACpB,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAG,OAAO,CAAC,CAAC,CAAC;IACpC,CAAC;SAAM,CAAC;QACJ,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAG,OAAO,CAAC,CAAC;IAClB,CAAC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