fix: 归档删除改为软删除
This commit is contained in:
@@ -157,10 +157,10 @@ export class DepositsController {
|
||||
userId: req.user?.id,
|
||||
username: req.user?.username,
|
||||
module: '押金管理',
|
||||
action: '删除分期',
|
||||
action: '归档分期',
|
||||
targetId: installmentId,
|
||||
targetType: 'deposit-installment',
|
||||
detail: `删除分期${installmentId}`,
|
||||
detail: `归档分期${installmentId}`,
|
||||
ipAddress,
|
||||
userAgent,
|
||||
});
|
||||
@@ -207,7 +207,7 @@ export class DepositsController {
|
||||
userId: req.user?.id,
|
||||
username: req.user?.username,
|
||||
module: '押金管理',
|
||||
action: '删除押金记录',
|
||||
action: '归档押金记录',
|
||||
targetId: id,
|
||||
targetType: 'deposit',
|
||||
ipAddress,
|
||||
|
||||
@@ -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