@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,7 +1,8 @@
|
|
|
1
1
|
import { Request as ExRequest } from 'express-serve-static-core';
|
|
2
|
-
export
|
|
3
|
-
user:
|
|
4
|
-
|
|
5
|
-
|
|
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: (...
|
|
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
|
-
|
|
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
|
-
|
|
11
|
+
const ModifyBodyInner = (0, common_1.createParamDecorator)((fns, ctx) => {
|
|
11
12
|
const request = ctx.switchToHttp().getRequest();
|
|
12
|
-
if (Array.isArray(
|
|
13
|
-
|
|
13
|
+
if (Array.isArray(fns)) {
|
|
14
|
+
fns.forEach((f) => f === null || f === void 0 ? void 0 : f(request));
|
|
14
15
|
}
|
|
15
16
|
else {
|
|
16
|
-
|
|
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;
|
|
1
|
+
{"version":3,"file":"ModifyBody.decorator.js","sourceRoot":"","sources":["../../../../packages/decorators/src/ModifyBody.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwE;AAgBjE,MAAM,YAAY,GACvB,CAAC,GAAG,GAAG,WAAW,EAAgB,EAAE,CACpC,CAAC,OAAO,EAAE,EAAE;;IACV,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,MAAA,OAAO,CAAC,IAAI,0CAAE,GAAG,CAAC;IACtC,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AALS,QAAA,YAAY,gBAKrB;AAEJ,MAAM,eAAe,GAAG,IAAA,6BAAoB,EAC1C,CAAC,GAA8C,EAAE,GAAqB,EAAE,EAAE;IACxE,MAAM,OAAO,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;IAChD,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACrB,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAG,OAAO,CAAC,CAAC,CAAC;IACrC,CAAC;SAAM,CAAC;QACJ,uEAAuE;QACtE,GAAW,aAAX,GAAG,uBAAH,GAAG,CAAW,OAAO,CAAC,CAAC;IAC5B,CAAC;IACD,OAAO,OAAO,CAAC,IAAI,CAAC;AACtB,CAAC,CACF,CAAC;AAEK,MAAM,UAAU,GAAG,CAAC,GAAG,GAA8C,EAAE,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;AAAzF,QAAA,UAAU,cAA+E"}
|