import bcrypt from "bcryptjs"; import { IUser, Role, User } from "../models"; export const createUser = async (user: IUser) => { // 비밀번호 암호화 const hash = await bcrypt.hash(user.password, 10); // 사용자 역할 추가: 기본값은 "user" 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 findUserByEmail = async ( email: string, includePassword: boolean = false ) => { let user; if (includePassword) { user = await User.findOne({ email }).select("+password"); } else { user = await User.findOne({ email }); } return user; }; export const getProfile = async (userId: string) => { const profile = await User.findById(userId); return profile; //이름 수정 }; export const getUsers = async () => { const users = await User.find({}); return users; }; export const isUser = async (email: string) => { const user = await User.findOne({ email }); if (user) { return true; } else { return false; } }; export const isValidUserId = async (userId: string) => { const user = await User.findById(userId); if (user) { return true; } else { return false; } };