reest
Version:
A library inspired by NestJS's elegance, specifically designed for efficient serverless API development on AWS Lambda. It streamlines the creation of microservices with automated Swagger documentation and enhanced decorator-based middleware support, makin
37 lines (32 loc) • 938 B
text/typescript
import { returnType } from "../utils/ReturnType";
export function Body() {
return function (
target: Object,
propertyKey: string | symbol,
parameterIndex: number
) {
const type = Reflect.getMetadata("design:paramtypes", target, propertyKey)[
parameterIndex
];
const parameterType: any = returnType(type) || { type: "object" };
if (parameterType.type !== "object") {
throw new Error("Body parameter must be an object");
}
const metadataKey = `__bodyParameter__${String(propertyKey)}`;
const existingParameters =
Reflect.getOwnMetadata(metadataKey, target, propertyKey) || [];
const paramInfo = {
type: "body",
paramName: "body",
parameterIndex,
options: { type: parameterType },
};
existingParameters.push(paramInfo);
Reflect.defineMetadata(
metadataKey,
existingParameters,
target,
propertyKey
);
};
}