-
-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathhttp-metadata.accessor.ts
53 lines (45 loc) · 1.93 KB
/
http-metadata.accessor.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import 'reflect-metadata';
import {
INTERCEPTOR_METADATA,
METHOD_METADATA,
OPTIONS_METADATA,
PATH_METADATA,
REQUEST_PARAMS_METADATA,
RESPONSE,
RESPONSE_HEADER,
} from './http.constants';
import { getMetadata, BRAKES_METADATA } from '@nestcloud/common';
import { Injectable } from '@nestjs/common';
import { ParamsMetadata } from './interfaces/params-metadata.interface';
import { LOADBALANCE_SERVICE } from '@nestcloud/common';
@Injectable()
export class HttpMetadataAccessor {
getUrl(instance: Function, target: Function): string | undefined {
return getMetadata(PATH_METADATA, target, instance.constructor);
}
getMethod(instance: Function, target: Function): string | undefined {
return getMetadata(METHOD_METADATA, target, instance.constructor);
}
getResponseConfig(instance: Function, target: Function): string | undefined {
let responseType = getMetadata(RESPONSE, target, instance.constructor);
if (!responseType) {
responseType = getMetadata(RESPONSE_HEADER, target, instance.constructor);
}
return responseType;
}
getParams(instance: Function, key: any): ParamsMetadata | undefined {
return Reflect.getMetadata(REQUEST_PARAMS_METADATA, instance.constructor, key);
}
getOptions(instance: Function, target: Function) {
return getMetadata(OPTIONS_METADATA, target, instance.constructor);
}
getService(instance: Function, target: Function): string | undefined {
return getMetadata<string>(LOADBALANCE_SERVICE, target, instance.constructor);
}
getInterceptorRefs(instance: Function, target: Function): Function[] | undefined {
return getMetadata<Function[]>(INTERCEPTOR_METADATA, target, instance.constructor);
}
getFallbackRef(instance: Function, target: Function): Function | undefined {
return getMetadata<Function>(BRAKES_METADATA, target, instance.constructor);
}
}