Skip to content

Commit 71ccf5f

Browse files
committed
fix: remove hours justification from api response
1 parent e5bede2 commit 71ccf5f

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

owl-api/src/projects/projects.service.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ export class ProjectsService {
1616
private posthog: PosthogService,
1717
) {}
1818

19+
private excludeHoursJustification<T extends { hoursJustification?: any }>(obj: T): Omit<T, 'hoursJustification'> {
20+
const { hoursJustification, ...rest } = obj;
21+
return rest;
22+
}
23+
24+
private excludeHoursJustificationFromArray<T extends { hoursJustification?: any }>(arr: T[]): Omit<T, 'hoursJustification'>[] {
25+
return arr.map(item => this.excludeHoursJustification(item));
26+
}
27+
1928
async createProject(createProjectDto: CreateProjectDto, userId: number) {
2029
const lockKey = `project-create-lock:${userId}`;
2130
const lockValue = randomBytes(16).toString('hex');
@@ -77,7 +86,7 @@ export class ProjectsService {
7786
});
7887
}
7988

80-
return project;
89+
return this.excludeHoursJustification(project);
8190
} finally {
8291
await this.redis.releaseLock(lockKey, lockValue);
8392
}
@@ -92,7 +101,7 @@ export class ProjectsService {
92101
orderBy: { createdAt: 'desc' },
93102
});
94103

95-
return projects;
104+
return this.excludeHoursJustificationFromArray(projects);
96105
}
97106

98107
async getProject(projectId: number, userId: number) {
@@ -118,7 +127,7 @@ export class ProjectsService {
118127
throw new ForbiddenException('Access denied');
119128
}
120129

121-
return project;
130+
return this.excludeHoursJustification(project);
122131
}
123132

124133
async createSubmission(createSubmissionDto: CreateSubmissionDto, userId: number) {
@@ -321,7 +330,7 @@ export class ProjectsService {
321330
if (Object.keys(requestedData).length === 0) {
322331
return {
323332
message: 'No changes provided.',
324-
project,
333+
project: this.excludeHoursJustification(project),
325334
};
326335
}
327336

@@ -332,7 +341,7 @@ export class ProjectsService {
332341

333342
return {
334343
message: 'Project updated successfully.',
335-
project: updatedProject,
344+
project: this.excludeHoursJustification(updatedProject),
336345
};
337346
}
338347

@@ -499,7 +508,7 @@ export class ProjectsService {
499508

500509
return {
501510
message: 'Hackatime projects updated successfully.',
502-
project: updatedProject,
511+
project: this.excludeHoursJustification(updatedProject),
503512
};
504513
}
505514

0 commit comments

Comments
 (0)