54 lines
925 B
TypeScript
54 lines
925 B
TypeScript
import bcrypt from "bcrypt";
|
|
import userModel from "./user.model";
|
|
|
|
export class UserService {
|
|
|
|
async getAll() {
|
|
|
|
return await userModel
|
|
.find()
|
|
.populate("roleId");
|
|
}
|
|
|
|
async getById(
|
|
id:string
|
|
) {
|
|
return await userModel
|
|
.find()
|
|
.populate("roleId");
|
|
}
|
|
|
|
async create(
|
|
data:any
|
|
) {
|
|
const passwordHash = await bcrypt.hash(
|
|
data.passwordHash,
|
|
10
|
|
);
|
|
|
|
data.passwordHash = passwordHash;
|
|
|
|
return await userModel.create(data);
|
|
}
|
|
|
|
async update(
|
|
id:string,
|
|
data:any
|
|
) {
|
|
return await userModel.findByIdAndUpdate(
|
|
id,
|
|
data,
|
|
{
|
|
new:true
|
|
}
|
|
);
|
|
}
|
|
|
|
async delete(
|
|
id:string
|
|
) {
|
|
return await userModel.findByIdAndDelete(
|
|
id
|
|
);
|
|
}
|
|
} |