feat(admin): overhaul orders management page with interactive modal, postal tracking code editor, inline status selector and invoice print
This commit is contained in:
1 parent
d1802581eb
commit
24c361c4ff
5 files changed
+573
-64
No files matched your search
@@ -114,9 +114,13 @@ export class AdminController {
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Put('orders/:id/status')
|
||||
@ApiOperation({ summary: 'تغییر وضعیت سفارش' })
|
||||
async updateOrderStatus(@Param('id') id: string, @Body('status') status: string) {
|
||||
const order = await this.adminService.updateOrderStatus(id, status);
|
||||
@ApiOperation({ summary: 'تغییر وضعیت و کد رهگیری سفارش' })
|
||||
async updateOrderStatus(
|
||||
@Param('id') id: string,
|
||||
@Body('status') status: string,
|
||||
@Body('trackingNumber') trackingNumber?: string
|
||||
) {
|
||||
const order = await this.adminService.updateOrderStatus(id, status, trackingNumber);
|
||||
return {
|
||||
success: true,
|
||||
data: order
|
||||
|
||||
@@ -206,7 +206,13 @@ export class AdminService {
|
||||
|
||||
const where: any = {};
|
||||
if (query.search) {
|
||||
where.id = { contains: query.search };
|
||||
where.OR = [
|
||||
{ id: { contains: query.search } },
|
||||
{ trackingNumber: { contains: query.search, mode: 'insensitive' } },
|
||||
{ user: { firstName: { contains: query.search, mode: 'insensitive' } } },
|
||||
{ user: { lastName: { contains: query.search, mode: 'insensitive' } } },
|
||||
{ user: { phone: { contains: query.search } } }
|
||||
];
|
||||
}
|
||||
if (query.status) {
|
||||
where.status = query.status;
|
||||
@@ -214,8 +220,19 @@ export class AdminService {
|
||||
|
||||
const [data, total] = await Promise.all([
|
||||
this.prisma.order.findMany({
|
||||
where, skip, take: limit, orderBy: { createdAt: 'desc' },
|
||||
include: { user: true, orderItems: true }
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
include: {
|
||||
user: true,
|
||||
orderItems: {
|
||||
include: {
|
||||
product: true
|
||||
}
|
||||
},
|
||||
coupon: true
|
||||
}
|
||||
}),
|
||||
this.prisma.order.count({ where })
|
||||
]);
|
||||
@@ -223,10 +240,22 @@ export class AdminService {
|
||||
return { data, meta: { total, page, limit, lastPage: Math.ceil(total / limit) } };
|
||||
}
|
||||
|
||||
async updateOrderStatus(id: string, status: string) {
|
||||
async updateOrderStatus(id: string, status: string, trackingNumber?: string) {
|
||||
const dataToUpdate: any = { status };
|
||||
if (trackingNumber !== undefined) {
|
||||
dataToUpdate.trackingNumber = trackingNumber;
|
||||
}
|
||||
return this.prisma.order.update({
|
||||
where: { id },
|
||||
data: { status }
|
||||
data: dataToUpdate,
|
||||
include: {
|
||||
user: true,
|
||||
orderItems: {
|
||||
include: {
|
||||
product: true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user