Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HRIS-356] - [FE] DTR management export function for admin #298

Merged
merged 14 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;"
}
}
}
3 changes: 2 additions & 1 deletion client/.prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"tabWidth": 2,
"printWidth": 100,
"singleQuote": true,
"trailingComma": "none"
"trailingComma": "none",
"endOfLine": "lf"
}
4 changes: 2 additions & 2 deletions client/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ ENV PORT 3000

WORKDIR /usr/src/app

COPY package.json /usr/src/app
COPY package-lock.json /usr/src/app
COPY package*.json /usr/src/app
COPY package*-lock.json /usr/src/app

RUN npm install

Expand Down
30 changes: 30 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"react": "18.2.0",
"react-apexcharts": "^1.4.0",
"react-confirm-alert": "^3.0.6",
"react-csv": "^2.2.2",
"react-dom": "18.2.0",
"react-feather": "^2.0.10",
"react-file-icon": "^1.3.0",
Expand All @@ -56,6 +57,7 @@
"@tailwindcss/line-clamp": "^0.4.2",
"@types/node": "18.11.3",
"@types/react": "18.0.21",
"@types/react-csv": "^1.1.10",
"@types/react-dom": "18.0.6",
"@types/react-file-icon": "^1.0.1",
"@typescript-eslint/eslint-plugin": "^5.47.1",
Expand Down
21 changes: 21 additions & 0 deletions client/src/graphql/queries/eslFiledOffsets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@ export const GET_ALL_ESL_FILED_OFFSETS = gql`
id
name
}
userName
description
isLeaderApproved
isUsed
}
}
`
export const GET_ALL_FILED_OFFSETS = gql`
{
allFiledOffsets {
id
title
timeIn
timeOut
createdAt
updatedAt
teamLeader {
id
name
}
userName
description
isLeaderApproved
isUsed
Expand Down
19 changes: 19 additions & 0 deletions client/src/graphql/queries/workInterruptionQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,22 @@ export const GET_ALL_WORK_INTERRUPTIONS_QUERY = gql`
}
}
`
export const GET_ALL_INTERRUPTIONS_QUERY = gql`
{
allWorkInterruptions {
userName
id
timeOut
timeIn
otherReason
remarks
workInterruptionType {
id
name
}
workInterruptionTypeId
timeEntryId
createdAt
}
}
`
17 changes: 15 additions & 2 deletions client/src/hooks/useFileOffset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import toast from 'react-hot-toast'
import { useQuery, useMutation, UseQueryResult, UseMutationResult } from '@tanstack/react-query'

import { client } from '~/utils/shared/client'
import { GET_ALL_ESL_FILED_OFFSETS } from '~/graphql/queries/eslFiledOffsets'
import { GET_ALL_ESL_FILED_OFFSETS, GET_ALL_FILED_OFFSETS } from '~/graphql/queries/eslFiledOffsets'
import { IFiledOffsetData, IFileOffset } from '~/utils/interfaces/fileOffsetInterface'
import { CREATE_FILE_OFFSET_MUTATION } from '~/graphql/mutations/fileOffsetMutation'

Expand All @@ -11,10 +11,15 @@ type FiledOffsetFuncReturnType = UseQueryResult<
{ eslOffsetsByTimeEntry: IFiledOffsetData[] },
unknown
>
type AllFiledOffsetsFuncReturnType = UseQueryResult<
{ allFiledOffsets: IFiledOffsetData[] },
unknown
>

type HookReturnType = {
handleAddFileOffsetMutation: () => FileOffsetFuncReturnType
getESLFiledOffsetsQuery: (timeEntryId: number) => FiledOffsetFuncReturnType
getAllFiledOffsetsQuery: () => AllFiledOffsetsFuncReturnType
}

const useFileOffset = (): HookReturnType => {
Expand All @@ -36,9 +41,17 @@ const useFileOffset = (): HookReturnType => {
select: (data: { eslOffsetsByTimeEntry: IFiledOffsetData[] }) => data
})

const getAllFiledOffsetsQuery = (): AllFiledOffsetsFuncReturnType =>
useQuery({
queryKey: ['GET_ALL_FILED_OFFSETS'],
queryFn: async () => await client.request(GET_ALL_FILED_OFFSETS),
select: (data: { allFiledOffsets: IFiledOffsetData[] }) => data
})

return {
handleAddFileOffsetMutation,
getESLFiledOffsetsQuery
getESLFiledOffsetsQuery,
getAllFiledOffsetsQuery
}
}

Expand Down
Loading
Loading