role.db.ts 565 Bytes
Newer Older
Yoon, Daeki's avatar
Yoon, Daeki committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { Role, User } from "../models";

export const findRoleById = async (roleId: string) => {
  const role = await Role.findById(roleId);
  return role;
};

export const findRoleByName = async (roleName: string) => {
  const role = await Role.findOne({ name: roleName });
  return role;
};

export const findRoleByUserId = async (userId: string) => {
  const user = await User.findById(userId).populate("role");
  const role = user?.get("role");
  return role;
};

export const getAllRoles = async () => {
  const roles = await Role.find({});
  return roles;
};