first commit
This commit is contained in:
51
src/modules/forms/center/service/center.service.ts
Normal file
51
src/modules/forms/center/service/center.service.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import createHttpError from "http-errors";
|
||||
import { Controller } from "../../../../core/controller/main.controller";
|
||||
import { GlobalErrorMessages } from "../../../../core/messages/errors";
|
||||
import { Center } from "../../../../models/Center";
|
||||
import { JobCategory } from "../../../../models/JobCategory";
|
||||
|
||||
class CenterServiceClass extends Controller {
|
||||
// ایجاد مرکز جدید
|
||||
async create(data: any) {
|
||||
return await Center.create(data);
|
||||
}
|
||||
|
||||
// دریافت لیست تمام مراکز (همراه با رستههای شغلی مرتبط)
|
||||
async getAll() {
|
||||
return await Center.findAll({
|
||||
include: [{ model: JobCategory, as: "categories" }],
|
||||
order: [["createdAt", "DESC"]],
|
||||
});
|
||||
}
|
||||
|
||||
// دریافت یک مرکز خاص با ID
|
||||
async getById(id: string) {
|
||||
const center = await Center.findByPk(id, {
|
||||
include: [{ model: JobCategory, as: "categories" }],
|
||||
});
|
||||
if (!center) throw new Error("مرکز مورد نظر یافت نشد.");
|
||||
return center;
|
||||
}
|
||||
|
||||
// بروزرسانی اطلاعات مرکز
|
||||
async update(id: string, data: any) {
|
||||
const center = await this.getById(id);
|
||||
return await center.update(data);
|
||||
}
|
||||
|
||||
// حذف مرکز
|
||||
async delete(id: string) {
|
||||
const center = await this.getById(id);
|
||||
await center.destroy();
|
||||
return { message: "مرکز با موفقیت حذف شد." };
|
||||
}
|
||||
|
||||
// متد کمکی برای گرفتن مراکز فوری (Urgent)
|
||||
async getUrgentCenters() {
|
||||
return await Center.findAll({ where: { isUrgent: true } });
|
||||
}
|
||||
}
|
||||
|
||||
const CenterService = new CenterServiceClass();
|
||||
|
||||
export default CenterService;
|
||||
Reference in New Issue
Block a user