Skip to content

Commit

Permalink
Merge branch 'develop' into HRIS-379
Browse files Browse the repository at this point in the history
  • Loading branch information
sunasterisk-jejercito authored Aug 2, 2024
2 parents 0e893c5 + 6d8a896 commit bcae831
Show file tree
Hide file tree
Showing 39 changed files with 1,581 additions and 823 deletions.
4 changes: 3 additions & 1 deletion api/DTOs/ESLOffsetDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@ public class ESLOffsetDTO : ESLOffset
{
public new string TimeIn { get; set; } = default!;
public new string TimeOut { get; set; } = default!;
public string UserName { get; set; } = default!;

public ESLOffsetDTO(ESLOffset eslOffset)
{
if (eslOffset != null)
{
Id = eslOffset.Id;
UserId = eslOffset.UserId;
UserName = eslOffset.User?.Name ?? string.Empty;
TimeEntryId = eslOffset.TimeEntryId;
TeamLeaderId = eslOffset.TeamLeaderId;
TimeIn = eslOffset.TimeIn.ToString(@"hh\:mm");
TimeOut = eslOffset.TimeOut.ToString(@"hh\:mm");
Title = eslOffset.Title;
Description = eslOffset.Description;
IsLeaderApproved = eslOffset.IsLeaderApproved;
User = eslOffset.User;
User = eslOffset.User ?? new User();
TeamLeader = eslOffset.TeamLeader;
TimeEntry = eslOffset.TimeEntry;
IsUsed = eslOffset.IsUsed;
Expand Down
2 changes: 2 additions & 0 deletions api/DTOs/WorkInterruptionDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class WorkInterruptionDTO : WorkInterruption
{
public new string? TimeOut { get; set; }
public new string? TimeIn { get; set; }
public string? UserName { get; set; }
public WorkInterruptionDTO(WorkInterruption interruption)
{
Id = interruption.Id;
Expand All @@ -18,6 +19,7 @@ public WorkInterruptionDTO(WorkInterruption interruption)
WorkInterruptionType = interruption.WorkInterruptionType;
CreatedAt = interruption.CreatedAt;
UpdatedAt = interruption.UpdatedAt;
UserName = interruption.TimeEntry?.User?.Name;
}
}
}
6 changes: 4 additions & 2 deletions api/Schema/Queries/ESLOffsetQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ public ESLOffsetQuery(ESLOffsetService eslOffsetService)
{
_eslOffsetService = eslOffsetService;
}

public async Task<List<ESLOffsetDTO>> GetESLOffsetsByTimeEntry(int timeEntryId, bool onlyUnused = false)
{
return await _eslOffsetService.GetTimeEntryOffsets(timeEntryId, onlyUnused);
}

public async Task<List<ESLOffsetDTO>> GetAllESLOffsets(bool? isUsed = null)
{
return await _eslOffsetService.GetAllESLOffsets(isUsed);
}
public async Task<List<ESLOffsetDTO>> GetAllFiledOffsets()
{
return await _eslOffsetService.GetAllFiledOffsets();
}
}
}
12 changes: 12 additions & 0 deletions api/Schema/Queries/InterruptionQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,17 @@ public async Task<List<WorkInterruptionDTO>> GetInterruptionsByTimeEntryId(ShowI
{
return await _interruptionService.Show(interruption);
}
public async Task<List<WorkInterruptionDTO>> GetAllWorkInterruptions()
{
var interruptions = await _interruptionService.GetAllInterruptions();

// Ensure related data is included
foreach (var interruption in interruptions)
{
await _interruptionService.IncludeRelatedData(interruption);
}

return interruptions;
}
}
}
15 changes: 15 additions & 0 deletions api/Services/ESLOffsetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public async Task<List<ESLOffsetDTO>> GetTimeEntryOffsets(int timeEntryId, bool
{
var eslOffsets = await context.ESLOffsets
.Include(x => x.TeamLeader)
.Include(x => x.User)
.Where(x => x.TimeEntryId == timeEntryId && (onlyUnused ? x.IsUsed == false && x.IsLeaderApproved == true : true))
.OrderByDescending(x => x.CreatedAt)
.Select(x => new ESLOffsetDTO(x))
Expand All @@ -67,14 +68,28 @@ public async Task<List<ESLOffsetDTO>> GetAllESLOffsets(bool? isUsed)
{
var eslOffsets = await context.ESLOffsets
.Include(x => x.TeamLeader)
.Include(x => x.User)
.Where(x => isUsed != null ? x.IsUsed == isUsed : true)
.Select(x => new ESLOffsetDTO(x))
.ToListAsync();

return eslOffsets;
}
}
public async Task<List<ESLOffsetDTO>> GetAllFiledOffsets()
{
using (HrisContext context = _contextFactory.CreateDbContext())
{
var filedOffsets = await context.ESLOffsets
.Include(x => x.TeamLeader)
.Include(x => x.User)
.OrderByDescending(x => x.CreatedAt)
.Select(x => new ESLOffsetDTO(x))
.ToListAsync();

return filedOffsets;
}
}
public string GetRequestStatus(ESLOffset request)
{
if (request.IsLeaderApproved == true) return RequestStatus.APPROVED;
Expand Down
27 changes: 27 additions & 0 deletions api/Services/InterruptionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,32 @@ public async Task<WorkInterruptionDTO> Create(CreateInterruptionRequest interrup
return new WorkInterruptionDTO(work);
}
}
public async Task<List<WorkInterruptionDTO>> GetAllInterruptions()
{
using HrisContext context = _contextFactory.CreateDbContext();
#pragma warning disable CS8602 // Dereference of a possibly null reference.
var interruptions = await context.WorkInterruptions
.Include(wi => wi.WorkInterruptionType)
.Include(wi => wi.TimeEntry)
.ThenInclude(te => te.User)
.ToListAsync();

return interruptions.Select(wi => new WorkInterruptionDTO(wi)).ToList();
}
public async Task IncludeRelatedData(WorkInterruptionDTO interruption)
{
using (HrisContext context = _contextFactory.CreateDbContext())
{
var timeEntry = await context.TimeEntries
.Include(te => te.User)
.FirstOrDefaultAsync(te => te.Id == interruption.TimeEntryId);

if (timeEntry != null)
{
interruption.TimeEntry = timeEntry;
interruption.UserName = timeEntry.User?.Name;
}
}
}
}
}
5 changes: 4 additions & 1 deletion api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"AllowedHosts": "*",
"FileSystemStorageConfig": {
"Directory": "wwwroot/media",
"EnableLogging": true
"EnableLogging": true,
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=sample;Trusted_Connection=True;"
}
}
}
5 changes: 1 addition & 4 deletions api_v2/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,5 @@ module.exports = {
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
ignorePatterns: [
'src/prisma/classes/index.ts',
'src/graphql/graphql.ts'
]
ignorePatterns: ['src/prisma/classes/index.ts', 'src/graphql/graphql.ts'],
};
5 changes: 3 additions & 2 deletions api_v2/.prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"singleQuote": true,
"trailingComma": "all"
}
"trailingComma": "all",
"endOfLine": "lf"
}
21 changes: 10 additions & 11 deletions api_v2/config/bull.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { BullModuleOptions, BullOptionsFactory } from "@nestjs/bull";
import { BullModuleOptions, BullOptionsFactory } from '@nestjs/bull';

