Initial commit of the Mado Motor NestJS API.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { UpdateOrderStatusDto } from './dto/update-order-status.dto';
|
||||
|
||||
@Injectable()
|
||||
export class OrdersService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
list() {
|
||||
return this.prisma.order.findMany({
|
||||
orderBy: { createdAt: 'desc' },
|
||||
select: {
|
||||
id: true,
|
||||
customerName: true,
|
||||
customerPhone: true,
|
||||
itemCount: true,
|
||||
status: true,
|
||||
createdAt: true,
|
||||
items: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async findOne(id: number) {
|
||||
const order = await this.prisma.order.findUnique({
|
||||
where: { id },
|
||||
include: { items: true },
|
||||
});
|
||||
if (!order) {
|
||||
throw new NotFoundException('سفارش یافت نشد');
|
||||
}
|
||||
return order;
|
||||
}
|
||||
|
||||
async updateStatus(id: number, dto: UpdateOrderStatusDto) {
|
||||
await this.findOne(id);
|
||||
return this.prisma.order.update({
|
||||
where: { id },
|
||||
data: { status: dto.status },
|
||||
include: { items: true },
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user