Scope customer order lists with selfOnly and expose product FA names.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
41d3f8f4eb
commit
cffc828328
@@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
ArrayMinSize,
|
ArrayMinSize,
|
||||||
|
IsBoolean,
|
||||||
IsDateString,
|
IsDateString,
|
||||||
IsEnum,
|
IsEnum,
|
||||||
IsIn,
|
IsIn,
|
||||||
@@ -12,7 +13,7 @@ import {
|
|||||||
ValidateIf,
|
ValidateIf,
|
||||||
ValidateNested,
|
ValidateNested,
|
||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
import { Type } from 'class-transformer';
|
import { Transform, Type } from 'class-transformer';
|
||||||
import { OrderStatus, TransactionType } from '@prisma/client';
|
import { OrderStatus, TransactionType } from '@prisma/client';
|
||||||
import { ShippingAddressDto } from '../../cart/dto/cart.dto';
|
import { ShippingAddressDto } from '../../cart/dto/cart.dto';
|
||||||
|
|
||||||
@@ -172,4 +173,13 @@ export class ListOrdersDto {
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsIn(['paid', 'unpaid', 'failed'])
|
@IsIn(['paid', 'unpaid', 'failed'])
|
||||||
paymentStatus?: 'paid' | 'unpaid' | 'failed';
|
paymentStatus?: 'paid' | 'unpaid' | 'failed';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When true, only return the authenticated user's own orders
|
||||||
|
* (even if they also have orders.read staff permission).
|
||||||
|
*/
|
||||||
|
@IsOptional()
|
||||||
|
@Transform(({ value }) => value === true || value === 'true' || value === '1')
|
||||||
|
@IsBoolean()
|
||||||
|
selfOnly?: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,9 +113,9 @@ export class OrdersService {
|
|||||||
|
|
||||||
const where: Prisma.OrderWhereInput = {
|
const where: Prisma.OrderWhereInput = {
|
||||||
businessId,
|
businessId,
|
||||||
...(scope === 'customer' ? { userId: actor.id } : {}),
|
...(scope === 'customer' || query.selfOnly ? { userId: actor.id } : {}),
|
||||||
...(query.status ? { status: query.status } : {}),
|
...(query.status ? { status: query.status } : {}),
|
||||||
...(scope === 'admin' && query.customerUserId
|
...(scope === 'admin' && !query.selfOnly && query.customerUserId
|
||||||
? { userId: BigInt(query.customerUserId) }
|
? { userId: BigInt(query.customerUserId) }
|
||||||
: {}),
|
: {}),
|
||||||
...(query.orderNumber
|
...(query.orderNumber
|
||||||
@@ -150,7 +150,7 @@ export class OrdersService {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
: {}),
|
: {}),
|
||||||
...(scope === 'admin' && query.customerQuery?.trim()
|
...(scope === 'admin' && !query.selfOnly && query.customerQuery?.trim()
|
||||||
? {
|
? {
|
||||||
customer: this.buildCustomerSearchFilter(query.customerQuery.trim()),
|
customer: this.buildCustomerSearchFilter(query.customerQuery.trim()),
|
||||||
}
|
}
|
||||||
@@ -931,11 +931,17 @@ export class OrdersService {
|
|||||||
cellNumber: order.customer.cellNumber,
|
cellNumber: order.customer.cellNumber,
|
||||||
email: order.customer.email,
|
email: order.customer.email,
|
||||||
},
|
},
|
||||||
items: order.items.map((item) => ({
|
items: order.items.map((item) => {
|
||||||
|
const content = isRecord(item.product.content) ? item.product.content : null
|
||||||
|
const productNameFa =
|
||||||
|
content && typeof content.nameFa === 'string' ? content.nameFa.trim() : ''
|
||||||
|
return {
|
||||||
id: item.id.toString(),
|
id: item.id.toString(),
|
||||||
storeItemVariantId: item.storeItemVariantId?.toString() ?? null,
|
storeItemVariantId: item.storeItemVariantId?.toString() ?? null,
|
||||||
productId: item.productId.toString(),
|
productId: item.productId.toString(),
|
||||||
productTitle: item.productTitle,
|
productTitle: item.productTitle,
|
||||||
|
productNameFa: productNameFa || null,
|
||||||
|
productSlug: item.product.slug ?? null,
|
||||||
productImage: this.resolveProductImage(item.product, galleryByProductId),
|
productImage: this.resolveProductImage(item.product, galleryByProductId),
|
||||||
variantSku: item.variantSku,
|
variantSku: item.variantSku,
|
||||||
unitPrice: Number(item.unitPrice),
|
unitPrice: Number(item.unitPrice),
|
||||||
@@ -944,7 +950,8 @@ export class OrdersService {
|
|||||||
quantity: item.quantity,
|
quantity: item.quantity,
|
||||||
lineTotal: Number(item.lineTotal),
|
lineTotal: Number(item.lineTotal),
|
||||||
selections: item.selectionsSnapshot,
|
selections: item.selectionsSnapshot,
|
||||||
})),
|
}
|
||||||
|
}),
|
||||||
transactions: (order.transactions ?? []).map((transaction) =>
|
transactions: (order.transactions ?? []).map((transaction) =>
|
||||||
this.serializeTransaction(transaction),
|
this.serializeTransaction(transaction),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user