fix: 归档删除改为软删除
This commit is contained in:
@@ -36,12 +36,18 @@ export class DepositsService {
|
||||
.orderBy('d.createdAt', 'DESC');
|
||||
if (query?.studentId) qb.andWhere('d.studentId = :studentId', { studentId: query.studentId });
|
||||
if (query?.status) qb.andWhere('d.status = :status', { status: query.status });
|
||||
return qb.getMany();
|
||||
else qb.andWhere('d.status != :archived', { archived: 'archived' });
|
||||
const deposits = await qb.getMany();
|
||||
for (const deposit of deposits) {
|
||||
deposit.installments = deposit.installments?.filter((item) => item.status !== 'archived') ?? [];
|
||||
}
|
||||
return deposits;
|
||||
}
|
||||
|
||||
async findOne(id: number) {
|
||||
const deposit = await this.repo.findOne({ where: { id }, relations: ['student', 'installments'] });
|
||||
if (!deposit) throw new NotFoundException('押金记录不存在');
|
||||
deposit.installments = deposit.installments?.filter((item) => item.status !== 'archived') ?? [];
|
||||
return deposit;
|
||||
}
|
||||
|
||||
@@ -110,8 +116,9 @@ export class DepositsService {
|
||||
async deleteInstallment(id: number) {
|
||||
const installment = await this.installmentRepo.findOne({ where: { id } });
|
||||
if (!installment) throw new NotFoundException('分期记录不存在');
|
||||
await this.installmentRepo.delete(id);
|
||||
return { message: '删除成功' };
|
||||
if (installment.status === 'archived') throw new BadRequestException('分期记录已归档');
|
||||
await this.installmentRepo.update(id, { status: 'archived' });
|
||||
return { message: '已归档' };
|
||||
}
|
||||
|
||||
async refund(id: number, dto: RefundDepositDto, userId?: number) {
|
||||
@@ -137,8 +144,9 @@ export class DepositsService {
|
||||
async remove(id: number) {
|
||||
const deposit = await this.repo.findOne({ where: { id } });
|
||||
if (!deposit) throw new NotFoundException('押金记录不存在');
|
||||
await this.repo.delete(id);
|
||||
return { message: '删除成功' };
|
||||
if (deposit.status === 'archived') throw new BadRequestException('押金记录已归档');
|
||||
await this.repo.update(id, { status: 'archived' });
|
||||
return { message: '已归档' };
|
||||
}
|
||||
|
||||
async getStats() {
|
||||
|
||||
Reference in New Issue
Block a user