短信验证调试成功

This commit is contained in:
2026-07-06 13:18:56 +08:00
parent 5ba69eb935
commit 1c978b8adc
62 changed files with 2491 additions and 354 deletions
@@ -14,22 +14,37 @@ export class UserAddressService {
return serializeBigInt(list);
}
async normalizeDefaultAddress(userId: bigint) {
const defaults = await this.prisma.userAddress.findMany({
where: { userId, isDefault: 1 },
orderBy: { updatedAt: 'desc' },
});
if (defaults.length <= 1) return;
const keep = defaults[0];
await this.prisma.$transaction(async (tx) => {
await tx.userAddress.updateMany({ where: { userId }, data: { isDefault: 0 } });
await tx.userAddress.update({ where: { id: keep.id }, data: { isDefault: 1 } });
});
}
async create(userId: bigint, body: Record<string, unknown>) {
const isDefault = body.isDefault ? 1 : 0;
if (isDefault) {
await this.prisma.userAddress.updateMany({ where: { userId }, data: { isDefault: 0 } });
}
const address = await this.prisma.userAddress.create({
data: {
userId,
receiverName: String(body.receiverName),
phone: String(body.phone),
province: String(body.province),
city: String(body.city),
district: String(body.district),
detail: String(body.detail),
isDefault,
},
const address = await this.prisma.$transaction(async (tx) => {
if (isDefault) {
await tx.userAddress.updateMany({ where: { userId }, data: { isDefault: 0 } });
}
return tx.userAddress.create({
data: {
userId,
receiverName: String(body.receiverName),
phone: String(body.phone),
province: String(body.province),
city: String(body.city),
district: String(body.district),
detail: String(body.detail),
isDefault,
},
});
});
return serializeBigInt(address);
}
@@ -37,20 +52,22 @@ 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('地址不存在');
if (body.isDefault) {
await this.prisma.userAddress.updateMany({ where: { userId }, data: { isDefault: 0 } });
}
const address = await this.prisma.userAddress.update({
where: { id },
data: {
receiverName: body.receiverName ? String(body.receiverName) : undefined,
phone: body.phone ? String(body.phone) : undefined,
province: body.province ? String(body.province) : undefined,
city: body.city ? String(body.city) : undefined,
district: body.district ? String(body.district) : undefined,
detail: body.detail ? String(body.detail) : undefined,
isDefault: body.isDefault ? 1 : undefined,
},
const address = await this.prisma.$transaction(async (tx) => {
if (body.isDefault) {
await tx.userAddress.updateMany({ where: { userId }, data: { isDefault: 0 } });
}
return tx.userAddress.update({
where: { id },
data: {
receiverName: body.receiverName ? String(body.receiverName) : undefined,
phone: body.phone ? String(body.phone) : undefined,
province: body.province ? String(body.province) : undefined,
city: body.city ? String(body.city) : undefined,
district: body.district ? String(body.district) : undefined,
detail: body.detail ? String(body.detail) : undefined,
isDefault: body.isDefault ? 1 : undefined,
},
});
});
return serializeBigInt(address);
}