-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Body.ts
30 lines (28 loc) · 1.03 KB
/
Body.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { getOrSetControllerId } from "../metadata/controller.ts";
import { getMetadataArgsStorage } from "../mod.ts";
import { ParamType } from "../types/param.ts";
import { RequestBodyParseOptions } from "../models/request.ts";
import { ClassMethodDecoratorContext } from "./decorator.models.ts";
/**
* Injects a Body object to the controller action parameter.
* Must be applied on a controller action parameter.
* @transform - may by transform function or class for global transform, see validator example
* @options - RequestBodyParseOptions
*/
export function Body(
transform?: any,
options?: RequestBodyParseOptions,
): Function {
return function (object: Object, context: ClassMethodDecoratorContext, index: number) {
const controllerId = getOrSetControllerId(context);
getMetadataArgsStorage().params.push({
type: ParamType.Body,
target: object.constructor,
method: context.name as string,
index: index,
transform,
bodyParseOptions: options,
controllerId: controllerId,
});
};
}