fix: code review — 7 issues resolved
(C1) Add dimensionScores/radarData/passed columns to AssessmentSession (C2) Mock DataSource in service.spec.ts + app.e2e-spec.ts (C3) Mock AuditLogService in controller.spec.ts (C4) Rewrite deleteSession tests for dataSource.transaction (I1) batchDeleteSessions uses transaction with certificate cleanup (I2) extractDimensionScores reads from session property (I3/I5) PDF generator supports multi-page + newline splitting (I4) findOne inside transaction uses deleteCondition
This commit is contained in:
@@ -1145,7 +1145,7 @@ const initialState: Partial<EvaluationState> = {
|
||||
deleteCondition.userId = userId;
|
||||
}
|
||||
|
||||
const session = await manager.findOne(AssessmentSession, { where: { id: sessionId } });
|
||||
const session = await manager.findOne(AssessmentSession, { where: deleteCondition });
|
||||
if (!session) {
|
||||
throw new NotFoundException('Session not found or you do not have permission to delete it');
|
||||
}
|
||||
@@ -1726,13 +1726,25 @@ const initialState: Partial<EvaluationState> = {
|
||||
|
||||
async batchDeleteSessions(ids: string[], user: any): Promise<number> {
|
||||
const isAdmin = user.role === 'super_admin' || user.role === 'admin';
|
||||
const queryBuilder = this.sessionRepository.createQueryBuilder().delete().whereInIds(ids);
|
||||
if (!isAdmin) {
|
||||
queryBuilder.andWhere('user_id = :userId', { userId: user.id });
|
||||
}
|
||||
const result = await queryBuilder.execute();
|
||||
this.logger.log(`[batchDeleteSessions] Deleted ${result.affected} sessions`);
|
||||
return result.affected || 0;
|
||||
|
||||
return this.dataSource.transaction(async (manager) => {
|
||||
const query: any = { id: In(ids) };
|
||||
if (!isAdmin) {
|
||||
query.userId = user.id;
|
||||
}
|
||||
|
||||
const sessions = await manager.find(AssessmentSession, { where: query });
|
||||
const sessionIds = sessions.map((s) => s.id);
|
||||
|
||||
if (sessionIds.length === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
await manager.delete(AssessmentCertificate, { sessionId: In(sessionIds) });
|
||||
const result = await manager.delete(AssessmentSession, { id: In(sessionIds) });
|
||||
this.logger.log(`[batchDeleteSessions] Deleted ${sessionIds.length} sessions`);
|
||||
return result.affected || 0;
|
||||
});
|
||||
}
|
||||
|
||||
async batchExportSessions(ids: string[], userId: string): Promise<any[]> {
|
||||
|
||||
Reference in New Issue
Block a user