1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Search = exports.All = exports.Head = exports.Options = exports.Patch = exports.Put = exports.Delete = exports.Get = exports.Post = exports.RequestMapping = void 0;
|
4 | const constants_1 = require("../../constants");
|
5 | const request_method_enum_1 = require("../../enums/request-method.enum");
|
6 | const defaultMetadata = {
|
7 | [constants_1.PATH_METADATA]: '/',
|
8 | [constants_1.METHOD_METADATA]: request_method_enum_1.RequestMethod.GET,
|
9 | };
|
10 | const RequestMapping = (metadata = defaultMetadata) => {
|
11 | const pathMetadata = metadata[constants_1.PATH_METADATA];
|
12 | const path = pathMetadata && pathMetadata.length ? pathMetadata : '/';
|
13 | const requestMethod = metadata[constants_1.METHOD_METADATA] || request_method_enum_1.RequestMethod.GET;
|
14 | return (target, key, descriptor) => {
|
15 | Reflect.defineMetadata(constants_1.PATH_METADATA, path, descriptor.value);
|
16 | Reflect.defineMetadata(constants_1.METHOD_METADATA, requestMethod, descriptor.value);
|
17 | return descriptor;
|
18 | };
|
19 | };
|
20 | exports.RequestMapping = RequestMapping;
|
21 | const createMappingDecorator = (method) => (path) => {
|
22 | return (0, exports.RequestMapping)({
|
23 | [constants_1.PATH_METADATA]: path,
|
24 | [constants_1.METHOD_METADATA]: method,
|
25 | });
|
26 | };
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | exports.Post = createMappingDecorator(request_method_enum_1.RequestMethod.POST);
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | exports.Get = createMappingDecorator(request_method_enum_1.RequestMethod.GET);
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | exports.Delete = createMappingDecorator(request_method_enum_1.RequestMethod.DELETE);
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | exports.Put = createMappingDecorator(request_method_enum_1.RequestMethod.PUT);
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | exports.Patch = createMappingDecorator(request_method_enum_1.RequestMethod.PATCH);
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 | exports.Options = createMappingDecorator(request_method_enum_1.RequestMethod.OPTIONS);
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | exports.Head = createMappingDecorator(request_method_enum_1.RequestMethod.HEAD);
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 | exports.All = createMappingDecorator(request_method_enum_1.RequestMethod.ALL);
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | exports.Search = createMappingDecorator(request_method_enum_1.RequestMethod.SEARCH);
|