Skip to content

Commit bae1493

Browse files
committed
chore(order): cập nhật schema cho danh sách quản lý đơn hàng
- Thêm trường `orderCode` vào `GetManageOrderListResSchema` để lưu trữ mã đơn hàng. - Cải tiến cấu trúc schema để bao gồm thông tin metadata và loại bỏ các trường không cần thiết từ phản hồi.
1 parent e36c357 commit bae1493

2 files changed

Lines changed: 52 additions & 7 deletions

File tree

src/routes/order/order.model.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,30 @@ export const GetOrderListResSchema = z.object({
2525
})
2626
})
2727

28-
export const GetManageOrderListResSchema = GetOrderListResSchema
28+
// Schema cho manage order list (có thêm orderCode field)
29+
export const GetManageOrderListResSchema = z.object({
30+
message: z.string().optional(),
31+
data: z.array(
32+
OrderSchema.extend({
33+
items: z.array(ProductSKUSnapshotSchema),
34+
orderCode: z.string().nullable().optional() // Thêm orderCode field
35+
}).omit({
36+
receiver: true,
37+
deletedAt: true,
38+
deletedById: true,
39+
createdById: true,
40+
updatedById: true
41+
})
42+
),
43+
metadata: z.object({
44+
totalItems: z.number(),
45+
page: z.number(),
46+
limit: z.number(),
47+
totalPages: z.number(),
48+
hasNext: z.boolean(),
49+
hasPrev: z.boolean()
50+
})
51+
})
2952

3053
// Schema cho manage order list query
3154
export const GetManageOrderListQuerySchema = PaginationQuerySchema.extend({

src/shared/repositories/shared-shipping.repo.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ export class SharedShippingRepository {
220220
this.logger.log(`[SHARED_SHIPPING] Lấy shop address cho shop: ${shopId}`)
221221

222222
try {
223+
// 1. Kiểm tra shop có tồn tại không
223224
const shopData = await this.prismaService.user.findUnique({
224225
where: { id: shopId }
225226
})
@@ -231,20 +232,41 @@ export class SharedShippingRepository {
231232

232233
this.logger.log(`[SHARED_SHIPPING] Shop data: ${JSON.stringify(shopData, null, 2)}`)
233234

234-
// Lấy shop address từ UserAddress
235-
this.logger.log(`[SHARED_SHIPPING] Lấy shop address từ UserAddress`)
236-
const shopUserAddress = await this.prismaService.userAddress.findFirst({
235+
// 2. Lấy shop address từ UserAddress (default address trước, fallback về bất kỳ address nào)
236+
this.logger.log(`[SHARED_SHIPPING] Lấy shop default address từ UserAddress`)
237+
let shopUserAddress = await this.prismaService.userAddress.findFirst({
237238
where: { userId: shopId, isDefault: true },
238239
include: { address: true }
239240
})
240241

241-
if (!shopUserAddress || !shopUserAddress.address) {
242-
this.logger.error(`[SHARED_SHIPPING] Shop address không tồn tại cho shop: ${shopId}`)
243-
throw new Error('Shop address not found')
242+
// Nếu không có default address, lấy address đầu tiên
243+
if (!shopUserAddress) {
244+
this.logger.warn(`[SHARED_SHIPPING] Shop không có default address, thử lấy address đầu tiên cho shop: ${shopId}`)
245+
shopUserAddress = await this.prismaService.userAddress.findFirst({
246+
where: { userId: shopId },
247+
include: { address: true }
248+
})
244249
}
245250

251+
if (!shopUserAddress) {
252+
this.logger.error(`[SHARED_SHIPPING] Shop không có bất kỳ address nào cho shop: ${shopId}`)
253+
throw new Error('Shop has no addresses')
254+
}
255+
256+
if (!shopUserAddress.address) {
257+
this.logger.error(`[SHARED_SHIPPING] Shop address record không có address data cho shop: ${shopId}`)
258+
throw new Error('Shop address data not found')
259+
}
260+
261+
this.logger.log(`[SHARED_SHIPPING] Shop UserAddress: ${JSON.stringify(shopUserAddress, null, 2)}`)
246262
this.logger.log(`[SHARED_SHIPPING] Shop address: ${JSON.stringify(shopUserAddress.address, null, 2)}`)
247263

264+
// 3. Kiểm tra address có đầy đủ thông tin không
265+
if (!shopUserAddress.address.province || !shopUserAddress.address.district || !shopUserAddress.address.ward) {
266+
this.logger.error(`[SHARED_SHIPPING] Shop address thiếu thông tin địa chỉ cho shop: ${shopId}`)
267+
throw new Error('Shop address missing required location information')
268+
}
269+
248270
const result = {
249271
shop: shopData,
250272
address: shopUserAddress.address

0 commit comments

Comments
 (0)