gg-express 1.0.97 → 1.0.99
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/staticRouteInterface_hotel.d.ts +18 -1
- package/dist/v2/GGExpressV2.d.ts +8 -3
- package/dist/v2/GGExpressV2.js +1 -1
- package/dist/v2/generateStaticRouteFileV2.js +5 -2
- package/dist/v2/output/staticRouteInterface_hotel_v2.d.ts +48 -3
- package/dist/v2/run_v2.test.js +18 -1
- package/package.json +1 -1
- package/src/staticRouteInterface_hotel.ts +29 -55
- package/src/v2/GGExpressV2.ts +15 -11
- package/src/v2/generateStaticRouteFileV2.ts +5 -2
- package/src/v2/output/staticRouteInterface_hotel_v2.ts +68 -23
- package/src/v2/run_v2.test.ts +23 -1
- package/src/v2/typeResolver.ts +1 -0
|
@@ -7,7 +7,24 @@ export interface staticRouteInterface_hotel {
|
|
|
7
7
|
};
|
|
8
8
|
data: {
|
|
9
9
|
id: number;
|
|
10
|
-
|
|
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;
|
|
11
28
|
}[];
|
|
12
29
|
};
|
|
13
30
|
responseStructure: {
|
package/dist/v2/GGExpressV2.d.ts
CHANGED
|
@@ -5,11 +5,16 @@ export type Method = "get" | "post" | "put" | "delete";
|
|
|
5
5
|
type MyRequest<M extends Method, RQ extends ConstSchemaType> = M extends "get" ? TypeResolve<MyRequestQuery<RQ>> : TypeResolve<MyRequestBody<RQ>>;
|
|
6
6
|
type MyRequestQuery<T extends ConstSchemaType> = Request<{}, {}, {}, T, {}>;
|
|
7
7
|
type MyRequestBody<T extends ConstSchemaType> = Request<{}, {}, T, {}, {}>;
|
|
8
|
-
type
|
|
9
|
-
status: "SUCCESS"
|
|
8
|
+
type SuccessResponse<T extends ConstSchemaType> = {
|
|
9
|
+
status: "SUCCESS";
|
|
10
10
|
message: string;
|
|
11
11
|
data: TypeResolve<T>;
|
|
12
|
-
}
|
|
12
|
+
};
|
|
13
|
+
type ErrorResponse = {
|
|
14
|
+
status: "ERROR" | "SERVER_ERROR";
|
|
15
|
+
message: string;
|
|
16
|
+
};
|
|
17
|
+
type MyResponse<T extends ConstSchemaType> = Response<SuccessResponse<T> | ErrorResponse>;
|
|
13
18
|
export default class GGExpressV2<appName extends string> {
|
|
14
19
|
express: Express.Express;
|
|
15
20
|
private outputPath;
|
package/dist/v2/GGExpressV2.js
CHANGED
|
@@ -43,7 +43,7 @@ class GGExpressV2 {
|
|
|
43
43
|
// Express handler ต้องกว้าง
|
|
44
44
|
(req, res, next) => next(),
|
|
45
45
|
// แต่ middleware ของคุณจะถูก wrap ทีละตัว
|
|
46
|
-
...middlewares.map((mw) => (
|
|
46
|
+
...middlewares.map((mw) => (req, res, next) => mw(req, res, next)));
|
|
47
47
|
}
|
|
48
48
|
get(url, options, ...middlewares) {
|
|
49
49
|
return this.rootMethod("get", url, options, ...middlewares);
|
|
@@ -62,9 +62,12 @@ function parentInputToCode(data) {
|
|
|
62
62
|
typeof target[0] === "string" ||
|
|
63
63
|
target[0] === null ||
|
|
64
64
|
target[0] === undefined)
|
|
65
|
-
return `${parentKeyName} : [${target
|
|
65
|
+
// return `${parentKeyName} : [${(target as string[])
|
|
66
|
+
// .map((word) => ` "${word}" `)
|
|
67
|
+
// .join(",")}] `
|
|
68
|
+
return `${parentKeyName} : ${target
|
|
66
69
|
.map((word) => ` "${word}" `)
|
|
67
|
-
.join("
|
|
70
|
+
.join("|")} `;
|
|
68
71
|
// nest or input nest
|
|
69
72
|
else if (typeof target[0] === "object")
|
|
70
73
|
for (const row of target) {
|
|
@@ -3,12 +3,57 @@ export interface staticRouteInterface_hotel_v2 {
|
|
|
3
3
|
"/api/hotel/users/id": {
|
|
4
4
|
requireParams: {
|
|
5
5
|
id: number;
|
|
6
|
+
data: {
|
|
7
|
+
id: number;
|
|
8
|
+
bookingGroupID: number;
|
|
9
|
+
checkInDate: string;
|
|
10
|
+
checkOutDate: string;
|
|
11
|
+
checkInTime: string;
|
|
12
|
+
checkOutTime: string;
|
|
13
|
+
roomRate: number;
|
|
14
|
+
extraBedRate: number;
|
|
15
|
+
roomNumber: string;
|
|
16
|
+
editTime: string;
|
|
17
|
+
createTime: string;
|
|
18
|
+
shiftDate: string;
|
|
19
|
+
shiftName: string;
|
|
20
|
+
userName: string;
|
|
21
|
+
bookingStatus: "ACTIVE" | "CLOSE" | "CANCEL" | "NO_SHOW";
|
|
22
|
+
is_specificRoom: number;
|
|
23
|
+
guestCount: number;
|
|
24
|
+
reasonToCancel: string;
|
|
25
|
+
note: string;
|
|
26
|
+
};
|
|
27
|
+
name: string;
|
|
28
|
+
status: "on" | "off";
|
|
6
29
|
};
|
|
7
30
|
responseStructure: {
|
|
8
31
|
data: {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
32
|
+
x: string;
|
|
33
|
+
data: {
|
|
34
|
+
zoneID: number;
|
|
35
|
+
zoneName: string;
|
|
36
|
+
data: {
|
|
37
|
+
itemID: number;
|
|
38
|
+
itemEachHotelID: number;
|
|
39
|
+
itemName: string;
|
|
40
|
+
requisitionQty: {
|
|
41
|
+
expected: number;
|
|
42
|
+
actual: number;
|
|
43
|
+
};
|
|
44
|
+
zoneStockQty: {
|
|
45
|
+
begin: number;
|
|
46
|
+
end: number;
|
|
47
|
+
};
|
|
48
|
+
usedQty: number;
|
|
49
|
+
lossQty: number;
|
|
50
|
+
damageQty: number;
|
|
51
|
+
returnQty: {
|
|
52
|
+
expected: number;
|
|
53
|
+
actual: number;
|
|
54
|
+
};
|
|
55
|
+
notReturnQty: number;
|
|
56
|
+
}[];
|
|
12
57
|
}[];
|
|
13
58
|
};
|
|
14
59
|
status: "SUCCESS" | "ERROR";
|
package/dist/v2/run_v2.test.js
CHANGED
|
@@ -142,13 +142,30 @@ function run() {
|
|
|
142
142
|
},
|
|
143
143
|
});
|
|
144
144
|
});
|
|
145
|
+
ggapp.post("/api/hotel/booking/id", {
|
|
146
|
+
requireParams: {
|
|
147
|
+
id: "number",
|
|
148
|
+
},
|
|
149
|
+
responseStructure: {
|
|
150
|
+
bookingData: {
|
|
151
|
+
id: "number",
|
|
152
|
+
roomNumber: "string",
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
}, (req, res, next) => {
|
|
156
|
+
req.body.id;
|
|
157
|
+
return res.json({
|
|
158
|
+
status: "ERROR",
|
|
159
|
+
message: "",
|
|
160
|
+
});
|
|
161
|
+
});
|
|
145
162
|
app.listen(3002, () => __awaiter(this, void 0, void 0, function* () {
|
|
146
163
|
yield ggapp.generateAPIFiles();
|
|
147
164
|
console.log("done");
|
|
148
165
|
// process.exit(0)
|
|
149
166
|
}));
|
|
150
167
|
}
|
|
151
|
-
|
|
168
|
+
run();
|
|
152
169
|
// setTimeout(() => {
|
|
153
170
|
// const x = new GGApi_v2()
|
|
154
171
|
// //@ts-ignore
|
package/package.json
CHANGED
|
@@ -1,56 +1,30 @@
|
|
|
1
1
|
export interface staticRouteInterface_hotel {
|
|
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
|
-
responseStructure: {
|
|
33
|
-
status: "SUCCESS" | "ERROR"
|
|
34
|
-
message: string
|
|
35
|
-
parameter: { numberOfPeople: number; itemName: string }
|
|
36
|
-
data: { id: number; name: string }[]
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
post: {
|
|
41
|
-
"/api/hotel/item": {
|
|
42
|
-
requireParams: {
|
|
43
|
-
parameter: Partial<{ lotNumber: number }>
|
|
44
|
-
data: Partial<{ id: number; name: "item-1" | "item-2"; price: number }>
|
|
45
|
-
}
|
|
46
|
-
responseStructure: {
|
|
47
|
-
status: "SUCCESS" | "ERROR"
|
|
48
|
-
message: string
|
|
49
|
-
parameter: { numberOfPeople: number; itemName: string }
|
|
50
|
-
data: { id: number; name: string }[]
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
put: {}
|
|
55
|
-
delete: {}
|
|
56
|
-
}
|
|
2
|
+
get : { "/api/hotel/users/id" : {
|
|
3
|
+
requireParams : { parameter:{ files : string[]}, data:{ id : number, bookingGroupID : number, checkInDate : string, checkOutDate : string, checkInTime : string, checkOutTime : string, roomRate : number, extraBedRate : number, roomNumber : string, editTime : string, createTime : string, shiftDate : string, shiftName : string, userName : string, bookingStatus : "ACTIVE" | "CLOSE" | "CANCEL" | "NO_SHOW", is_specificRoom : number, guestCount : number, reasonToCancel : string, note : string}[]},
|
|
4
|
+
responseStructure : {
|
|
5
|
+
status : "SUCCESS" | "ERROR",
|
|
6
|
+
message : string,
|
|
7
|
+
parameter : { numberOfPeople : number, itemName : string}, data : { id : number, name : string } []}
|
|
8
|
+
} , "/api/seed/memo/id" : {
|
|
9
|
+
requireParams : { parameter:{ files : string[]}, data:{ id : number, name : "A" | "B"}[]},
|
|
10
|
+
responseStructure : {
|
|
11
|
+
status : "SUCCESS" | "ERROR",
|
|
12
|
+
message : string,
|
|
13
|
+
parameter : { numberOfPeople : number, itemName : string}, data : { id : number, name : string } []}
|
|
14
|
+
} , "/api/hotel/memo/id" : {
|
|
15
|
+
requireParams : { parameter:{ files : string[]}, data:{ id : number, name : "A" | "B"}[]},
|
|
16
|
+
responseStructure : {
|
|
17
|
+
status : "SUCCESS" | "ERROR",
|
|
18
|
+
message : string,
|
|
19
|
+
parameter : { numberOfPeople : number, itemName : string}, data : { id : number, name : string } []}
|
|
20
|
+
} },
|
|
21
|
+
post : { "/api/hotel/item" : {
|
|
22
|
+
requireParams : { parameter:Partial<{ lotNumber : number}>, data:Partial<{ id : number, name : "item-1" | "item-2", price : number}>},
|
|
23
|
+
responseStructure : {
|
|
24
|
+
status : "SUCCESS" | "ERROR",
|
|
25
|
+
message : string,
|
|
26
|
+
parameter : { numberOfPeople : number, itemName : string}, data : { id : number, name : string } []}
|
|
27
|
+
} },
|
|
28
|
+
put : { },
|
|
29
|
+
delete : { },
|
|
30
|
+
}
|
package/src/v2/GGExpressV2.ts
CHANGED
|
@@ -6,7 +6,6 @@ import { generateStaticRouteFileV2 } from "./generateStaticRouteFileV2"
|
|
|
6
6
|
import path from "path"
|
|
7
7
|
import { generateGGApi_v2 } from "./generateGGApi_v2"
|
|
8
8
|
|
|
9
|
-
type Unarray<T> = T extends (infer U)[] ? U : T
|
|
10
9
|
export type Method = "get" | "post" | "put" | "delete"
|
|
11
10
|
|
|
12
11
|
type MyRequest<M extends Method, RQ extends ConstSchemaType> = M extends "get"
|
|
@@ -18,12 +17,22 @@ type MyRequest<M extends Method, RQ extends ConstSchemaType> = M extends "get"
|
|
|
18
17
|
type MyRequestQuery<T extends ConstSchemaType> = Request<{}, {}, {}, T, {}>
|
|
19
18
|
type MyRequestBody<T extends ConstSchemaType> = Request<{}, {}, T, {}, {}>
|
|
20
19
|
|
|
21
|
-
type
|
|
22
|
-
status: "SUCCESS"
|
|
20
|
+
type SuccessResponse<T extends ConstSchemaType> = {
|
|
21
|
+
status: "SUCCESS"
|
|
23
22
|
message: string
|
|
24
23
|
data: TypeResolve<T>
|
|
25
|
-
}
|
|
24
|
+
}
|
|
26
25
|
|
|
26
|
+
type ErrorResponse = {
|
|
27
|
+
status: "ERROR" | "SERVER_ERROR"
|
|
28
|
+
message: string
|
|
29
|
+
}
|
|
30
|
+
type MyResponse<T extends ConstSchemaType> = Response<
|
|
31
|
+
SuccessResponse<T> | ErrorResponse
|
|
32
|
+
>
|
|
33
|
+
type GGHandlerReturn<RS extends ConstSchemaType> = Response<
|
|
34
|
+
MyResponse<RS>
|
|
35
|
+
> | void // สำหรับ next()
|
|
27
36
|
const myExpressRouteList: {
|
|
28
37
|
method: "get" | "post" | "put" | "delete"
|
|
29
38
|
url: string
|
|
@@ -84,13 +93,8 @@ export default class GGExpressV2<appName extends string> {
|
|
|
84
93
|
|
|
85
94
|
// แต่ middleware ของคุณจะถูก wrap ทีละตัว
|
|
86
95
|
...middlewares.map(
|
|
87
|
-
(mw) =>
|
|
88
|
-
(
|
|
89
|
-
mw(
|
|
90
|
-
req as unknown as MyRequest<M, RQ>,
|
|
91
|
-
res as MyResponse<RS>,
|
|
92
|
-
next
|
|
93
|
-
)) as Express.RequestHandler
|
|
96
|
+
(mw) => (req: Request, res: Response, next: NextFunction) =>
|
|
97
|
+
mw(req as unknown as MyRequest<M, RQ>, res as MyResponse<RS>, next)
|
|
94
98
|
)
|
|
95
99
|
)
|
|
96
100
|
}
|
|
@@ -85,9 +85,12 @@ function parentInputToCode(data: ConstSchemaType) {
|
|
|
85
85
|
target[0] === null ||
|
|
86
86
|
target[0] === undefined
|
|
87
87
|
)
|
|
88
|
-
return `${parentKeyName} : [${(target as string[])
|
|
88
|
+
// return `${parentKeyName} : [${(target as string[])
|
|
89
|
+
// .map((word) => ` "${word}" `)
|
|
90
|
+
// .join(",")}] `
|
|
91
|
+
return `${parentKeyName} : ${(target as string[])
|
|
89
92
|
.map((word) => ` "${word}" `)
|
|
90
|
-
.join("
|
|
93
|
+
.join("|")} `
|
|
91
94
|
// nest or input nest
|
|
92
95
|
else if (typeof target[0] === "object")
|
|
93
96
|
for (const row of target as ConstSchemaType[]) {
|
|
@@ -1,24 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
export interface staticRouteInterface_hotel_v2 {
|
|
2
|
+
get: {
|
|
3
|
+
"/api/hotel/users/id": {
|
|
4
|
+
requireParams: {
|
|
5
|
+
id: number
|
|
6
|
+
data: {
|
|
7
|
+
id: number
|
|
8
|
+
bookingGroupID: number
|
|
9
|
+
checkInDate: string
|
|
10
|
+
checkOutDate: string
|
|
11
|
+
checkInTime: string
|
|
12
|
+
checkOutTime: string
|
|
13
|
+
roomRate: number
|
|
14
|
+
extraBedRate: number
|
|
15
|
+
roomNumber: string
|
|
16
|
+
editTime: string
|
|
17
|
+
createTime: string
|
|
18
|
+
shiftDate: string
|
|
19
|
+
shiftName: string
|
|
20
|
+
userName: string
|
|
21
|
+
bookingStatus: "ACTIVE" | "CLOSE" | "CANCEL" | "NO_SHOW"
|
|
22
|
+
is_specificRoom: number
|
|
23
|
+
guestCount: number
|
|
24
|
+
reasonToCancel: string
|
|
25
|
+
note: string
|
|
26
|
+
}
|
|
27
|
+
name: string
|
|
28
|
+
status: "on" | "off"
|
|
29
|
+
}
|
|
30
|
+
responseStructure: {
|
|
31
|
+
data: {
|
|
32
|
+
x: string
|
|
33
|
+
data: {
|
|
34
|
+
zoneID: number
|
|
35
|
+
zoneName: string
|
|
36
|
+
data: {
|
|
37
|
+
itemID: number
|
|
38
|
+
itemEachHotelID: number
|
|
39
|
+
itemName: string
|
|
40
|
+
requisitionQty: { expected: number; actual: number }
|
|
41
|
+
zoneStockQty: { begin: number; end: number }
|
|
42
|
+
usedQty: number
|
|
43
|
+
lossQty: number
|
|
44
|
+
damageQty: number
|
|
45
|
+
returnQty: { expected: number; actual: number }
|
|
46
|
+
notReturnQty: number
|
|
47
|
+
}[]
|
|
48
|
+
}[]
|
|
49
|
+
}
|
|
50
|
+
status: "SUCCESS" | "ERROR"
|
|
51
|
+
message: string
|
|
52
|
+
}
|
|
53
|
+
}
|
|
23
54
|
}
|
|
24
|
-
|
|
55
|
+
post: {
|
|
56
|
+
"/api/hotel/booking/id": {
|
|
57
|
+
requireParams: { id: number }
|
|
58
|
+
responseStructure: {
|
|
59
|
+
data: {
|
|
60
|
+
bookingData: { id: number; roomNumber: string }
|
|
61
|
+
}
|
|
62
|
+
status: "SUCCESS" | "ERROR"
|
|
63
|
+
message: string
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
put: {}
|
|
68
|
+
delete: {}
|
|
69
|
+
}
|
package/src/v2/run_v2.test.ts
CHANGED
|
@@ -139,13 +139,35 @@ function run() {
|
|
|
139
139
|
}
|
|
140
140
|
)
|
|
141
141
|
|
|
142
|
+
ggapp.post(
|
|
143
|
+
"/api/hotel/booking/id",
|
|
144
|
+
{
|
|
145
|
+
requireParams: {
|
|
146
|
+
id: "number",
|
|
147
|
+
},
|
|
148
|
+
responseStructure: {
|
|
149
|
+
bookingData: {
|
|
150
|
+
id: "number",
|
|
151
|
+
roomNumber: "string",
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
(req, res, next) => {
|
|
156
|
+
req.body.id
|
|
157
|
+
return res.json({
|
|
158
|
+
status: "ERROR",
|
|
159
|
+
message: "",
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
)
|
|
163
|
+
|
|
142
164
|
app.listen(3002, async () => {
|
|
143
165
|
await ggapp.generateAPIFiles()
|
|
144
166
|
console.log("done")
|
|
145
167
|
// process.exit(0)
|
|
146
168
|
})
|
|
147
169
|
}
|
|
148
|
-
|
|
170
|
+
run()
|
|
149
171
|
|
|
150
172
|
// setTimeout(() => {
|
|
151
173
|
// const x = new GGApi_v2()
|
package/src/v2/typeResolver.ts
CHANGED
|
@@ -10,6 +10,7 @@ type BaseType =
|
|
|
10
10
|
|
|
11
11
|
type CustomType = BaseType | `${BaseType}?` | `${BaseType}~` | `${BaseType}?~`
|
|
12
12
|
type InputEnum = readonly string[] | readonly number[]
|
|
13
|
+
|
|
13
14
|
export type ConstSchemaType = {
|
|
14
15
|
[key in string]: CustomType | ConstSchemaType | ConstSchemaType[] | InputEnum
|
|
15
16
|
}
|