export class BullConfigService implements BullOptionsFactory {

createBullOptions(): BullModuleOptions {
return {
redis: {
host: process.env.QUEUE_HOST || 'localhost',
port: process.env.QUEUE_PORT ? parseInt(process.env.QUEUE_PORT) : 6379
}
}
}
}
createBullOptions(): BullModuleOptions {
return {
redis: {
host: process.env.QUEUE_HOST || 'localhost',
port: process.env.QUEUE_PORT ? parseInt(process.env.QUEUE_PORT) : 6379,
},
};
}
}
4 changes: 2 additions & 2 deletions api_v2/config/cache.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default () => ({
cacheTTL: process.env.CACHE_TTL || '3600',
})
cacheTTL: process.env.CACHE_TTL || '3600',
});
5 changes: 3 additions & 2 deletions api_v2/config/hris-api.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default () => ({
hrisApiGraphQLEndpoint: process.env.HRIS_API_GRAPHQL_ENDPOINT || 'http://localhost:5257/graphql',
})
hrisApiGraphQLEndpoint:
process.env.HRIS_API_GRAPHQL_ENDPOINT || 'http://localhost:5257/graphql',
});
8 changes: 4 additions & 4 deletions api_v2/config/jwt.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default () => ({
jwtSecret: process.env.JWT_SECRET_KEY,
jwtSigningExpiration: process.env.JWT_SIGNING_EXPIRATION || '7d',
jwtSigningAlgorithm: process.env.JWT_SIGNING_ALGORITHM || 'HS256',
})
jwtSecret: process.env.JWT_SECRET_KEY,
jwtSigningExpiration: process.env.JWT_SIGNING_EXPIRATION || '7d',
jwtSigningAlgorithm: process.env.JWT_SIGNING_ALGORITHM || 'HS256',
});
6 changes: 3 additions & 3 deletions api_v2/config/queue.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default () => ({
queueHost: process.env.QUEUE_HOST || 'localhost',
queuePort: process.env.QUEUE_PORT || 6379
})
queueHost: process.env.QUEUE_HOST || 'localhost',
queuePort: process.env.QUEUE_PORT || 6379,
});
4 changes: 2 additions & 2 deletions api_v2/config/slack.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default () => ({
slackOAuthToken: process.env.SLACK_O_AUTH_TOKEN
})
slackOAuthToken: process.env.SLACK_O_AUTH_TOKEN,
});
4 changes: 4 additions & 0 deletions api_v2/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { WorkInterruptionModule } from './work-interruption/work-interruption.mo
import { APP_GUARD } from '@nestjs/core';
import { PositionsGuard } from './guards/position.guard';
import { TimeRecordModule } from './time-record/time-record.module';
import { UserModule } from './user/user.module';
import { DtrManagementModule } from './dtr-management/dtr-management.module';

