-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
129 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { OvertimeService } from './overtime.service'; | ||
import { OvertimeResolver } from './overtime.resolver'; | ||
import { PrismaService } from '@/prisma/prisma.service'; | ||
|
||
@Module({ | ||
providers: [OvertimeResolver, OvertimeService, PrismaService], | ||
}) | ||
export class OvertimeModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { OvertimeResolver } from './overtime.resolver'; | ||
import { OvertimeService } from './overtime.service'; | ||
import { PrismaService } from '@/prisma/prisma.service'; | ||
|
||
describe('OvertimeResolver', () => { | ||
let resolver: OvertimeResolver; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [OvertimeResolver, OvertimeService, PrismaService], | ||
}).compile(); | ||
|
||
resolver = module.get<OvertimeResolver>(OvertimeResolver); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(resolver).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Args, Query, Resolver } from '@nestjs/graphql'; | ||
import { OvertimeService } from './overtime.service'; | ||
import { OvertimeDTO } from '@/graphql/graphql'; | ||
|
||
@Resolver('Overtime') | ||
export class OvertimeResolver { | ||
constructor(private readonly overtimeService: OvertimeService) {} | ||
// Query to get all overtime entries | ||
@Query(() => [OvertimeDTO]) | ||
async allOvertime() { | ||
return await this.overtimeService.getAllOvertime(); | ||
} | ||
|
||
// Query to get overtime by user ID | ||
@Query() | ||
async overtime(@Args('userId') userId: number) { | ||
return await this.overtimeService.getOvertimeByUser(userId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { OvertimeService } from './overtime.service'; | ||
import { PrismaService } from '@/prisma/prisma.service'; | ||
|
||
describe('OvertimeService', () => { | ||
let service: OvertimeService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [OvertimeService, PrismaService], | ||
}).compile(); | ||
|
||
service = module.get<OvertimeService>(OvertimeService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { PrismaService } from '@/prisma/prisma.service'; | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class OvertimeService { | ||
constructor(private readonly prisma: PrismaService) {} | ||
|
||
// Fetch all overtime entries | ||
async getAllOvertime() { | ||
const overtimes = await this.prisma.overtime.findMany({ | ||
include: { | ||
multiProjects: { | ||
include: { | ||
project: true, | ||
}, | ||
}, | ||
manager: true, | ||
user: { | ||
include: { | ||
role: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
// Manually map the overtimes and add roleName | ||
return overtimes.map((overtime) => ({ | ||
...overtime, | ||
user: { | ||
...overtime.user, | ||
roleName: overtime.user.role ? overtime.user.role.name : null, | ||
}, | ||
})); | ||
} | ||
|
||
// Fetch overtime entries by user ID | ||
async getOvertimeByUser(userId: number) { | ||
return this.prisma.overtime.findMany({ | ||
where: { userId }, | ||
include: { | ||
multiProjects: { | ||
include: { | ||
project: true, | ||
}, | ||
}, | ||
user: true, | ||
manager: true, | ||
}, | ||
}); | ||
} | ||
} |