Service interface bu controller frontenddan olgan so‘rovlar ustida ishlash va unga mos javob qaytarish uchun foydalaniladi.
import ErrorResponse from '../shared/utils/errorResponse';
import OrdersDao from './dao/orders.dao';
import { IOrder } from './interface/orders.interface';
export default class OrdersService {
private dao = new OrdersDao();
async create(values: IOrder) {
return await this.dao.create(values);
}
async getAll(page: number, limit: number, search?: string) {
return await this.dao.getAll(page, limit, search);
}
async findOne(uid: number) {
const order = await this.dao.findOne(uid);
if (!order[0]) throw new ErrorResponse(404, 'Order not found');
return order[0];
}
async update(uid: number, status: string) {
const order = await this.dao.findOne(uid);
if (!order) throw new ErrorResponse(404, 'Order not found');
return await this.dao.update(uid, status);
}
async delete(id: string) {
return await this.dao.delete(id);
}
}
|