perf: 优化页面
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
Reference in New Issue
Block a user