@Module({
imports: [
Expand Down Expand Up @@ -82,6 +84,8 @@ import { TimeRecordModule } from './time-record/time-record.module';
FileUploadModule,
WorkInterruptionModule,
TimeRecordModule,
UserModule,
DtrManagementModule,
],
controllers: [AppController],
providers: [
Expand Down
9 changes: 9 additions & 0 deletions api_v2/src/dtr-management/dtr-management.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { DtrManagementService } from './dtr-management.service';
import { DtrManagementResolver } from './dtr-management.resolver';
import { PrismaService } from '@/prisma/prisma.service';

@Module({
providers: [DtrManagementResolver, DtrManagementService, PrismaService],
})
export class DtrManagementModule {}
20 changes: 20 additions & 0 deletions api_v2/src/dtr-management/dtr-management.resolver.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { DtrManagementResolver } from './dtr-management.resolver';
import { DtrManagementService } from './dtr-management.service';
import { PrismaService } from '@/prisma/prisma.service';

describe('DtrManagementResolver', () => {
let resolver: DtrManagementResolver;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [DtrManagementResolver, DtrManagementService, PrismaService],
}).compile();

resolver = module.get<DtrManagementResolver>(DtrManagementResolver);
});

it('should be defined', () => {
expect(resolver).toBeDefined();
});
});
13 changes: 13 additions & 0 deletions api_v2/src/dtr-management/dtr-management.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Resolver, Query } from '@nestjs/graphql';
import { DtrManagementService } from './dtr-management.service';
import { TimeEntryDTO } from '@/graphql/graphql';

@Resolver(() => TimeEntryDTO)
export class DtrManagementResolver {
constructor(private readonly dtrManagementService: DtrManagementService) {}

@Query(() => [TimeEntryDTO])
async timeEntries() {
return this.dtrManagementService.timeEntries();
}
}
19 changes: 19 additions & 0 deletions api_v2/src/dtr-management/dtr-management.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Test, TestingModule } from '@nestjs/testing';
import { DtrManagementService } from './dtr-management.service';
import { PrismaService } from '@/prisma/prisma.service';

describe('DtrManagementService', () => {
let service: DtrManagementService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [DtrManagementService, PrismaService],
}).compile();

service = module.get<DtrManagementService>(DtrManagementService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
25 changes: 25 additions & 0 deletions api_v2/src/dtr-management/dtr-management.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { PrismaService } from '@/prisma/prisma.service';
import { Injectable } from '@nestjs/common';
import { TimeEntry } from '@prisma/client';

@Injectable()
export class DtrManagementService {
constructor(private readonly prisma: PrismaService) {}
async timeEntries(): Promise<TimeEntry[]> {
return this.prisma.timeEntry.findMany({
include: {
user: {
include: {
position: true,
},
},
timeIn: true,
timeOut: true,
overtime: true,
changeShiftRequest: true,
workInterruptions: true,
eslOffsets: true,
},
});
}
}
Loading

0 comments on commit bcae831

Please sign in to comment.