Skip to content

Commit f0f6e0a

Browse files
committed
feat: Add http code decorator
1 parent 48ada7b commit f0f6e0a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/adapter-express/express-utils/decorators.ts

+13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export function controller(path: string, ...middleware: Array<Middleware>) {
2828
target,
2929
};
3030

31+
const statusCode = Reflect.getOwnMetadata("status_code", target);
32+
Reflect.defineMetadata("status_code", statusCode, Reflect, path);
33+
3134
decorate(injectable(), target);
3235
Reflect.defineMetadata(METADATA_KEY.controller, currentMetadata, target);
3336

@@ -40,6 +43,16 @@ export function controller(path: string, ...middleware: Array<Middleware>) {
4043
};
4144
}
4245

46+
export function http(code: number) {
47+
return (
48+
target: object,
49+
key: string | symbol,
50+
descriptor: TypedPropertyDescriptor<any>,
51+
): void => {
52+
Reflect.defineMetadata("status_code", code, target.constructor);
53+
};
54+
}
55+
4356
/**
4457
* Decorator to allow accept all HTTP methods
4558
* @param path route path, wildcard

0 commit comments

Comments
 (0)