Commit 5c9540ec authored by Yoon, Daeki's avatar Yoon, Daeki 😅
Browse files

유저 만들 때 역할 항목 추가

parent 83e41a01
import bcrypt from "bcryptjs"; import bcrypt from "bcryptjs";
import { IUser, User } from "../models"; import { IUser, Role, User } from "../models";
export const createUser = async (user: IUser) => { export const createUser = async (user: IUser) => {
// 비밀번호 암호화 // 비밀번호 암호화
const hash = await bcrypt.hash(user.password, 10); const hash = await bcrypt.hash(user.password, 10);
const newUser = await User.create({ email: user.email, password: hash }); // 사용자 역할 추가: 기본값은 "user"
return newUser; let userRole = null;
if (user.role) {
userRole = await Role.findById(user.role);
} else {
userRole = await Role.findOne({ name: "user" });
}
const newUser = new User({
email: user.email,
password: hash,
role: userRole,
isNew: true,
});
const retUser = await newUser.save();
return retUser;
}; };
export const deleteUserById = async (userId: string) => { export const deleteUserById = async (userId: string) => {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment