File size: 1,107 Bytes
5a6eb7f
433085e
5a6eb7f
 
433085e
2003362
a6fbb8d
5a6eb7f
a6fbb8d
5a6eb7f
 
 
 
 
 
433085e
5a6eb7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a6fbb8d
5a6eb7f
 
1
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
33
34
35
import { jwtHelper } from "../../../../helpers/jwt.helper";
import { bodyValidator } from "../../../../helpers/validation.helper";
import { BaseController } from "../../../../lib/controllers/controller.base";
import { Prefix } from "../../../common/decorators/prefix.decorator";
import { userRegisterValidation } from "../../../common/users/validation/user.baseValidation";
import { usersService } from "../services/users.service";

const allowedRoles = ["superAdmin", "admin"];

@Prefix("/admin/users")
export class adminUsersController extends BaseController {
  static setRoutes(router) {
    router.post(
      "/create",
      jwtHelper.verifyToken(allowedRoles),
      bodyValidator(userRegisterValidation),
      adminUsersController.create
    );
  }

  static async create(req, res) {
    try {
      let result = await usersService.create(req.body);
      return res.status(result.code).json(result);
    } catch (err) {
      console.log(`err.message`, err.message);
      return res.status(500).json({
        success: false,
        code: 500,
        error: err.message,
      });
    }
  }
}