File size: 1,155 Bytes
5a6eb7f
433085e
5a6eb7f
 
260547f
22f0230
a6fbb8d
5a6eb7f
a6fbb8d
02fcdf7
ac9dbd5
22f0230
 
ac9dbd5
 
5a6eb7f
 
433085e
ac9dbd5
5a6eb7f
 
 
22f0230
5a6eb7f
22f0230
5a6eb7f
 
 
 
 
 
 
 
a6fbb8d
22f0230
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
36
37
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-register.validation";
import { UsersService } from "../services/users.service";

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

@Prefix("/console/users")
export class AdminUsersController extends BaseController {
  private usersService: UsersService = new UsersService();

  setRoutes() {
    this.router.post(
      "/create",
      jwtHelper.verifyToken(allowedRoles),
      bodyValidator(userRegisterValidation),
      this.create
    );
  }

  create = async (req, res) => {
    try {
      let result = await this.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,
      });
    }
  };
}