Files
hounam-submit-form-backend/src/modules/forms/physicalInfo/service/physicalInfoForm.service.ts
2026-05-26 16:00:09 +03:30

44 lines
1.2 KiB
TypeScript

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;