Files
sistema_combustible/backend/src/modules/user/user.service.ts
2026-06-03 20:07:39 +00:00

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
);
}
}