Files
shomal-hospital-ticketing-b…/src/modules/permission/permission.controller.ts
2026-06-13 14:01:25 +03:30

76 lines
2.3 KiB
TypeScript

import { NextFunction, Request, Response } from "express";
import { Controller } from "../../core/controller/main.controller";
import PermissionService from "./permission.service";
import { ServerResponse } from "../../core/types";
class PermissionControllerClass extends Controller {
#service;
constructor() {
super();
this.#service = PermissionService;
}
// ایجاد دسترسی جدید
create = async (req:any, res: ServerResponse, next: NextFunction) => {
try {
const result = await this.#service.create(req.body);
return res.status(201).json({status:201,data:result});
} catch (error) {
next(error);
}
};
// دریافت لیست دسترسی‌ها (با فیلتر و صفحه‌بندی)
getAll = async (req:any, res: ServerResponse, next: NextFunction) => {
try {
const result = await this.#service.getAll(req.query);
return res.status(200).json({status:200,data:result});
} catch (error) {
next(error);
}
};
// دریافت یک دسترسی خاص
getById = async (req:any, res: ServerResponse, next: NextFunction) => {
try {
const { id } = req.params;
const result = await this.#service.getById(id);
return res.status(200).json({status:200,data:result});
} catch (error) {
next(error);
}
};
// ویرایش دسترسی
update = async (req:any, res: ServerResponse, next: NextFunction) => {
try {
const { id } = req.params;
const result = await this.#service.update(id, req.body);
return res.status(200).json({status:200,data:result});
} catch (error) {
next(error);
}
};
getList = async(req:any,res:ServerResponse,next:NextFunction) => {
try {
const result = await this.#service.getList();
return res.status(200).json({status:200,data:result});
} catch (error) {
next(error);
}
}
// حذف دسترسی
delete = async (req:any, res: ServerResponse, next: NextFunction) => {
try {
const { id } = req.params;
const result = await this.#service.delete(id);
return res.status(200).json({status:200,data:result});
} catch (error) {
next(error);
}
};
}
const PermissionController = new PermissionControllerClass();
export default PermissionController;