拦截伪区县写入与下单;推单失败挂 fulfillmentHold,HQ 可见超区/推单失败。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { validateShippingAddress } from '@dukang/domain';
|
||||
import { PrismaService } from '../../common/prisma/prisma.module';
|
||||
import { serializeBigInt } from '../../common/decorators/current-user.decorator';
|
||||
|
||||
@@ -27,7 +28,25 @@ export class UserAddressService {
|
||||
});
|
||||
}
|
||||
|
||||
private assertShippingFields(body: Record<string, unknown>, existing?: {
|
||||
province: string;
|
||||
city: string;
|
||||
district: string;
|
||||
detail: string;
|
||||
}) {
|
||||
const check = validateShippingAddress({
|
||||
province: body.province != null ? String(body.province) : existing?.province,
|
||||
city: body.city != null ? String(body.city) : existing?.city,
|
||||
district: body.district != null ? String(body.district) : existing?.district,
|
||||
detail: body.detail != null ? String(body.detail) : existing?.detail,
|
||||
});
|
||||
if (!check.ok) {
|
||||
throw new BadRequestException(check.message || '收货地址不完整');
|
||||
}
|
||||
}
|
||||
|
||||
async create(userId: bigint, body: Record<string, unknown>) {
|
||||
this.assertShippingFields(body);
|
||||
const isDefault = body.isDefault ? 1 : 0;
|
||||
const address = await this.prisma.$transaction(async (tx) => {
|
||||
if (isDefault) {
|
||||
@@ -52,6 +71,7 @@ export class UserAddressService {
|
||||
async update(userId: bigint, id: bigint, body: Record<string, unknown>) {
|
||||
const existing = await this.prisma.userAddress.findFirst({ where: { id, userId } });
|
||||
if (!existing) throw new NotFoundException('地址不存在');
|
||||
this.assertShippingFields(body, existing);
|
||||
const address = await this.prisma.$transaction(async (tx) => {
|
||||
if (body.isDefault) {
|
||||
await tx.userAddress.updateMany({ where: { userId }, data: { isDefault: 0 } });
|
||||
|
||||
Reference in New Issue
Block a user