Files
shomal-hospital-ticketing-b…/src/modules/user/controller/user.controller.ts
2026-06-09 15:34:54 +03:30

99 lines
2.3 KiB
TypeScript

import { NextFunction } from "express";
import { ServerResponse } from "../../../core/types";
import { Controller } from "../../../core/controller/main.controller";
import UserService from "../services/user.service";
class UserControllerClass extends Controller {
#service;
constructor() {
super();
this.#service = UserService;
}
async create(req: any, res: ServerResponse, next: NextFunction) {
try {
await this.#service.create(req.body || {});
res.status(201).json({
status: 201,
data: {},
message: "ساخته شد",
});
} catch (error) {
next(error);
}
}
async getAll(req: any, res: ServerResponse, next: NextFunction) {
try {
const data = await this.#service.getAll(req);
return res.status(200).json({
status: 200,
data,
message: "Ok",
});
} catch (error) {
console.log(error);
next(error);
}
}
async getList(req: any, res: ServerResponse, next: NextFunction) {
try {
const data = await this.#service.getList();
return res.status(200).json({
status: 200,
data,
message: "Ok",
});
} catch (error) {
console.log(error);
next(error);
}
}
async update(req: any, res: ServerResponse, next: NextFunction) {
try {
const id = req?.params?.id;
await this.#service.update(id, req.body);
return res.status(200).json({
status: 200,
data: {},
message: "ويرايش شد",
});
} catch (error) {
next(error);
}
}
async delete(req: any, res: ServerResponse, next: NextFunction) {
try {
const id = req?.params?.id;
await this.#service.delete(id);
return res.status(200).json({
status: 200,
data: {},
message: "حذف شد",
});
} catch (error) {
next(error);
}
}
async getById(req: any, res: ServerResponse, next: NextFunction) {
try {
const id = req?.params?.id;
const data = await this.#service.getById(id);
res.status(201).json({
status: 201,
data,
message: "ساخته شد",
});
} catch (error) {
next(error);
}
}
}
const UserController = new UserControllerClass();
export default UserController;