create-nexwire 4.0.0 → 4.1.0
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/README.md +5 -4
- package/express/.env +1 -1
- package/express/README.md +13 -7
- package/express/package.json +2 -2
- package/express/src/config/session.ts +1 -1
- package/express/src/database/migrations/sqlite/meta/0000_snapshot.json +1 -1
- package/express/src/database/migrations/sqlite/meta/_journal.json +1 -1
- package/express/src/database/schema.ts +3 -3
- package/express/src/framework/cache/cache.ts +82 -81
- package/express/src/framework/database/seed.ts +1 -1
- package/express/src/framework/facade.ts +1 -24
- package/express/src/framework/http/app.ts +5 -5
- package/express/src/framework/http/openapi.ts +1 -1
- package/express/src/framework/http/router.ts +3 -18
- package/express/src/framework/http/types.ts +19 -0
- package/express/src/framework/http/validation.ts +18 -18
- package/express/src/framework/maker-cli/middleware/core.mjs +41 -47
- package/express/src/framework/maker-cli/module/core.mjs +920 -684
- package/express/src/framework/maker-cli/module/index.mjs +202 -140
- package/express/src/framework/maker-cli/runtime/core.mjs +1 -2
- package/express/src/framework/maker-cli/stubs/controller/openapi.ts.stub +40 -14
- package/express/src/framework/maker-cli/stubs/controller/openapi.with-model.ts.stub +40 -15
- package/express/src/framework/maker-cli/stubs/controller/plain.ts.stub +42 -16
- package/express/src/framework/maker-cli/stubs/controller/standalone.ts.stub +47 -0
- package/express/src/framework/maker-cli/stubs/facade/name.ts.stub +12 -0
- package/express/src/framework/maker-cli/stubs/helper/name.ts.stub +14 -0
- package/express/src/framework/maker-cli/stubs/middleware/name.local.ts.stub +15 -0
- package/express/src/framework/maker-cli/stubs/model/name.mysql.ts.stub +9 -8
- package/express/src/framework/maker-cli/stubs/model/name.postgresql.ts.stub +9 -8
- package/express/src/framework/maker-cli/stubs/model/name.sqlite.ts.stub +9 -8
- package/express/src/framework/maker-cli/stubs/notification/route.api.ts.stub +50 -50
- package/express/src/framework/maker-cli/stubs/notification/route.plain.ts.stub +11 -11
- package/express/src/framework/maker-cli/stubs/route/api.ts.stub +93 -79
- package/express/src/framework/maker-cli/stubs/route/plain.ts.stub +23 -10
- package/express/src/framework/maker-cli/stubs/route/standalone.api.ts.stub +113 -0
- package/express/src/framework/maker-cli/stubs/route/standalone.plain.ts.stub +37 -0
- package/express/src/framework/maker-cli/stubs/{controller/schema.plain.ts.stub → schema/name.plain.ts.stub} +13 -13
- package/express/src/framework/maker-cli/stubs/{controller/schema.ts.stub → schema/name.ts.stub} +32 -32
- package/express/src/framework/maker-cli/stubs/service/name.plain.ts.stub +67 -0
- package/express/src/framework/maker-cli/stubs/service/name.ts.stub +65 -0
- package/express/src/framework/maker-cli/stubs/type/name.ts.stub +22 -0
- package/express/src/framework/maker-cli/utils/naming.mjs +56 -13
- package/express/src/framework/modules/discover.ts +57 -54
- package/express/src/framework/notification/index.ts +1 -1
- package/express/src/framework/realtime/broadcast.ts +46 -46
- package/express/src/framework/server.ts +2 -1
- package/express/src/framework/session/session.ts +102 -98
- package/express/src/framework/support/mail.ts +48 -48
- package/express/src/framework/support/status-codes.ts +75 -0
- package/express/src/middlewares/auth-middleware.ts +1 -1
- package/express/src/modules/auth/__tests__/forgetpass.test.ts +200 -0
- package/express/src/modules/auth/__tests__/login.test.ts +171 -0
- package/express/src/modules/auth/__tests__/logout.test.ts +60 -0
- package/express/src/modules/auth/__tests__/logoutalldevices.test.ts +49 -0
- package/express/src/modules/auth/__tests__/me.test.ts +91 -0
- package/express/src/modules/auth/__tests__/refreshtoken.test.ts +305 -0
- package/express/src/modules/auth/__tests__/register.test.ts +291 -0
- package/express/src/modules/auth/__tests__/resetpass.test.ts +206 -0
- package/express/src/modules/auth/__tests__/verifyemail.test.ts +183 -0
- package/express/src/modules/auth/controllers/auth.ts +254 -0
- package/express/src/modules/auth/controllers/{role.controller.ts → role.ts} +25 -15
- package/{hono/src/modules/auth/database/models/notifications.ts → express/src/modules/auth/database/models/notification.ts} +1 -1
- package/express/src/modules/auth/database/models/role.ts +1 -1
- package/express/src/modules/auth/database/models/user.ts +1 -1
- package/express/src/modules/auth/facade.ts +12 -0
- package/express/src/modules/auth/{controllers/auth.helpers.ts → helpers/auth.ts} +3 -4
- package/express/src/modules/auth/jobs/registeruser.ts +23 -23
- package/express/src/modules/auth/routes/{api.ts → index.ts} +150 -150
- package/express/src/modules/auth/routes/role.ts +33 -33
- package/{hono/src/modules/auth/controllers/auth.schema.ts → express/src/modules/auth/schemas/auth.ts} +102 -102
- package/express/src/modules/auth/services/forgetpassword.ts +66 -0
- package/express/src/modules/auth/services/login.ts +63 -0
- package/express/src/modules/auth/services/logout.ts +25 -0
- package/express/src/modules/auth/services/logoutalldevices.ts +19 -0
- package/express/src/modules/auth/services/me.ts +31 -0
- package/express/src/modules/auth/services/refreshtoken.ts +110 -0
- package/express/src/modules/auth/services/register.ts +141 -0
- package/express/src/modules/auth/services/resetpassword.ts +69 -0
- package/express/src/modules/auth/services/verifyemail.ts +77 -0
- package/express/src/modules/auth/types/auth.ts +31 -0
- package/express/src/resources/src/assets/images/logo.png +0 -0
- package/express/src/resources/src/pages/auth/forgetPassword.vue +1 -0
- package/express/src/resources/src/pages/auth/login.vue +1 -1
- package/express/src/storage/database/nexwire.sqlite +0 -0
- package/hono/.env +1 -1
- package/hono/README.md +13 -7
- package/hono/package.json +1 -1
- package/hono/src/config/session.ts +1 -1
- package/hono/src/database/migrations/sqlite/meta/0000_snapshot.json +1 -1
- package/hono/src/database/migrations/sqlite/meta/_journal.json +1 -1
- package/hono/src/database/schema.ts +3 -3
- package/hono/src/framework/cache/cache.ts +82 -81
- package/hono/src/framework/database/seed.ts +1 -1
- package/hono/src/framework/http/app.ts +5 -5
- package/hono/src/framework/http/validation.ts +21 -21
- package/hono/src/framework/maker-cli/middleware/core.mjs +40 -46
- package/hono/src/framework/maker-cli/module/core.mjs +401 -168
- package/hono/src/framework/maker-cli/module/index.mjs +73 -11
- package/hono/src/framework/maker-cli/stubs/controller/openapi.ts.stub +28 -16
- package/hono/src/framework/maker-cli/stubs/controller/openapi.with-model.ts.stub +28 -17
- package/hono/src/framework/maker-cli/stubs/controller/plain.ts.stub +28 -16
- package/hono/src/framework/maker-cli/stubs/controller/standalone.ts.stub +56 -0
- package/hono/src/framework/maker-cli/stubs/facade/name.ts.stub +12 -0
- package/hono/src/framework/maker-cli/stubs/helper/name.ts.stub +14 -0
- package/hono/src/framework/maker-cli/stubs/middleware/name.local.ts.stub +15 -0
- package/hono/src/framework/maker-cli/stubs/model/name.mysql.ts.stub +9 -8
- package/hono/src/framework/maker-cli/stubs/model/name.postgresql.ts.stub +9 -8
- package/hono/src/framework/maker-cli/stubs/model/name.sqlite.ts.stub +9 -8
- package/hono/src/framework/maker-cli/stubs/notification/route.api.ts.stub +49 -49
- package/hono/src/framework/maker-cli/stubs/notification/route.plain.ts.stub +11 -11
- package/hono/src/framework/maker-cli/stubs/route/api.ts.stub +93 -79
- package/hono/src/framework/maker-cli/stubs/route/plain.ts.stub +23 -10
- package/hono/src/framework/maker-cli/stubs/route/standalone.api.ts.stub +112 -0
- package/hono/src/framework/maker-cli/stubs/route/standalone.plain.ts.stub +37 -0
- package/hono/src/framework/maker-cli/stubs/{controller/schema.plain.ts.stub → schema/name.plain.ts.stub} +13 -13
- package/hono/src/framework/maker-cli/stubs/{controller/schema.ts.stub → schema/name.ts.stub} +32 -32
- package/hono/src/framework/maker-cli/stubs/service/name.plain.ts.stub +67 -0
- package/hono/src/framework/maker-cli/stubs/service/name.ts.stub +65 -0
- package/hono/src/framework/maker-cli/stubs/type/name.ts.stub +22 -0
- package/hono/src/framework/maker-cli/utils/naming.mjs +56 -13
- package/hono/src/framework/modules/discover.ts +57 -54
- package/hono/src/framework/notification/index.ts +1 -1
- package/hono/src/framework/realtime/broadcast.ts +46 -46
- package/hono/src/framework/server.ts +1 -1
- package/hono/src/framework/session/session.ts +121 -116
- package/hono/src/middlewares/auth-middleware.ts +1 -1
- package/hono/src/modules/auth/__tests__/forgetpass.test.ts +170 -0
- package/hono/src/modules/auth/__tests__/login.test.ts +154 -0
- package/hono/src/modules/auth/__tests__/logout.test.ts +53 -0
- package/hono/src/modules/auth/__tests__/logoutalldevices.test.ts +34 -0
- package/hono/src/modules/auth/__tests__/me.test.ts +87 -0
- package/hono/src/modules/auth/__tests__/refreshtoken.test.ts +305 -0
- package/hono/src/modules/auth/__tests__/register.test.ts +258 -0
- package/hono/src/modules/auth/__tests__/resetpass.test.ts +214 -0
- package/hono/src/modules/auth/__tests__/verifyemail.test.ts +189 -0
- package/hono/src/modules/auth/controllers/auth.ts +238 -0
- package/hono/src/modules/auth/controllers/{role.controller.ts → role.ts} +25 -25
- package/{express/src/modules/auth/database/models/notifications.ts → hono/src/modules/auth/database/models/notification.ts} +1 -1
- package/hono/src/modules/auth/database/models/role.ts +1 -1
- package/hono/src/modules/auth/database/models/user.ts +1 -1
- package/hono/src/modules/auth/facade.ts +12 -0
- package/hono/src/modules/auth/{controllers/auth.helpers.ts → helpers/auth.ts} +5 -6
- package/hono/src/modules/auth/jobs/registeruser.ts +23 -23
- package/hono/src/modules/auth/routes/{api.ts → index.ts} +150 -150
- package/hono/src/modules/auth/routes/role.ts +33 -33
- package/{express/src/modules/auth/controllers/auth.schema.ts → hono/src/modules/auth/schemas/auth.ts} +102 -102
- package/hono/src/modules/auth/services/forgetpassword.ts +58 -0
- package/hono/src/modules/auth/services/login.ts +61 -0
- package/hono/src/modules/auth/services/logout.ts +24 -0
- package/hono/src/modules/auth/services/logoutalldevices.ts +19 -0
- package/hono/src/modules/auth/services/me.ts +31 -0
- package/hono/src/modules/auth/services/refreshtoken.ts +110 -0
- package/hono/src/modules/auth/services/register.ts +132 -0
- package/hono/src/modules/auth/services/resetpassword.ts +69 -0
- package/hono/src/modules/auth/services/verifyemail.ts +77 -0
- package/hono/src/modules/auth/types/auth.ts +31 -0
- package/hono/src/resources/src/assets/images/logo.png +0 -0
- package/hono/src/storage/database/nexwire.sqlite +0 -0
- package/package.json +1 -1
- package/express/src/framework/maker-cli/stubs/example/console.ts.stub +0 -34
- package/express/src/framework/maker-cli/stubs/example/controller.ts.stub +0 -418
- package/express/src/framework/maker-cli/stubs/example/job.ts.stub +0 -75
- package/express/src/framework/maker-cli/stubs/example/route.api.ts.stub +0 -207
- package/express/src/framework/maker-cli/stubs/example/route.plain.ts.stub +0 -18
- package/express/src/framework/maker-cli/stubs/example/schema.plain.ts.stub +0 -42
- package/express/src/framework/maker-cli/stubs/example/schema.ts.stub +0 -42
- package/express/src/modules/auth/controllers/auth.controller.ts +0 -358
- package/hono/src/framework/maker-cli/stubs/example/console.ts.stub +0 -34
- package/hono/src/framework/maker-cli/stubs/example/controller.ts.stub +0 -505
- package/hono/src/framework/maker-cli/stubs/example/job.ts.stub +0 -75
- package/hono/src/framework/maker-cli/stubs/example/route.api.ts.stub +0 -207
- package/hono/src/framework/maker-cli/stubs/example/route.plain.ts.stub +0 -18
- package/hono/src/framework/maker-cli/stubs/example/schema.plain.ts.stub +0 -42
- package/hono/src/framework/maker-cli/stubs/example/schema.ts.stub +0 -42
- package/hono/src/modules/auth/controllers/auth.controller.ts +0 -413
|
@@ -1,54 +1,80 @@
|
|
|
1
1
|
import type { Request, Response } from "express";
|
|
2
2
|
import { HttpStatusCodes } from "@/framework/facade.js";
|
|
3
3
|
import { validate } from "@/framework/facade.js";
|
|
4
|
-
import { Create{{ClassName}}Schema, Update{{ClassName}}Schema, {{ClassName}}IdParamsSchema } from "@/modules/{{module}}/
|
|
4
|
+
import { Create{{ClassName}}Schema, Update{{ClassName}}Schema, {{ClassName}}IdParamsSchema } from "@/modules/{{module}}/schemas/{{controller}}.js";
|
|
5
|
+
import { {{controller}}Service } from "@/modules/{{module}}/services/{{controller}}.js";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
|
-
* Why: Returns
|
|
8
|
+
* Why: Returns every {{controller}} row for list screens.
|
|
8
9
|
* When: Used by GET list endpoint.
|
|
9
10
|
* Where: GET /{{controller}} route.
|
|
10
11
|
*/
|
|
11
12
|
export const index = async (_req: Request, res: Response) => {
|
|
12
|
-
|
|
13
|
+
const data = await {{controller}}Service.list();
|
|
14
|
+
|
|
15
|
+
res.json({ message: "{{controller}} list fetched successfully", data });
|
|
13
16
|
};
|
|
14
17
|
|
|
15
18
|
/**
|
|
16
|
-
* Why: Returns one
|
|
19
|
+
* Why: Returns one {{controller}} row by validated route id.
|
|
17
20
|
* When: Used by detail screens or fetch-by-id calls.
|
|
18
21
|
* Where: GET /{{controller}}/{id} route.
|
|
19
22
|
*/
|
|
20
23
|
export const show = async (req: Request, res: Response) => {
|
|
21
24
|
const params = await validate({{ClassName}}IdParamsSchema, req.params);
|
|
22
|
-
|
|
25
|
+
const data = await {{controller}}Service.findOne(params.id);
|
|
26
|
+
|
|
27
|
+
if (!data) {
|
|
28
|
+
res.status(HttpStatusCodes.NOT_FOUND).json({ message: "{{controller}} not found" });
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
res.json({ message: "{{controller}} fetched successfully", data });
|
|
23
33
|
};
|
|
24
34
|
|
|
25
35
|
/**
|
|
26
|
-
* Why: Creates a new
|
|
36
|
+
* Why: Creates a new {{controller}} row from a validated request body.
|
|
27
37
|
* When: Used by create form submissions.
|
|
28
38
|
* Where: POST /{{controller}} route.
|
|
29
39
|
*/
|
|
30
40
|
export const store = async (req: Request, res: Response) => {
|
|
31
|
-
await validate(Create{{ClassName}}Schema, req.body);
|
|
32
|
-
|
|
41
|
+
const body = await validate(Create{{ClassName}}Schema, req.body);
|
|
42
|
+
const data = await {{controller}}Service.create(body);
|
|
43
|
+
|
|
44
|
+
res.status(HttpStatusCodes.CREATED).json({ message: "{{controller}} created successfully", data });
|
|
33
45
|
};
|
|
34
46
|
|
|
35
47
|
/**
|
|
36
|
-
* Why: Updates an existing
|
|
48
|
+
* Why: Updates an existing {{controller}} row using id + body validation.
|
|
37
49
|
* When: Used by edit/update form submissions.
|
|
38
50
|
* Where: PUT/PATCH /{{controller}}/{id} route.
|
|
39
51
|
*/
|
|
40
52
|
export const update = async (req: Request, res: Response) => {
|
|
41
|
-
await validate({{ClassName}}IdParamsSchema, req.params);
|
|
42
|
-
await validate(Update{{ClassName}}Schema, req.body);
|
|
43
|
-
|
|
53
|
+
const params = await validate({{ClassName}}IdParamsSchema, req.params);
|
|
54
|
+
const body = await validate(Update{{ClassName}}Schema, req.body);
|
|
55
|
+
const data = await {{controller}}Service.update(params.id, body);
|
|
56
|
+
|
|
57
|
+
if (!data) {
|
|
58
|
+
res.status(HttpStatusCodes.NOT_FOUND).json({ message: "{{controller}} not found" });
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
res.json({ message: "{{controller}} updated successfully", data });
|
|
44
63
|
};
|
|
45
64
|
|
|
46
65
|
/**
|
|
47
|
-
* Why: Deletes one
|
|
66
|
+
* Why: Deletes one {{controller}} row by validated route id.
|
|
48
67
|
* When: Used by delete actions.
|
|
49
68
|
* Where: DELETE /{{controller}}/{id} route.
|
|
50
69
|
*/
|
|
51
70
|
export const destroy = async (req: Request, res: Response) => {
|
|
52
|
-
await validate({{ClassName}}IdParamsSchema, req.params);
|
|
53
|
-
|
|
54
|
-
|
|
71
|
+
const params = await validate({{ClassName}}IdParamsSchema, req.params);
|
|
72
|
+
const data = await {{controller}}Service.remove(params.id);
|
|
73
|
+
|
|
74
|
+
if (!data) {
|
|
75
|
+
res.status(HttpStatusCodes.NOT_FOUND).json({ message: "{{controller}} not found" });
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
res.json({ message: "{{controller}} deleted successfully", data });
|
|
80
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Request, Response } from "express";
|
|
2
|
+
import { HttpStatusCodes } from "@/framework/facade.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Why: Returns collection response shape for list pages.
|
|
6
|
+
* When: Used by GET list endpoint.
|
|
7
|
+
* Where: GET /{{controller}} route.
|
|
8
|
+
*/
|
|
9
|
+
export const index = async (_req: Request, res: Response) => {
|
|
10
|
+
res.json({ message: "{{controller}} list fetched successfully", data: [] });
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Why: Returns one resource by validated route id.
|
|
15
|
+
* When: Used by detail screens or fetch-by-id calls.
|
|
16
|
+
* Where: GET /{{controller}}/{id} route.
|
|
17
|
+
*/
|
|
18
|
+
export const show = async (req: Request, res: Response) => {
|
|
19
|
+
res.json({ message: "{{controller}} fetched successfully", data: { id: req.params.id, name: "" } });
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Why: Creates a new resource from validated request body.
|
|
24
|
+
* When: Used by create form submissions.
|
|
25
|
+
* Where: POST /{{controller}} route.
|
|
26
|
+
*/
|
|
27
|
+
export const store = async (_req: Request, res: Response) => {
|
|
28
|
+
res.status(HttpStatusCodes.CREATED).json({ message: "{{controller}} created successfully" });
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Why: Updates an existing resource using id + body validation.
|
|
33
|
+
* When: Used by edit/update form submissions.
|
|
34
|
+
* Where: PUT/PATCH /{{controller}}/{id} route.
|
|
35
|
+
*/
|
|
36
|
+
export const update = async (_req: Request, res: Response) => {
|
|
37
|
+
res.json({ message: "{{controller}} updated successfully" });
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Why: Deletes one resource by validated route id.
|
|
42
|
+
* When: Used by delete actions.
|
|
43
|
+
* Where: DELETE /{{controller}}/{id} route.
|
|
44
|
+
*/
|
|
45
|
+
export const destroy = async (_req: Request, res: Response) => {
|
|
46
|
+
res.json({ message: "{{controller}} deleted successfully" });
|
|
47
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public API for the {{module}} module.
|
|
3
|
+
*
|
|
4
|
+
* Other modules import from this file, never from controllers/ or services/ directly.
|
|
5
|
+
* Re-export the pieces they are allowed to depend on:
|
|
6
|
+
*
|
|
7
|
+
* export { list, findOne } from "./services/{{controller}}.js";
|
|
8
|
+
*
|
|
9
|
+
* Rule: a facade must never import another module's facade.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why: Reusable {{name}} logic that does not belong to a controller or service.
|
|
3
|
+
* When: Called by controllers, services, jobs, or other helpers.
|
|
4
|
+
* Where: src/modules/{{module}}/helpers/{{name}}.ts
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Why: Placeholder shared helper.
|
|
9
|
+
* When: Replace this with real logic and rename it.
|
|
10
|
+
* Where: Anywhere inside the {{module}} module.
|
|
11
|
+
*/
|
|
12
|
+
export function {{name}}Helper<T>(value: T): T {
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { NextFunction, Request, Response } from "express";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Why: Route-scoped middleware for the {{module}} module.
|
|
5
|
+
* When: Attach to a route or route group inside routes/*.ts.
|
|
6
|
+
* Where: src/modules/{{module}}/middlewares/{{name}}.ts
|
|
7
|
+
*
|
|
8
|
+
* Register it in a route file:
|
|
9
|
+
* import { {{camel}}Middleware } from "@/modules/{{module}}/middlewares/{{name}}.js";
|
|
10
|
+
* router.get("/path", {{camel}}Middleware, handler);
|
|
11
|
+
*/
|
|
12
|
+
export function {{camel}}Middleware(_req: Request, _res: Response, next: NextFunction) {
|
|
13
|
+
// Guard the route here, then continue the chain.
|
|
14
|
+
return next();
|
|
15
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { relations } from "drizzle-orm";
|
|
2
|
-
import { int, mysqlTable, timestamp } from "drizzle-orm/mysql-core";
|
|
3
|
-
|
|
4
|
-
export const {{tableVariable}} = mysqlTable("{{tableName}}", {
|
|
5
|
-
id: int("id").autoincrement().primaryKey(),
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { relations } from "drizzle-orm";
|
|
2
|
+
import { int, mysqlTable, timestamp, varchar } from "drizzle-orm/mysql-core";
|
|
3
|
+
|
|
4
|
+
export const {{tableVariable}} = mysqlTable("{{tableName}}", {
|
|
5
|
+
id: int("id").autoincrement().primaryKey(),
|
|
6
|
+
name: varchar("name", { length: 255 }).notNull(),
|
|
7
|
+
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
8
|
+
updatedAt: timestamp("updated_at").defaultNow().notNull()
|
|
9
|
+
});
|
|
9
10
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { relations } from "drizzle-orm";
|
|
2
|
-
import { pgTable, serial, timestamp } from "drizzle-orm/pg-core";
|
|
3
|
-
|
|
4
|
-
export const {{tableVariable}} = pgTable("{{tableName}}", {
|
|
5
|
-
id: serial("id").primaryKey(),
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
})
|
|
1
|
+
import { relations } from "drizzle-orm";
|
|
2
|
+
import { pgTable, serial, text, timestamp } from "drizzle-orm/pg-core";
|
|
3
|
+
|
|
4
|
+
export const {{tableVariable}} = pgTable("{{tableName}}", {
|
|
5
|
+
id: serial("id").primaryKey(),
|
|
6
|
+
name: text("name").notNull(),
|
|
7
|
+
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
|
|
8
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull()
|
|
9
|
+
});
|
|
9
10
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { relations } from "drizzle-orm";
|
|
2
|
-
import { integer, sqliteTable } from "drizzle-orm/sqlite-core";
|
|
3
|
-
|
|
4
|
-
export const {{tableVariable}} = sqliteTable("{{tableName}}", {
|
|
5
|
-
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
})
|
|
1
|
+
import { relations } from "drizzle-orm";
|
|
2
|
+
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
3
|
+
|
|
4
|
+
export const {{tableVariable}} = sqliteTable("{{tableName}}", {
|
|
5
|
+
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
6
|
+
name: text("name").notNull(),
|
|
7
|
+
createdAt: integer("created_at", { mode: "timestamp" }).$defaultFn(() => new Date()).notNull(),
|
|
8
|
+
updatedAt: integer("updated_at", { mode: "timestamp" }).$defaultFn(() => new Date()).notNull()
|
|
9
|
+
});
|
|
9
10
|
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import { createRoute, createRouter, HttpStatusCodes, jsonContent, z } from "@/framework/facade.js";
|
|
2
|
-
import { authMiddleware } from "@/middlewares/auth-middleware.js";
|
|
3
|
-
import { list, markAllRead, markRead, remove, unreadCount } from "../controllers/{{module}}.
|
|
4
|
-
import { PaginatedNotificationsSchema, UnreadCountSchema } from "../
|
|
5
|
-
|
|
6
|
-
const listRoute = createRoute({
|
|
7
|
-
path: "/",
|
|
8
|
-
method: "get",
|
|
9
|
-
tags: ["Notifications"],
|
|
10
|
-
responses: { [HttpStatusCodes.OK]: jsonContent(PaginatedNotificationsSchema, "Paginated notifications") },
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
const unreadCountRoute = createRoute({
|
|
14
|
-
path: "/unread-count",
|
|
15
|
-
method: "get",
|
|
16
|
-
tags: ["Notifications"],
|
|
17
|
-
responses: { [HttpStatusCodes.OK]: jsonContent(UnreadCountSchema, "Unread count") },
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const markReadRoute = createRoute({
|
|
21
|
-
path: "/{id}/read",
|
|
22
|
-
method: "patch",
|
|
23
|
-
tags: ["Notifications"],
|
|
24
|
-
request: { params: z.object({ id: z.coerce.number() }) },
|
|
25
|
-
responses: { [HttpStatusCodes.OK]: jsonContent(z.object({ ok: z.boolean() }), "Marked as read") },
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const markAllReadRoute = createRoute({
|
|
29
|
-
path: "/read-all",
|
|
30
|
-
method: "patch",
|
|
31
|
-
tags: ["Notifications"],
|
|
32
|
-
responses: { [HttpStatusCodes.OK]: jsonContent(z.object({ ok: z.boolean() }), "All marked as read") },
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const deleteRoute = createRoute({
|
|
36
|
-
path: "/{id}",
|
|
37
|
-
method: "delete",
|
|
38
|
-
tags: ["Notifications"],
|
|
39
|
-
request: { params: z.object({ id: z.coerce.number() }) },
|
|
40
|
-
responses: { [HttpStatusCodes.OK]: jsonContent(z.object({ ok: z.boolean() }), "Deleted") },
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
export default createRouter()
|
|
44
|
-
.group(authMiddleware)
|
|
45
|
-
.api(listRoute, list)
|
|
46
|
-
.api(unreadCountRoute, unreadCount)
|
|
47
|
-
.api(markReadRoute, markRead)
|
|
48
|
-
.api(markAllReadRoute, markAllRead)
|
|
49
|
-
.api(deleteRoute, remove);
|
|
50
|
-
|
|
1
|
+
import { createRoute, createRouter, HttpStatusCodes, jsonContent, z } from "@/framework/facade.js";
|
|
2
|
+
import { authMiddleware } from "@/middlewares/auth-middleware.js";
|
|
3
|
+
import { list, markAllRead, markRead, remove, unreadCount } from "../controllers/{{module}}.js";
|
|
4
|
+
import { PaginatedNotificationsSchema, UnreadCountSchema } from "../schemas/{{module}}.js";
|
|
5
|
+
|
|
6
|
+
const listRoute = createRoute({
|
|
7
|
+
path: "/",
|
|
8
|
+
method: "get",
|
|
9
|
+
tags: ["Notifications"],
|
|
10
|
+
responses: { [HttpStatusCodes.OK]: jsonContent(PaginatedNotificationsSchema, "Paginated notifications") },
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const unreadCountRoute = createRoute({
|
|
14
|
+
path: "/unread-count",
|
|
15
|
+
method: "get",
|
|
16
|
+
tags: ["Notifications"],
|
|
17
|
+
responses: { [HttpStatusCodes.OK]: jsonContent(UnreadCountSchema, "Unread count") },
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const markReadRoute = createRoute({
|
|
21
|
+
path: "/{id}/read",
|
|
22
|
+
method: "patch",
|
|
23
|
+
tags: ["Notifications"],
|
|
24
|
+
request: { params: z.object({ id: z.coerce.number() }) },
|
|
25
|
+
responses: { [HttpStatusCodes.OK]: jsonContent(z.object({ ok: z.boolean() }), "Marked as read") },
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const markAllReadRoute = createRoute({
|
|
29
|
+
path: "/read-all",
|
|
30
|
+
method: "patch",
|
|
31
|
+
tags: ["Notifications"],
|
|
32
|
+
responses: { [HttpStatusCodes.OK]: jsonContent(z.object({ ok: z.boolean() }), "All marked as read") },
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const deleteRoute = createRoute({
|
|
36
|
+
path: "/{id}",
|
|
37
|
+
method: "delete",
|
|
38
|
+
tags: ["Notifications"],
|
|
39
|
+
request: { params: z.object({ id: z.coerce.number() }) },
|
|
40
|
+
responses: { [HttpStatusCodes.OK]: jsonContent(z.object({ ok: z.boolean() }), "Deleted") },
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export default createRouter()
|
|
44
|
+
.group(authMiddleware)
|
|
45
|
+
.api(listRoute, list)
|
|
46
|
+
.api(unreadCountRoute, unreadCount)
|
|
47
|
+
.api(markReadRoute, markRead)
|
|
48
|
+
.api(markAllReadRoute, markAllRead)
|
|
49
|
+
.api(deleteRoute, remove);
|
|
50
|
+
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { group } from "@/framework/facade.js";
|
|
2
|
-
import { authMiddleware } from "@/middlewares/auth-middleware.js";
|
|
3
|
-
import { list, unreadCount, markRead, markAllRead, remove } from "../controllers/{{module}}.
|
|
4
|
-
|
|
5
|
-
export default group()
|
|
6
|
-
.use(authMiddleware)
|
|
7
|
-
.get("/", list)
|
|
8
|
-
.get("/unread-count", unreadCount)
|
|
9
|
-
.patch("/:id/read", markRead)
|
|
10
|
-
.patch("/read-all", markAllRead)
|
|
11
|
-
.delete("/:id", remove);
|
|
1
|
+
import { group } from "@/framework/facade.js";
|
|
2
|
+
import { authMiddleware } from "@/middlewares/auth-middleware.js";
|
|
3
|
+
import { list, unreadCount, markRead, markAllRead, remove } from "../controllers/{{module}}.js";
|
|
4
|
+
|
|
5
|
+
export default group()
|
|
6
|
+
.use(authMiddleware)
|
|
7
|
+
.get("/", list)
|
|
8
|
+
.get("/unread-count", unreadCount)
|
|
9
|
+
.patch("/:id/read", markRead)
|
|
10
|
+
.patch("/read-all", markAllRead)
|
|
11
|
+
.delete("/:id", remove);
|
|
12
12
|
|
|
@@ -1,80 +1,94 @@
|
|
|
1
|
-
import { createRoute, group, HttpStatusCodes, jsonContent } from "@/framework/facade.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
{{ClassName}}
|
|
7
|
-
{{ClassName}}
|
|
8
|
-
{{ClassName}}
|
|
9
|
-
{{ClassName}}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
[HttpStatusCodes.
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
[HttpStatusCodes.
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
[HttpStatusCodes.
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
.api(
|
|
77
|
-
.api(
|
|
78
|
-
.api(
|
|
79
|
-
.api(
|
|
1
|
+
import { createRoute, group, HttpStatusCodes, jsonContent } from "@/framework/facade.js";
|
|
2
|
+
import { authMiddleware } from "@/middlewares/auth-middleware.js";
|
|
3
|
+
import { requireRole } from "@/middlewares/role-middleware.js";
|
|
4
|
+
import { destroy, index, show, store, update } from "@/modules/{{module}}/controllers/{{controller}}.js";
|
|
5
|
+
import {
|
|
6
|
+
Create{{ClassName}}Schema,
|
|
7
|
+
{{ClassName}}IdParamsSchema,
|
|
8
|
+
{{ClassName}}ListResponseSchema,
|
|
9
|
+
{{ClassName}}MessageSchema,
|
|
10
|
+
{{ClassName}}ResponseSchema,
|
|
11
|
+
Update{{ClassName}}Schema
|
|
12
|
+
} from "@/modules/{{module}}/schemas/{{controller}}.js";
|
|
13
|
+
|
|
14
|
+
const indexRoute = createRoute({
|
|
15
|
+
path: "/",
|
|
16
|
+
method: "get",
|
|
17
|
+
tags: ["{{ModuleClass}}"],
|
|
18
|
+
responses: {
|
|
19
|
+
[HttpStatusCodes.OK]: jsonContent({{ClassName}}ListResponseSchema, "{{module}} list")
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const showRoute = createRoute({
|
|
24
|
+
path: "/{id}",
|
|
25
|
+
method: "get",
|
|
26
|
+
tags: ["{{ModuleClass}}"],
|
|
27
|
+
request: {
|
|
28
|
+
params: {{ClassName}}IdParamsSchema
|
|
29
|
+
},
|
|
30
|
+
responses: {
|
|
31
|
+
[HttpStatusCodes.OK]: jsonContent({{ClassName}}ResponseSchema, "{{module}} item"),
|
|
32
|
+
[HttpStatusCodes.NOT_FOUND]: jsonContent({{ClassName}}MessageSchema, "Not found")
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const storeRoute = createRoute({
|
|
37
|
+
path: "/",
|
|
38
|
+
method: "post",
|
|
39
|
+
tags: ["{{ModuleClass}}"],
|
|
40
|
+
request: {
|
|
41
|
+
body: jsonContent(Create{{ClassName}}Schema, "Create {{module}} payload")
|
|
42
|
+
},
|
|
43
|
+
responses: {
|
|
44
|
+
[HttpStatusCodes.CREATED]: jsonContent({{ClassName}}MessageSchema, "Created")
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const updateRoute = createRoute({
|
|
49
|
+
path: "/{id}",
|
|
50
|
+
method: "put",
|
|
51
|
+
tags: ["{{ModuleClass}}"],
|
|
52
|
+
request: {
|
|
53
|
+
params: {{ClassName}}IdParamsSchema,
|
|
54
|
+
body: jsonContent(Update{{ClassName}}Schema, "Update {{module}} payload")
|
|
55
|
+
},
|
|
56
|
+
responses: {
|
|
57
|
+
[HttpStatusCodes.OK]: jsonContent({{ClassName}}MessageSchema, "Updated"),
|
|
58
|
+
[HttpStatusCodes.NOT_FOUND]: jsonContent({{ClassName}}MessageSchema, "Not found")
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const destroyRoute = createRoute({
|
|
63
|
+
path: "/{id}",
|
|
64
|
+
method: "delete",
|
|
65
|
+
tags: ["{{ModuleClass}}"],
|
|
66
|
+
request: {
|
|
67
|
+
params: {{ClassName}}IdParamsSchema
|
|
68
|
+
},
|
|
69
|
+
responses: {
|
|
70
|
+
[HttpStatusCodes.OK]: jsonContent({{ClassName}}MessageSchema, "Deleted"),
|
|
71
|
+
[HttpStatusCodes.NOT_FOUND]: jsonContent({{ClassName}}MessageSchema, "Not found")
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
export default group()
|
|
76
|
+
.api(indexRoute, index)
|
|
77
|
+
.api(showRoute, show)
|
|
78
|
+
.api(storeRoute, store)
|
|
79
|
+
.api(updateRoute, update)
|
|
80
|
+
.api(destroyRoute, destroy);
|
|
81
|
+
|
|
82
|
+
// Gate the whole group (authMiddleware resolves the session once for every route):
|
|
83
|
+
// export default group(authMiddleware).api(indexRoute, index) ...
|
|
84
|
+
//
|
|
85
|
+
// Or gate a single route by role. requireRole reads the role authMiddleware set,
|
|
86
|
+
// so authMiddleware must run first:
|
|
87
|
+
// group().api(destroyRoute, [authMiddleware, requireRole("admin")], destroy)
|
|
88
|
+
//
|
|
89
|
+
// Or group all authMiddleware and set single requireRole middleware
|
|
90
|
+
// so authMiddleware must run on all chain and requireRole single on per route:
|
|
91
|
+
// group(authMiddleware).api(destroyRoute, [requireRole("admin")], destroy)
|
|
92
|
+
//
|
|
93
|
+
// Delete the imports above when you do not need them.
|
|
80
94
|
|
|
@@ -1,11 +1,24 @@
|
|
|
1
|
-
import { group } from "@/framework/facade.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export default group()
|
|
6
|
-
.get("/", index)
|
|
7
|
-
.get("/:id", show)
|
|
8
|
-
.post("/", store)
|
|
9
|
-
.put("/:id", update)
|
|
10
|
-
.delete("/:id", destroy);
|
|
1
|
+
import { group } from "@/framework/facade.js";
|
|
2
|
+
import { authMiddleware } from "@/middlewares/auth-middleware.js";
|
|
3
|
+
import { requireRole } from "@/middlewares/role-middleware.js";
|
|
4
|
+
import { index, show, store, update, destroy } from "@/modules/{{module}}/controllers/{{controller}}.js";
|
|
11
5
|
|
|
6
|
+
export default group()
|
|
7
|
+
.get("/", index)
|
|
8
|
+
.get("/:id", show)
|
|
9
|
+
.post("/", store)
|
|
10
|
+
.put("/:id", update)
|
|
11
|
+
.delete("/:id", destroy);
|
|
12
|
+
|
|
13
|
+
// Gate the whole group (authMiddleware resolves the session once for every route):
|
|
14
|
+
// export default group(authMiddleware).api(indexRoute, index) ...
|
|
15
|
+
//
|
|
16
|
+
// Or gate a single route by role. requireRole reads the role authMiddleware set,
|
|
17
|
+
// so authMiddleware must run first:
|
|
18
|
+
// group().api(destroyRoute, [authMiddleware, requireRole("admin")], destroy)
|
|
19
|
+
//
|
|
20
|
+
// Or group all authMiddleware and set single requireRole middleware
|
|
21
|
+
// so authMiddleware must run on all chain and requireRole single on per route:
|
|
22
|
+
// group(authMiddleware).api(destroyRoute, [requireRole("admin")], destroy)
|
|
23
|
+
//
|
|
24
|
+
// Delete the imports above when you do not need them.
|