Spaces:
Running
Running
Commit
·
36d3d2c
1
Parent(s):
f39e411
refactor: move decorators to lib
Browse files- src/lib/decorators/controller-middleware.decorator.ts +21 -0
- src/{modules/common → lib}/decorators/prefix.decorator.ts +1 -1
- src/modules/console/admins/controllers/admins.controller.ts +1 -1
- src/modules/console/users/controllers/users.controller.ts +1 -1
- src/modules/user/auth/controllers/auth.controller.ts +1 -1
src/lib/decorators/controller-middleware.decorator.ts
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { BaseController } from "../controllers/controller.base";
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Decorator that adds a prefix to a controller's path.
|
5 |
+
* @param prefix - The prefix to be added.
|
6 |
+
* @returns A decorator function.
|
7 |
+
*/
|
8 |
+
export const ControllerMiddleware = (middleware: any) => {
|
9 |
+
return (target: typeof BaseController) => {
|
10 |
+
const originalConstructor = target;
|
11 |
+
const newConstructor: any = function (...args: any[]) {
|
12 |
+
const instance: BaseController = new (originalConstructor as any)(
|
13 |
+
...args
|
14 |
+
);
|
15 |
+
instance.router.use(middleware);
|
16 |
+
return instance;
|
17 |
+
};
|
18 |
+
newConstructor.prototype = originalConstructor.prototype;
|
19 |
+
return newConstructor;
|
20 |
+
};
|
21 |
+
};
|
src/{modules/common → lib}/decorators/prefix.decorator.ts
RENAMED
@@ -1,4 +1,4 @@
|
|
1 |
-
import { BaseController } from "
|
2 |
|
3 |
export const Prefix = (prefix: string) => {
|
4 |
return (target: typeof BaseController) => {
|
|
|
1 |
+
import { BaseController } from "../controllers/controller.base";
|
2 |
|
3 |
export const Prefix = (prefix: string) => {
|
4 |
return (target: typeof BaseController) => {
|
src/modules/console/admins/controllers/admins.controller.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import { Request, Response, Router } from "express";
|
2 |
import { BaseController } from "../../../../lib/controllers/controller.base";
|
3 |
-
import { Prefix } from "../../../common/decorators/prefix.decorator";
|
4 |
import { AdminsService } from "../services/admins.service";
|
5 |
import { createAdminSchema } from "../validations/create-admin.validation";
|
6 |
import {
|
@@ -8,6 +7,7 @@ import {
|
|
8 |
paramsValidator,
|
9 |
} from "../../../../helpers/validation.helper";
|
10 |
import { asyncHandler } from "../../../../helpers/async-handler";
|
|
|
11 |
|
12 |
@Prefix("/console/admins")
|
13 |
export class AdminsController extends BaseController {
|
|
|
1 |
import { Request, Response, Router } from "express";
|
2 |
import { BaseController } from "../../../../lib/controllers/controller.base";
|
|
|
3 |
import { AdminsService } from "../services/admins.service";
|
4 |
import { createAdminSchema } from "../validations/create-admin.validation";
|
5 |
import {
|
|
|
7 |
paramsValidator,
|
8 |
} from "../../../../helpers/validation.helper";
|
9 |
import { asyncHandler } from "../../../../helpers/async-handler";
|
10 |
+
import { Prefix } from "../../../../lib/decorators/prefix.decorator";
|
11 |
|
12 |
@Prefix("/console/admins")
|
13 |
export class AdminsController extends BaseController {
|
src/modules/console/users/controllers/users.controller.ts
CHANGED
@@ -2,7 +2,7 @@ import { asyncHandler } from "../../../../helpers/async-handler";
|
|
2 |
import { jwtHelper } from "../../../../helpers/jwt.helper";
|
3 |
import { bodyValidator } from "../../../../helpers/validation.helper";
|
4 |
import { BaseController } from "../../../../lib/controllers/controller.base";
|
5 |
-
import { Prefix } from "
|
6 |
import { userRegisterValidation } from "../../../common/users/validation/user-register.validation";
|
7 |
import { UsersService } from "../services/users.service";
|
8 |
|
|
|
2 |
import { jwtHelper } from "../../../../helpers/jwt.helper";
|
3 |
import { bodyValidator } from "../../../../helpers/validation.helper";
|
4 |
import { BaseController } from "../../../../lib/controllers/controller.base";
|
5 |
+
import { Prefix } from "../../../../lib/decorators/prefix.decorator";
|
6 |
import { userRegisterValidation } from "../../../common/users/validation/user-register.validation";
|
7 |
import { UsersService } from "../services/users.service";
|
8 |
|
src/modules/user/auth/controllers/auth.controller.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
import { UsersService } from "../services/users.service";
|
2 |
import { jwtHelper } from "../../../../helpers/jwt.helper";
|
3 |
import { BaseController } from "../../../../lib/controllers/controller.base";
|
4 |
-
import { Prefix } from "../../../common/decorators/prefix.decorator";
|
5 |
import { bodyValidator } from "../../../../helpers/validation.helper";
|
6 |
import { userRegisterValidation } from "../../../common/users/validation/user-register.validation";
|
7 |
import { loginValidation } from "../validation/user.Validation";
|
8 |
import { asyncHandler } from "../../../../helpers/async-handler";
|
|
|
9 |
|
10 |
@Prefix("/user/auth")
|
11 |
export class AuthController extends BaseController {
|
|
|
1 |
import { UsersService } from "../services/users.service";
|
2 |
import { jwtHelper } from "../../../../helpers/jwt.helper";
|
3 |
import { BaseController } from "../../../../lib/controllers/controller.base";
|
|
|
4 |
import { bodyValidator } from "../../../../helpers/validation.helper";
|
5 |
import { userRegisterValidation } from "../../../common/users/validation/user-register.validation";
|
6 |
import { loginValidation } from "../validation/user.Validation";
|
7 |
import { asyncHandler } from "../../../../helpers/async-handler";
|
8 |
+
import { Prefix } from "../../../../lib/decorators/prefix.decorator";
|
9 |
|
10 |
@Prefix("/user/auth")
|
11 |
export class AuthController extends BaseController {
|