feat: appove and go

This commit is contained in:
thanhnv
2026-07-19 09:37:16 +07:00
parent 13fae3e6c3
commit 709b6cccd6
24 changed files with 1245 additions and 70 deletions
@@ -70,9 +70,9 @@ export class KeyResultsService {
createdById: user.sub,
},
});
await this.recalculateObjectiveStatus(existing.objectiveId, tx);
return keyResult;
});
await this.recalculateObjectiveStatus(existing.objectiveId);
return updated;
}
@@ -88,14 +88,17 @@ export class KeyResultsService {
}
}
private async recalculateObjectiveStatus(objectiveId: number): Promise<void> {
const keyResults = await this.prisma.keyResult.findMany({ where: { objectiveId } });
private async recalculateObjectiveStatus(
objectiveId: number,
tx: Prisma.TransactionClient = this.prisma,
): Promise<void> {
const keyResults = await tx.keyResult.findMany({ where: { objectiveId } });
const average =
keyResults.length === 0
? 0
: Math.round(keyResults.reduce((total, keyResult) => total + keyResult.progress, 0) / keyResults.length);
const status =
average === 0 ? 'NOT_STARTED' : average >= 100 ? 'COMPLETED' : 'IN_PROGRESS';
await this.prisma.objective.update({ where: { id: objectiveId }, data: { status } });
await tx.objective.update({ where: { id: objectiveId }, data: { status } });
}
}