feat: appove and go
This commit is contained in:
@@ -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 } });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user