Skip to content

Commit cc4a02c

Browse files
committed
fix: add sum hours endpoints
1 parent 7e54645 commit cc4a02c

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

owl-api/src/user/user.controller.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,24 @@ export class UserController {
157157
return this.userService.getAllHackatimeProjects(userEmail);
158158
}
159159

160+
@Get('api/user/projects/now-hackatime-hours/total')
161+
@UseGuards(AuthGuard)
162+
@HttpCode(200)
163+
async getTotalNowHackatimeHours(@Req() req: express.Request) {
164+
const userId = req.user.userId;
165+
const total = await this.userService.getTotalNowHackatimeHours(userId);
166+
return { totalNowHackatimeHours: total };
167+
}
168+
169+
@Get('api/user/projects/approved-hours/total')
170+
@UseGuards(AuthGuard)
171+
@HttpCode(200)
172+
async getTotalApprovedHours(@Req() req: express.Request) {
173+
const userId = req.user.userId;
174+
const total = await this.userService.getTotalApprovedHours(userId);
175+
return { totalApprovedHours: total };
176+
}
177+
160178
@Get('api/user/hackatime-account')
161179
@UseGuards(AuthGuard)
162180
@Throttle({ default: { ttl: 3600000, limit: 1000000 } })

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,26 @@ export class UserService {
564564
return res.json();
565565
}
566566

567+
async getTotalNowHackatimeHours(userId: number): Promise<number> {
568+
const result = await this.prisma.project.aggregate({
569+
where: { userId },
570+
_sum: {
571+
nowHackatimeHours: true,
572+
},
573+
});
574+
return result._sum.nowHackatimeHours ?? 0;
575+
}
576+
577+
async getTotalApprovedHours(userId: number): Promise<number> {
578+
const result = await this.prisma.project.aggregate({
579+
where: { userId },
580+
_sum: {
581+
approvedHours: true,
582+
},
583+
});
584+
return result._sum.approvedHours ?? 0;
585+
}
586+
567587
async getLinkedHackatimeProjects(userEmail: string, projectId: number): Promise<any> {
568588
const allProjects = await this.getAllHackatimeProjects(userEmail);
569589

0 commit comments

Comments
 (0)