perf: 优化页面

This commit is contained in:
richarjiang
2026-04-05 13:25:54 +08:00
parent a85270efd4
commit 9811c9a13b
31 changed files with 3135 additions and 375 deletions

View File

@@ -1,5 +1,6 @@
import { CardTypeCategory } from '@mp-pilates/shared'
import {
IsBoolean,
IsEnum,
IsInt,
IsNumber,
@@ -41,6 +42,10 @@ export class UpdateCardTypeDto {
@IsString()
description?: string
@IsOptional()
@IsBoolean()
isActive?: boolean
@IsOptional()
@IsInt()
@Min(0)

View File

@@ -157,16 +157,29 @@ export class MembershipService {
return { ...updated }
}
async deleteCardType(id: string): Promise<CardType> {
async deleteCardType(id: string): Promise<{ deleted: boolean; deactivated: boolean }> {
const existing = await this.prisma.cardType.findUnique({ where: { id } })
if (!existing) {
throw new NotFoundException(`CardType ${id} not found`)
}
const updated = await this.prisma.cardType.update({
where: { id },
data: { isActive: false },
})
return { ...updated }
// Check if any memberships or orders reference this card type
const [membershipCount, orderCount] = await Promise.all([
this.prisma.membership.count({ where: { cardTypeId: id } }),
this.prisma.order.count({ where: { cardTypeId: id } }),
])
if (membershipCount > 0 || orderCount > 0) {
// Has dependencies — soft delete (deactivate) instead
await this.prisma.cardType.update({
where: { id },
data: { isActive: false },
})
return { deleted: false, deactivated: true }
}
// No dependencies — safe to hard delete
await this.prisma.cardType.delete({ where: { id } })
return { deleted: true, deactivated: false }
}
}

File diff suppressed because one or more lines are too long