Skip to content

Commit

Permalink
Resolve Conflict v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Fontilllas committed Sep 3, 2024
2 parents d88cedd + 5f0a094 commit 8d76c38
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 9 deletions.
2 changes: 2 additions & 0 deletions api_v2/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { UserModule } from './user/user.module';
import { DtrManagementModule } from './dtr-management/dtr-management.module';
import { TimeOutModule } from './time-out/time-out.module';
import { TimeInModule } from './time-in/time-in.module';
import { OvertimeModule } from './overtime/overtime.module';

@Module({
imports: [
Expand Down Expand Up @@ -92,6 +93,7 @@ import { TimeInModule } from './time-in/time-in.module';
DtrManagementModule,
TimeOutModule,
TimeInModule,
OvertimeModule,
],
controllers: [AppController],
providers: [
Expand Down
10 changes: 5 additions & 5 deletions api_v2/src/graphql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,11 +806,11 @@ export class Overtime {
export class OvertimeDTO {
user?: Nullable<Over>;
id: number;
projects: MultiProject[];
projects?: Nullable<MultiProject[]>;
otherProject?: Nullable<string>;
supervisor: string;
supervisor?: Nullable<string>;
dateFiled?: Nullable<DateTime>;
remarks: string;
remarks?: Nullable<string>;
overtimeDate?: Nullable<DateTime>;
approvedMinutes?: Nullable<number>;
isLeaderApproved?: Nullable<boolean>;
Expand All @@ -820,7 +820,7 @@ export class OvertimeDTO {
managerId?: Nullable<number>;
timeEntryId: number;
requestedMinutes: number;
multiProjects: MultiProject[];
multiProjects?: Nullable<MultiProject[]>;
manager: User;
timeEntry: TimeEntry;
createdAt?: Nullable<DateTime>;
Expand Down Expand Up @@ -1196,4 +1196,4 @@ export class ISchema {
SubscriptionObjectType: SubscriptionObjectType;
}

type Nullable<T> = T | null;
type Nullable<T> = T | null;
8 changes: 4 additions & 4 deletions api_v2/src/graphql/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,11 @@ type Overtime {
type OvertimeDTO {
user: Over
id: Int!
projects: [MultiProject!]!
projects: [MultiProject!]
otherProject: String
supervisor: String!
supervisor: String
dateFiled: DateTime
remarks: String!
remarks: String
overtimeDate: DateTime
approvedMinutes: Int
isLeaderApproved: Boolean
Expand All @@ -506,7 +506,7 @@ type OvertimeDTO {
managerId: Int
timeEntryId: Int!
requestedMinutes: Int!
multiProjects: [MultiProject!]!
multiProjects: [MultiProject!]
manager: User!
timeEntry: TimeEntry!
createdAt: DateTime
Expand Down
9 changes: 9 additions & 0 deletions api_v2/src/overtime/overtime.module.ts
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 {}
20 changes: 20 additions & 0 deletions api_v2/src/overtime/overtime.resolver.spec.ts
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();
});
});
19 changes: 19 additions & 0 deletions api_v2/src/overtime/overtime.resolver.ts
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);
}
}
19 changes: 19 additions & 0 deletions api_v2/src/overtime/overtime.service.spec.ts
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();
});
});
51 changes: 51 additions & 0 deletions api_v2/src/overtime/overtime.service.ts
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,
},
});
}
}

0 comments on commit 8d76c38

Please sign in to comment.