first commit
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import createHttpError from "http-errors";
|
||||
import { Controller } from "../../../../core/controller/main.controller";
|
||||
import { PhysicalInfo } from "../../../../models/PhysicalInfo";
|
||||
|
||||
class PhysicalInfoServiceClass extends Controller {
|
||||
async create(data: any) {
|
||||
return await PhysicalInfo.create(data);
|
||||
}
|
||||
|
||||
async getById(id: string) {
|
||||
const info = await PhysicalInfo.findByPk(id);
|
||||
if (!info) throw new createHttpError.NotFound("اطلاعات جسمانی یافت نشد");
|
||||
return info;
|
||||
}
|
||||
|
||||
async update(id: string, data: any) {
|
||||
const [affectedRows] = await PhysicalInfo.update(data, {
|
||||
where: { id },
|
||||
});
|
||||
|
||||
if (affectedRows === 0) {
|
||||
throw new createHttpError.NotFound("اطلاعات جسمانی برای ویرایش یافت نشد");
|
||||
}
|
||||
|
||||
return await PhysicalInfo.findByPk(id);
|
||||
}
|
||||
|
||||
async delete(id: string) {
|
||||
const deleted = await PhysicalInfo.destroy({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
if (!deleted) {
|
||||
throw new createHttpError.NotFound("اطلاعات جسمانی برای حذف یافت نشد");
|
||||
}
|
||||
|
||||
return { message: "با موفقیت حذف شد" };
|
||||
}
|
||||
}
|
||||
|
||||
const PhysicalInfoService = new PhysicalInfoServiceClass();
|
||||
|
||||
export default PhysicalInfoService;
|
||||
Reference in New Issue
Block a user