gg-express 1.0.99 → 1.0.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/v2/GGExpressV2.d.ts +22 -16
- package/dist/v2/GGExpressV2.js +2 -1
- package/dist/v2/generateStaticRouteFileV2.d.ts +2 -2
- package/dist/v2/output/staticRouteInterface_hotel_v2.d.ts +28 -22
- package/dist/v2/run_v2.test.js +20 -8
- package/dist/v2/typeResolver.js +3 -0
- package/package.json +1 -1
- package/src/v2/GGExpressV2.ts +91 -28
- package/src/v2/generateStaticRouteFileV2.ts +5 -5
- package/src/v2/output/staticRouteInterface_hotel_v2.ts +25 -22
- package/src/v2/run_v2.test.ts +20 -8
- package/src/v2/typeResolver.ts +4 -0
package/dist/v2/GGExpressV2.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { NextFunction
|
|
1
|
+
import { NextFunction } from "express";
|
|
2
|
+
import { Request, Response } from "express-serve-static-core";
|
|
2
3
|
import Express from "express-serve-static-core";
|
|
3
4
|
import { TypeResolve, ConstSchemaType } from "./typeResolver";
|
|
4
5
|
export type Method = "get" | "post" | "put" | "delete";
|
|
5
|
-
type MyRequest<M extends Method, RQ extends ConstSchemaType> = M extends "get" ?
|
|
6
|
-
type MyRequestQuery<T extends ConstSchemaType> = Request<{}, {}, {}, T, {}>;
|
|
7
|
-
type MyRequestBody<T extends ConstSchemaType> = Request<{}, {}, T, {}, {}>;
|
|
6
|
+
type MyRequest<M extends Method, RQ extends ConstSchemaType, P extends boolean = false> = M extends "get" ? MyRequestQuery<RQ, P> : MyRequestBody<RQ, P>;
|
|
7
|
+
type MyRequestQuery<T extends ConstSchemaType, P extends boolean = false> = P extends true ? Request<{}, {}, {}, Partial<TypeResolve<T>>, {}> : Request<{}, {}, {}, TypeResolve<T>, {}>;
|
|
8
|
+
type MyRequestBody<T extends ConstSchemaType, P extends boolean = false> = P extends true ? Request<{}, {}, Partial<TypeResolve<T>>, {}, {}> : Request<{}, {}, TypeResolve<T>, {}, {}>;
|
|
8
9
|
type SuccessResponse<T extends ConstSchemaType> = {
|
|
9
10
|
status: "SUCCESS";
|
|
10
11
|
message: string;
|
|
@@ -15,28 +16,33 @@ type ErrorResponse = {
|
|
|
15
16
|
message: string;
|
|
16
17
|
};
|
|
17
18
|
type MyResponse<T extends ConstSchemaType> = Response<SuccessResponse<T> | ErrorResponse>;
|
|
19
|
+
type RequestParamWrapper<RQ extends ConstSchemaType, P extends boolean = false> = {
|
|
20
|
+
isPartial?: P;
|
|
21
|
+
data: RQ;
|
|
22
|
+
};
|
|
23
|
+
type RequestQueryBodyWrapper<M extends Method, RQ extends ConstSchemaType, P extends boolean = false> = MyRequest<M, RQ, P>;
|
|
18
24
|
export default class GGExpressV2<appName extends string> {
|
|
19
25
|
express: Express.Express;
|
|
20
26
|
private outputPath;
|
|
21
27
|
appName: string;
|
|
22
28
|
constructor(app: Express.Express, appName: appName, outputPath: string[]);
|
|
23
29
|
private rootMethod;
|
|
24
|
-
get<RQ extends ConstSchemaType, RS extends ConstSchemaType>(url: `/api/${appName | "seed"}/${string}` | `/api/${appName | "seed"}/${string}`[], options: {
|
|
25
|
-
requireParams: RQ
|
|
30
|
+
get<RQ extends ConstSchemaType, RS extends ConstSchemaType, P extends boolean = false>(url: `/api/${appName | "seed"}/${string}` | `/api/${appName | "seed"}/${string}`[], options: {
|
|
31
|
+
requireParams: RequestParamWrapper<RQ, P>;
|
|
26
32
|
responseStructure: RS;
|
|
27
|
-
}, ...middlewares: Array<(req:
|
|
28
|
-
post<RQ extends ConstSchemaType, RS extends ConstSchemaType>(url: `/api/${appName | "seed"}/${string}` | `/api/${appName | "seed"}/${string}`[], options: {
|
|
29
|
-
requireParams: RQ
|
|
33
|
+
}, ...middlewares: Array<(req: RequestQueryBodyWrapper<"get", RQ, P>, res: MyResponse<RS>, next: NextFunction) => any>): Express.Express;
|
|
34
|
+
post<RQ extends ConstSchemaType, RS extends ConstSchemaType, P extends boolean = false>(url: `/api/${appName | "seed"}/${string}` | `/api/${appName | "seed"}/${string}`[], options: {
|
|
35
|
+
requireParams: RequestParamWrapper<RQ, P>;
|
|
30
36
|
responseStructure: RS;
|
|
31
|
-
}, ...middlewares: Array<(req:
|
|
32
|
-
put<RQ extends ConstSchemaType, RS extends ConstSchemaType>(url: `/api/${appName | "seed"}/${string}` | `/api/${appName | "seed"}/${string}`[], options: {
|
|
33
|
-
requireParams: RQ
|
|
37
|
+
}, ...middlewares: Array<(req: RequestQueryBodyWrapper<"post", RQ, P>, res: MyResponse<RS>, next: NextFunction) => any>): Express.Express;
|
|
38
|
+
put<RQ extends ConstSchemaType, RS extends ConstSchemaType, P extends boolean = false>(url: `/api/${appName | "seed"}/${string}` | `/api/${appName | "seed"}/${string}`[], options: {
|
|
39
|
+
requireParams: RequestParamWrapper<RQ, P>;
|
|
34
40
|
responseStructure: RS;
|
|
35
|
-
}, ...middlewares: Array<(req:
|
|
36
|
-
delete<RQ extends ConstSchemaType, RS extends ConstSchemaType>(url: `/api/${appName | "seed"}/${string}` | `/api/${appName | "seed"}/${string}`[], options: {
|
|
37
|
-
requireParams: RQ
|
|
41
|
+
}, ...middlewares: Array<(req: RequestQueryBodyWrapper<"put", RQ, P>, res: MyResponse<RS>, next: NextFunction) => any>): Express.Express;
|
|
42
|
+
delete<RQ extends ConstSchemaType, RS extends ConstSchemaType, P extends boolean = false>(url: `/api/${appName | "seed"}/${string}` | `/api/${appName | "seed"}/${string}`[], options: {
|
|
43
|
+
requireParams: RequestParamWrapper<RQ, P>;
|
|
38
44
|
responseStructure: RS;
|
|
39
|
-
}, ...middlewares: Array<(req:
|
|
45
|
+
}, ...middlewares: Array<(req: RequestQueryBodyWrapper<"delete", RQ, P>, res: MyResponse<RS>, next: NextFunction) => any>): Express.Express;
|
|
40
46
|
generateAPIFiles(): Promise<void>;
|
|
41
47
|
private generateStaticRouteFile;
|
|
42
48
|
}
|
package/dist/v2/GGExpressV2.js
CHANGED
|
@@ -35,7 +35,7 @@ class GGExpressV2 {
|
|
|
35
35
|
myExpressRouteList.push({
|
|
36
36
|
method: method,
|
|
37
37
|
url: url,
|
|
38
|
-
requireParams: options.requireParams,
|
|
38
|
+
requireParams: options.requireParams.data,
|
|
39
39
|
responseStructure: Object.assign({}, options.responseStructure),
|
|
40
40
|
});
|
|
41
41
|
});
|
|
@@ -69,6 +69,7 @@ class GGExpressV2 {
|
|
|
69
69
|
for (let row of this.outputPath) {
|
|
70
70
|
fs_1.default.writeFileSync(path_1.default.join(row, `staticRouteInterface_${this.appName}_v2.ts`), staticRouteCode);
|
|
71
71
|
yield (0, generateGGApi_v2_1.generateGGApi_v2)(this.appName, path_1.default.join(row, `apiConnector_${this.appName}_v2.ts`));
|
|
72
|
+
console.log(`generate -> ${`staticRouteInterface_${this.appName}_v2.ts`}`);
|
|
72
73
|
}
|
|
73
74
|
});
|
|
74
75
|
}
|
|
@@ -6,7 +6,7 @@ type routeList = {
|
|
|
6
6
|
requireParams: ConstSchemaType;
|
|
7
7
|
responseStructure: ConstSchemaType;
|
|
8
8
|
};
|
|
9
|
-
type
|
|
9
|
+
type PrepareRouteStructure = {
|
|
10
10
|
[K in Method]: {
|
|
11
11
|
[key in string]: {
|
|
12
12
|
requireParams: string;
|
|
@@ -14,6 +14,6 @@ type PrepareRouteStucture = {
|
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
|
-
export declare function prepareExportInterfaceData(data: routeList[]):
|
|
17
|
+
export declare function prepareExportInterfaceData(data: routeList[]): PrepareRouteStructure;
|
|
18
18
|
export declare function generateStaticRouteFileV2(appName: string, data: routeList[]): string;
|
|
19
19
|
export {};
|
|
@@ -2,30 +2,33 @@ export interface staticRouteInterface_hotel_v2 {
|
|
|
2
2
|
get: {
|
|
3
3
|
"/api/hotel/users/id": {
|
|
4
4
|
requireParams: {
|
|
5
|
-
|
|
5
|
+
isPartial?: boolean;
|
|
6
6
|
data: {
|
|
7
7
|
id: number;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
8
|
+
data: {
|
|
9
|
+
id: number;
|
|
10
|
+
bookingGroupID: number;
|
|
11
|
+
checkInDate: string;
|
|
12
|
+
checkOutDate: string;
|
|
13
|
+
checkInTime: string;
|
|
14
|
+
checkOutTime: string;
|
|
15
|
+
roomRate: number;
|
|
16
|
+
extraBedRate: number;
|
|
17
|
+
roomNumber: string;
|
|
18
|
+
editTime: string;
|
|
19
|
+
createTime: string;
|
|
20
|
+
shiftDate: string;
|
|
21
|
+
shiftName: string;
|
|
22
|
+
userName: string;
|
|
23
|
+
bookingStatus: "ACTIVE" | "CLOSE" | "CANCEL" | "NO_SHOW";
|
|
24
|
+
is_specificRoom: number;
|
|
25
|
+
guestCount: number;
|
|
26
|
+
reasonToCancel: string;
|
|
27
|
+
note: string;
|
|
28
|
+
};
|
|
29
|
+
name: string;
|
|
30
|
+
status: "on" | "off";
|
|
26
31
|
};
|
|
27
|
-
name: string;
|
|
28
|
-
status: "on" | "off";
|
|
29
32
|
};
|
|
30
33
|
responseStructure: {
|
|
31
34
|
data: {
|
|
@@ -64,7 +67,10 @@ export interface staticRouteInterface_hotel_v2 {
|
|
|
64
67
|
post: {
|
|
65
68
|
"/api/hotel/booking/id": {
|
|
66
69
|
requireParams: {
|
|
67
|
-
|
|
70
|
+
isPartial?: boolean;
|
|
71
|
+
data: {
|
|
72
|
+
id: number;
|
|
73
|
+
};
|
|
68
74
|
};
|
|
69
75
|
responseStructure: {
|
|
70
76
|
data: {
|
package/dist/v2/run_v2.test.js
CHANGED
|
@@ -43,10 +43,12 @@ function run() {
|
|
|
43
43
|
const ggapp = new GGExpressV2_1.default(app, "hotel", ["./output"]);
|
|
44
44
|
ggapp.get("/api/hotel/users/id", {
|
|
45
45
|
requireParams: {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
data: {
|
|
47
|
+
id: "number",
|
|
48
|
+
data: exports.hotel_model_const_temp["booking"],
|
|
49
|
+
name: "string",
|
|
50
|
+
status: ["on", "off"],
|
|
51
|
+
},
|
|
50
52
|
},
|
|
51
53
|
responseStructure: {
|
|
52
54
|
x: "string",
|
|
@@ -81,7 +83,6 @@ function run() {
|
|
|
81
83
|
],
|
|
82
84
|
},
|
|
83
85
|
}, (req, res, next) => {
|
|
84
|
-
req.query.status === "on";
|
|
85
86
|
return res.json({
|
|
86
87
|
message: "",
|
|
87
88
|
status: "SUCCESS",
|
|
@@ -121,7 +122,15 @@ function run() {
|
|
|
121
122
|
});
|
|
122
123
|
ggapp.post("/api/hotel/booking/id", {
|
|
123
124
|
requireParams: {
|
|
124
|
-
|
|
125
|
+
data: {
|
|
126
|
+
id: "number",
|
|
127
|
+
name: "string",
|
|
128
|
+
datax: [
|
|
129
|
+
{
|
|
130
|
+
id: "number",
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
},
|
|
125
134
|
},
|
|
126
135
|
responseStructure: {
|
|
127
136
|
bookingData: {
|
|
@@ -144,7 +153,9 @@ function run() {
|
|
|
144
153
|
});
|
|
145
154
|
ggapp.post("/api/hotel/booking/id", {
|
|
146
155
|
requireParams: {
|
|
147
|
-
|
|
156
|
+
data: {
|
|
157
|
+
id: "number",
|
|
158
|
+
},
|
|
148
159
|
},
|
|
149
160
|
responseStructure: {
|
|
150
161
|
bookingData: {
|
|
@@ -153,7 +164,8 @@ function run() {
|
|
|
153
164
|
},
|
|
154
165
|
},
|
|
155
166
|
}, (req, res, next) => {
|
|
156
|
-
|
|
167
|
+
var _a;
|
|
168
|
+
(_a = req.body) === null || _a === void 0 ? void 0 : _a.id;
|
|
157
169
|
return res.json({
|
|
158
170
|
status: "ERROR",
|
|
159
171
|
message: "",
|
package/dist/v2/typeResolver.js
CHANGED
package/package.json
CHANGED
package/src/v2/GGExpressV2.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { NextFunction
|
|
1
|
+
import { NextFunction } from "express"
|
|
2
|
+
import { Request, Response } from "express-serve-static-core"
|
|
2
3
|
import Express from "express-serve-static-core"
|
|
3
4
|
import fs from "fs"
|
|
4
5
|
import { TypeResolve, ConstSchemaType } from "./typeResolver"
|
|
@@ -8,14 +9,42 @@ import { generateGGApi_v2 } from "./generateGGApi_v2"
|
|
|
8
9
|
|
|
9
10
|
export type Method = "get" | "post" | "put" | "delete"
|
|
10
11
|
|
|
11
|
-
type MyRequest<
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
// type MyRequest<
|
|
13
|
+
// M extends Method,
|
|
14
|
+
// RQ extends ConstSchemaType,
|
|
15
|
+
// P extends boolean = false
|
|
16
|
+
// > = M extends "get"
|
|
17
|
+
// ? // get
|
|
18
|
+
// P extends true
|
|
19
|
+
// ? TypePartialResolve<MyRequestQuery<RQ>>
|
|
20
|
+
// : TypeResolve<MyRequestQuery<RQ>>
|
|
21
|
+
// : // post, put, delete
|
|
22
|
+
// P extends true
|
|
23
|
+
// ? TypePartialResolve<MyRequestBody<RQ>>
|
|
24
|
+
// : TypeResolve<MyRequestBody<RQ>>
|
|
25
|
+
type MyRequest<
|
|
26
|
+
M extends Method,
|
|
27
|
+
RQ extends ConstSchemaType,
|
|
28
|
+
P extends boolean = false
|
|
29
|
+
> = M extends "get"
|
|
30
|
+
? // get
|
|
31
|
+
MyRequestQuery<RQ, P>
|
|
14
32
|
: // post, put, delete
|
|
15
|
-
|
|
33
|
+
MyRequestBody<RQ, P>
|
|
16
34
|
|
|
17
|
-
type MyRequestQuery<
|
|
18
|
-
|
|
35
|
+
type MyRequestQuery<
|
|
36
|
+
T extends ConstSchemaType,
|
|
37
|
+
P extends boolean = false
|
|
38
|
+
> = P extends true
|
|
39
|
+
? Request<{}, {}, {}, Partial<TypeResolve<T>>, {}>
|
|
40
|
+
: Request<{}, {}, {}, TypeResolve<T>, {}>
|
|
41
|
+
|
|
42
|
+
type MyRequestBody<
|
|
43
|
+
T extends ConstSchemaType,
|
|
44
|
+
P extends boolean = false
|
|
45
|
+
> = P extends true
|
|
46
|
+
? Request<{}, {}, Partial<TypeResolve<T>>, {}, {}>
|
|
47
|
+
: Request<{}, {}, TypeResolve<T>, {}, {}>
|
|
19
48
|
|
|
20
49
|
type SuccessResponse<T extends ConstSchemaType> = {
|
|
21
50
|
status: "SUCCESS"
|
|
@@ -30,11 +59,23 @@ type ErrorResponse = {
|
|
|
30
59
|
type MyResponse<T extends ConstSchemaType> = Response<
|
|
31
60
|
SuccessResponse<T> | ErrorResponse
|
|
32
61
|
>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
62
|
+
|
|
63
|
+
type RequestParamWrapper<
|
|
64
|
+
RQ extends ConstSchemaType,
|
|
65
|
+
P extends boolean = false
|
|
66
|
+
> = {
|
|
67
|
+
isPartial?: P
|
|
68
|
+
data: RQ
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
type RequestQueryBodyWrapper<
|
|
72
|
+
M extends Method,
|
|
73
|
+
RQ extends ConstSchemaType,
|
|
74
|
+
P extends boolean = false
|
|
75
|
+
> = MyRequest<M, RQ, P>
|
|
76
|
+
|
|
36
77
|
const myExpressRouteList: {
|
|
37
|
-
method:
|
|
78
|
+
method: Method
|
|
38
79
|
url: string
|
|
39
80
|
requireParams: ConstSchemaType
|
|
40
81
|
responseStructure: ConstSchemaType
|
|
@@ -53,17 +94,18 @@ export default class GGExpressV2<appName extends string> {
|
|
|
53
94
|
private rootMethod<
|
|
54
95
|
M extends Method,
|
|
55
96
|
RQ extends ConstSchemaType,
|
|
56
|
-
RS extends ConstSchemaType
|
|
97
|
+
RS extends ConstSchemaType,
|
|
98
|
+
P extends boolean = false
|
|
57
99
|
>(
|
|
58
100
|
method: M,
|
|
59
101
|
url: string | string[],
|
|
60
102
|
options: {
|
|
61
|
-
requireParams: RQ
|
|
103
|
+
requireParams: RequestParamWrapper<RQ, P>
|
|
62
104
|
responseStructure: RS
|
|
63
105
|
},
|
|
64
106
|
...middlewares: Array<
|
|
65
107
|
(
|
|
66
|
-
req:
|
|
108
|
+
req: RequestQueryBodyWrapper<M, RQ, P>,
|
|
67
109
|
res: MyResponse<RS>,
|
|
68
110
|
next: NextFunction
|
|
69
111
|
) => void | Promise<void>
|
|
@@ -79,7 +121,7 @@ export default class GGExpressV2<appName extends string> {
|
|
|
79
121
|
myExpressRouteList.push({
|
|
80
122
|
method: method,
|
|
81
123
|
url: url,
|
|
82
|
-
requireParams: options.requireParams,
|
|
124
|
+
requireParams: options.requireParams.data,
|
|
83
125
|
responseStructure: {
|
|
84
126
|
...options.responseStructure,
|
|
85
127
|
},
|
|
@@ -94,21 +136,29 @@ export default class GGExpressV2<appName extends string> {
|
|
|
94
136
|
// แต่ middleware ของคุณจะถูก wrap ทีละตัว
|
|
95
137
|
...middlewares.map(
|
|
96
138
|
(mw) => (req: Request, res: Response, next: NextFunction) =>
|
|
97
|
-
mw(
|
|
139
|
+
mw(
|
|
140
|
+
req as RequestQueryBodyWrapper<M, RQ, P>,
|
|
141
|
+
res as MyResponse<RS>,
|
|
142
|
+
next
|
|
143
|
+
)
|
|
98
144
|
)
|
|
99
145
|
)
|
|
100
146
|
}
|
|
101
|
-
get<
|
|
147
|
+
get<
|
|
148
|
+
RQ extends ConstSchemaType,
|
|
149
|
+
RS extends ConstSchemaType,
|
|
150
|
+
P extends boolean = false
|
|
151
|
+
>(
|
|
102
152
|
url:
|
|
103
153
|
| `/api/${appName | "seed"}/${string}`
|
|
104
154
|
| `/api/${appName | "seed"}/${string}`[],
|
|
105
155
|
options: {
|
|
106
|
-
requireParams: RQ
|
|
156
|
+
requireParams: RequestParamWrapper<RQ, P>
|
|
107
157
|
responseStructure: RS
|
|
108
158
|
},
|
|
109
159
|
...middlewares: Array<
|
|
110
160
|
(
|
|
111
|
-
req:
|
|
161
|
+
req: RequestQueryBodyWrapper<"get", RQ, P>,
|
|
112
162
|
res: MyResponse<RS>,
|
|
113
163
|
next: NextFunction
|
|
114
164
|
) => any
|
|
@@ -117,17 +167,21 @@ export default class GGExpressV2<appName extends string> {
|
|
|
117
167
|
return this.rootMethod("get", url, options, ...middlewares)
|
|
118
168
|
}
|
|
119
169
|
|
|
120
|
-
post<
|
|
170
|
+
post<
|
|
171
|
+
RQ extends ConstSchemaType,
|
|
172
|
+
RS extends ConstSchemaType,
|
|
173
|
+
P extends boolean = false
|
|
174
|
+
>(
|
|
121
175
|
url:
|
|
122
176
|
| `/api/${appName | "seed"}/${string}`
|
|
123
177
|
| `/api/${appName | "seed"}/${string}`[],
|
|
124
178
|
options: {
|
|
125
|
-
requireParams: RQ
|
|
179
|
+
requireParams: RequestParamWrapper<RQ, P>
|
|
126
180
|
responseStructure: RS
|
|
127
181
|
},
|
|
128
182
|
...middlewares: Array<
|
|
129
183
|
(
|
|
130
|
-
req:
|
|
184
|
+
req: RequestQueryBodyWrapper<"post", RQ, P>,
|
|
131
185
|
res: MyResponse<RS>,
|
|
132
186
|
next: NextFunction
|
|
133
187
|
) => any
|
|
@@ -135,17 +189,21 @@ export default class GGExpressV2<appName extends string> {
|
|
|
135
189
|
) {
|
|
136
190
|
return this.rootMethod("post", url, options, ...middlewares)
|
|
137
191
|
}
|
|
138
|
-
put<
|
|
192
|
+
put<
|
|
193
|
+
RQ extends ConstSchemaType,
|
|
194
|
+
RS extends ConstSchemaType,
|
|
195
|
+
P extends boolean = false
|
|
196
|
+
>(
|
|
139
197
|
url:
|
|
140
198
|
| `/api/${appName | "seed"}/${string}`
|
|
141
199
|
| `/api/${appName | "seed"}/${string}`[],
|
|
142
200
|
options: {
|
|
143
|
-
requireParams: RQ
|
|
201
|
+
requireParams: RequestParamWrapper<RQ, P>
|
|
144
202
|
responseStructure: RS
|
|
145
203
|
},
|
|
146
204
|
...middlewares: Array<
|
|
147
205
|
(
|
|
148
|
-
req:
|
|
206
|
+
req: RequestQueryBodyWrapper<"put", RQ, P>,
|
|
149
207
|
res: MyResponse<RS>,
|
|
150
208
|
next: NextFunction
|
|
151
209
|
) => any
|
|
@@ -153,17 +211,21 @@ export default class GGExpressV2<appName extends string> {
|
|
|
153
211
|
) {
|
|
154
212
|
return this.rootMethod("put", url, options, ...middlewares)
|
|
155
213
|
}
|
|
156
|
-
delete<
|
|
214
|
+
delete<
|
|
215
|
+
RQ extends ConstSchemaType,
|
|
216
|
+
RS extends ConstSchemaType,
|
|
217
|
+
P extends boolean = false
|
|
218
|
+
>(
|
|
157
219
|
url:
|
|
158
220
|
| `/api/${appName | "seed"}/${string}`
|
|
159
221
|
| `/api/${appName | "seed"}/${string}`[],
|
|
160
222
|
options: {
|
|
161
|
-
requireParams: RQ
|
|
223
|
+
requireParams: RequestParamWrapper<RQ, P>
|
|
162
224
|
responseStructure: RS
|
|
163
225
|
},
|
|
164
226
|
...middlewares: Array<
|
|
165
227
|
(
|
|
166
|
-
req:
|
|
228
|
+
req: RequestQueryBodyWrapper<"delete", RQ, P>,
|
|
167
229
|
res: MyResponse<RS>,
|
|
168
230
|
next: NextFunction
|
|
169
231
|
) => any
|
|
@@ -191,6 +253,7 @@ export default class GGExpressV2<appName extends string> {
|
|
|
191
253
|
this.appName,
|
|
192
254
|
path.join(row, `apiConnector_${this.appName}_v2.ts`)
|
|
193
255
|
)
|
|
256
|
+
console.log(`generate -> ${`staticRouteInterface_${this.appName}_v2.ts`}`)
|
|
194
257
|
}
|
|
195
258
|
}
|
|
196
259
|
}
|
|
@@ -7,7 +7,7 @@ type routeList = {
|
|
|
7
7
|
responseStructure: ConstSchemaType
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
type
|
|
10
|
+
type PrepareRouteStructure = {
|
|
11
11
|
[K in Method]: {
|
|
12
12
|
[key in string]: {
|
|
13
13
|
requireParams: string
|
|
@@ -20,7 +20,7 @@ type MyResponse = {
|
|
|
20
20
|
[url in string]: {}
|
|
21
21
|
}
|
|
22
22
|
export function prepareExportInterfaceData(data: routeList[]) {
|
|
23
|
-
let prepareRoute:
|
|
23
|
+
let prepareRoute: PrepareRouteStructure = {
|
|
24
24
|
get: {},
|
|
25
25
|
post: {},
|
|
26
26
|
put: {},
|
|
@@ -31,8 +31,8 @@ export function prepareExportInterfaceData(data: routeList[]) {
|
|
|
31
31
|
}
|
|
32
32
|
function extract(
|
|
33
33
|
allData: routeList[],
|
|
34
|
-
prepareRoute:
|
|
35
|
-
):
|
|
34
|
+
prepareRoute: PrepareRouteStructure
|
|
35
|
+
): PrepareRouteStructure {
|
|
36
36
|
for (const route of allData) {
|
|
37
37
|
prepareRoute[route.method][route.url] = {
|
|
38
38
|
requireParams: parentInputToCode(route.requireParams),
|
|
@@ -104,7 +104,7 @@ function parentInputToCode(data: ConstSchemaType) {
|
|
|
104
104
|
}
|
|
105
105
|
export function generateStaticRouteFileV2(appName: string, data: routeList[]) {
|
|
106
106
|
const interfaceName = `staticRouteInterface_${appName}_v2`
|
|
107
|
-
const generateEachUrl = (data:
|
|
107
|
+
const generateEachUrl = (data: PrepareRouteStructure[Method]) => {
|
|
108
108
|
const keyName = Object.keys(data)
|
|
109
109
|
return keyName
|
|
110
110
|
.map(
|
|
@@ -2,30 +2,33 @@ export interface staticRouteInterface_hotel_v2 {
|
|
|
2
2
|
get: {
|
|
3
3
|
"/api/hotel/users/id": {
|
|
4
4
|
requireParams: {
|
|
5
|
-
|
|
5
|
+
isPartial?: boolean
|
|
6
6
|
data: {
|
|
7
7
|
id: number
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
8
|
+
data: {
|
|
9
|
+
id: number
|
|
10
|
+
bookingGroupID: number
|
|
11
|
+
checkInDate: string
|
|
12
|
+
checkOutDate: string
|
|
13
|
+
checkInTime: string
|
|
14
|
+
checkOutTime: string
|
|
15
|
+
roomRate: number
|
|
16
|
+
extraBedRate: number
|
|
17
|
+
roomNumber: string
|
|
18
|
+
editTime: string
|
|
19
|
+
createTime: string
|
|
20
|
+
shiftDate: string
|
|
21
|
+
shiftName: string
|
|
22
|
+
userName: string
|
|
23
|
+
bookingStatus: "ACTIVE" | "CLOSE" | "CANCEL" | "NO_SHOW"
|
|
24
|
+
is_specificRoom: number
|
|
25
|
+
guestCount: number
|
|
26
|
+
reasonToCancel: string
|
|
27
|
+
note: string
|
|
28
|
+
}
|
|
29
|
+
name: string
|
|
30
|
+
status: "on" | "off"
|
|
26
31
|
}
|
|
27
|
-
name: string
|
|
28
|
-
status: "on" | "off"
|
|
29
32
|
}
|
|
30
33
|
responseStructure: {
|
|
31
34
|
data: {
|
|
@@ -54,7 +57,7 @@ export interface staticRouteInterface_hotel_v2 {
|
|
|
54
57
|
}
|
|
55
58
|
post: {
|
|
56
59
|
"/api/hotel/booking/id": {
|
|
57
|
-
requireParams: { id: number }
|
|
60
|
+
requireParams: { isPartial?: boolean; data: { id: number } }
|
|
58
61
|
responseStructure: {
|
|
59
62
|
data: {
|
|
60
63
|
bookingData: { id: number; roomNumber: string }
|
package/src/v2/run_v2.test.ts
CHANGED
|
@@ -33,10 +33,12 @@ function run() {
|
|
|
33
33
|
"/api/hotel/users/id",
|
|
34
34
|
{
|
|
35
35
|
requireParams: {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
data: {
|
|
37
|
+
id: "number",
|
|
38
|
+
data: hotel_model_const_temp["booking"],
|
|
39
|
+
name: "string",
|
|
40
|
+
status: ["on", "off"],
|
|
41
|
+
},
|
|
40
42
|
},
|
|
41
43
|
responseStructure: {
|
|
42
44
|
x: "string",
|
|
@@ -72,7 +74,6 @@ function run() {
|
|
|
72
74
|
},
|
|
73
75
|
},
|
|
74
76
|
(req, res, next) => {
|
|
75
|
-
req.query.status === "on"
|
|
76
77
|
return res.json({
|
|
77
78
|
message: "",
|
|
78
79
|
status: "SUCCESS",
|
|
@@ -115,7 +116,15 @@ function run() {
|
|
|
115
116
|
"/api/hotel/booking/id",
|
|
116
117
|
{
|
|
117
118
|
requireParams: {
|
|
118
|
-
|
|
119
|
+
data: {
|
|
120
|
+
id: "number",
|
|
121
|
+
name: "string",
|
|
122
|
+
datax: [
|
|
123
|
+
{
|
|
124
|
+
id: "number",
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
},
|
|
119
128
|
},
|
|
120
129
|
responseStructure: {
|
|
121
130
|
bookingData: {
|
|
@@ -126,6 +135,7 @@ function run() {
|
|
|
126
135
|
},
|
|
127
136
|
(req, res, next) => {
|
|
128
137
|
req.body.id
|
|
138
|
+
|
|
129
139
|
return res.json({
|
|
130
140
|
message: "",
|
|
131
141
|
status: "SUCCESS",
|
|
@@ -143,7 +153,9 @@ function run() {
|
|
|
143
153
|
"/api/hotel/booking/id",
|
|
144
154
|
{
|
|
145
155
|
requireParams: {
|
|
146
|
-
|
|
156
|
+
data: {
|
|
157
|
+
id: "number",
|
|
158
|
+
},
|
|
147
159
|
},
|
|
148
160
|
responseStructure: {
|
|
149
161
|
bookingData: {
|
|
@@ -153,7 +165,7 @@ function run() {
|
|
|
153
165
|
},
|
|
154
166
|
},
|
|
155
167
|
(req, res, next) => {
|
|
156
|
-
req.body
|
|
168
|
+
req.body?.id
|
|
157
169
|
return res.json({
|
|
158
170
|
status: "ERROR",
|
|
159
171
|
message: "",
|
package/src/v2/typeResolver.ts
CHANGED
|
@@ -14,6 +14,7 @@ type InputEnum = readonly string[] | readonly number[]
|
|
|
14
14
|
export type ConstSchemaType = {
|
|
15
15
|
[key in string]: CustomType | ConstSchemaType | ConstSchemaType[] | InputEnum
|
|
16
16
|
}
|
|
17
|
+
|
|
17
18
|
type ResolveBase<T extends BaseType> = T extends "string"
|
|
18
19
|
? string
|
|
19
20
|
: T extends "string[]"
|
|
@@ -56,3 +57,6 @@ type chooseType<T> = T extends InputEnum
|
|
|
56
57
|
export type TypeResolve<T> = {
|
|
57
58
|
[K in keyof T]: chooseType<T[K]>
|
|
58
59
|
}
|
|
60
|
+
// export type PartialTypeResolve<T> = {
|
|
61
|
+
// [K in keyof T]: chooseType<T[K]>
|
|
62
|
+
// }
|