forked from nestjs/nest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparam.utils.ts
More file actions
38 lines (35 loc) · 1.21 KB
/
Copy pathparam.utils.ts
File metadata and controls
38 lines (35 loc) · 1.21 KB
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
31
32
33
34
35
36
37
38
import { PipeTransform, Type } from '@nestjs/common';
import { assignMetadata } from '@nestjs/common/decorators/http/route-params.decorator';
import 'reflect-metadata';
import { PARAM_ARGS_METADATA } from '../constants';
import { RpcParamtype } from '../enums/rpc-paramtype.enum';
export function createRpcParamDecorator(
paramtype: RpcParamtype,
): (...pipes: (Type<PipeTransform> | PipeTransform)[]) => ParameterDecorator {
return (...pipes: (Type<PipeTransform> | PipeTransform)[]) => (
target,
key,
index,
) => {
const args =
Reflect.getMetadata(PARAM_ARGS_METADATA, target.constructor, key) || {};
Reflect.defineMetadata(
PARAM_ARGS_METADATA,
assignMetadata(args, paramtype, index, undefined, ...pipes),
target.constructor,
key,
);
};
}
export const createPipesRpcParamDecorator = (paramtype: RpcParamtype) => (
...pipes: (Type<PipeTransform> | PipeTransform)[]
): ParameterDecorator => (target, key, index) => {
const args =
Reflect.getMetadata(PARAM_ARGS_METADATA, target.constructor, key) || {};
Reflect.defineMetadata(
PARAM_ARGS_METADATA,
assignMetadata(args, paramtype, index, undefined, ...pipes),
target.constructor,
key,
);
};