feat(csv): ajusted csv logics and minor fixes to employees
This commit is contained in:
parent
a2fc68e9c0
commit
f9a247d9f1
|
|
@ -553,7 +553,7 @@
|
||||||
"required": true,
|
"required": true,
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "boolean"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -561,7 +561,7 @@
|
||||||
"required": true,
|
"required": true,
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "boolean"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -569,7 +569,7 @@
|
||||||
"required": true,
|
"required": true,
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "boolean"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -577,7 +577,7 @@
|
||||||
"required": true,
|
"required": true,
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "boolean"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -585,7 +585,7 @@
|
||||||
"required": true,
|
"required": true,
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "boolean"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -593,7 +593,7 @@
|
||||||
"required": true,
|
"required": true,
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "boolean"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -601,7 +601,7 @@
|
||||||
"required": true,
|
"required": true,
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "boolean"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
|
||||||
|
|
||||||
export type Modules =
|
export type Modules =
|
||||||
| 'timesheets'
|
| 'timesheets'
|
||||||
| 'timesheets_approval'
|
| 'timesheets_approval'
|
||||||
|
|
@ -14,29 +16,3 @@ export const module_list = [
|
||||||
'personal_profile',
|
'personal_profile',
|
||||||
'dashboard',
|
'dashboard',
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
const createDefaultModuleAccess = (): Record<Modules, boolean> =>
|
|
||||||
module_list.reduce((acc, mod) => {
|
|
||||||
acc[mod] = false;
|
|
||||||
return acc;
|
|
||||||
}, {} as Record<Modules, boolean>);
|
|
||||||
|
|
||||||
|
|
||||||
export const toBooleanFromString = (arr?: readonly string[] | null): Record<Modules, boolean> => {
|
|
||||||
const result = createDefaultModuleAccess();
|
|
||||||
if (!arr || !Array.isArray(arr)) return result;
|
|
||||||
for (const item of arr) {
|
|
||||||
if (typeof item !== 'string') continue;
|
|
||||||
const trimmed = item.trim();
|
|
||||||
if ((module_list as readonly string[]).includes(trimmed)) {
|
|
||||||
result[trimmed as Modules] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const toStringFromBoolean = (boolean_module_access: Record<Modules, boolean>): Modules[] => {
|
|
||||||
const access_array = Object.entries(boolean_module_access);
|
|
||||||
const allowed_accesses = access_array.filter(([_key, value]) => value === true);
|
|
||||||
return allowed_accesses.map(([key]) => key as Modules);
|
|
||||||
}
|
|
||||||
25
src/common/utils/boolean-utils.ts
Normal file
25
src/common/utils/boolean-utils.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
export const createDefaultBooleanValue = <T extends PropertyKey>(keys_list: PropertyKey[]): Record<T, boolean> =>
|
||||||
|
keys_list.reduce((acc, mod) => {
|
||||||
|
acc[mod] = false;
|
||||||
|
return acc;
|
||||||
|
}, {} as Record<T, boolean>);
|
||||||
|
|
||||||
|
|
||||||
|
export const toBooleanFromKeys = <T extends PropertyKey>(keys_list: PropertyKey[], arr?: readonly PropertyKey[] | null): Record<T, boolean> => {
|
||||||
|
const result = createDefaultBooleanValue(keys_list);
|
||||||
|
if (!arr || !Array.isArray(arr)) return result;
|
||||||
|
for (const item of arr) {
|
||||||
|
if (typeof item !== 'string') continue;
|
||||||
|
const trimmed = item.trim();
|
||||||
|
if ((keys_list as readonly PropertyKey[]).includes(trimmed)) {
|
||||||
|
result[trimmed as T] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const toKeysFromBoolean = <T extends PropertyKey>(boolean_values: Record<T, boolean>): T[] => {
|
||||||
|
const values_array = Object.entries(boolean_values);
|
||||||
|
const values = values_array.filter(([_key, value]) => value === true);
|
||||||
|
return values.map(([key]) => key as T);
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from "@nestjs/common";
|
||||||
import { Users } from "@prisma/client";
|
import { Users } from "@prisma/client";
|
||||||
import { Result } from "src/common/errors/result-error.factory";
|
import { Result } from "src/common/errors/result-error.factory";
|
||||||
import { toBooleanFromString } from "src/common/mappers/module-access.mapper";
|
import { Modules } from "src/common/mappers/module-access.mapper";
|
||||||
|
import { toBooleanFromKeys } from "src/common/utils/boolean-utils";
|
||||||
import { toDateFromString } from "src/common/utils/date-utils";
|
import { toDateFromString } from "src/common/utils/date-utils";
|
||||||
import { EmployeeDetailedDto } from "src/identity-and-account/employees/employee-detailed.dto";
|
import { EmployeeDetailedDto } from "src/identity-and-account/employees/employee-detailed.dto";
|
||||||
import { toCompanyCodeFromString } from "src/identity-and-account/employees/employee.utils";
|
import { toCompanyCodeFromString } from "src/identity-and-account/employees/employee.utils";
|
||||||
|
|
@ -12,7 +13,7 @@ export class EmployeesCreateService {
|
||||||
constructor(private readonly prisma: PrismaService) { }
|
constructor(private readonly prisma: PrismaService) { }
|
||||||
|
|
||||||
async createEmployee(dto: EmployeeDetailedDto): Promise<Result<boolean, string>> {
|
async createEmployee(dto: EmployeeDetailedDto): Promise<Result<boolean, string>> {
|
||||||
const normalized_access = toBooleanFromString(dto.user_module_access);
|
const normalized_access = toBooleanFromKeys<Modules>(dto.user_module_access);
|
||||||
const supervisor_id = await this.toIdFromFullName(dto.supervisor_full_name);
|
const supervisor_id = await this.toIdFromFullName(dto.supervisor_full_name);
|
||||||
const company_code = toCompanyCodeFromString(dto.company_name);
|
const company_code = toCompanyCodeFromString(dto.company_name);
|
||||||
const first_work_day = toDateFromString(dto.first_work_day);
|
const first_work_day = toDateFromString(dto.first_work_day);
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from "@nestjs/common";
|
||||||
import { PrismaService } from "src/prisma/prisma.service";
|
import { PrismaService } from "src/prisma/prisma.service";
|
||||||
|
|
||||||
import { Modules, toStringFromBoolean } from "src/common/mappers/module-access.mapper";
|
import { Modules } from "src/common/mappers/module-access.mapper";
|
||||||
import { EmailToIdResolver } from "src/common/mappers/email-id.mapper";
|
import { EmailToIdResolver } from "src/common/mappers/email-id.mapper";
|
||||||
import { toStringFromDate } from "src/common/utils/date-utils";
|
import { toStringFromDate } from "src/common/utils/date-utils";
|
||||||
import { Result } from "src/common/errors/result-error.factory";
|
import { Result } from "src/common/errors/result-error.factory";
|
||||||
|
|
||||||
import { toStringFromCompanyCode } from "src/identity-and-account/employees/employee.utils";
|
import { toStringFromCompanyCode } from "src/identity-and-account/employees/employee.utils";
|
||||||
import { EmployeeDetailedDto } from "src/identity-and-account/employees/employee-detailed.dto";
|
import { EmployeeDetailedDto } from "src/identity-and-account/employees/employee-detailed.dto";
|
||||||
|
import { toKeysFromBoolean } from "src/common/utils/boolean-utils";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class EmployeesGetService {
|
export class EmployeesGetService {
|
||||||
|
|
@ -59,6 +60,7 @@ export class EmployeesGetService {
|
||||||
last_work_day: r.last_work_day ? toStringFromDate(r.last_work_day) : null,
|
last_work_day: r.last_work_day ? toStringFromDate(r.last_work_day) : null,
|
||||||
preset_id: r.schedule_preset_id ?? undefined,
|
preset_id: r.schedule_preset_id ?? undefined,
|
||||||
})));
|
})));
|
||||||
|
console.log('Employee_list', employee_list);
|
||||||
return { success: true, data: employee_list };
|
return { success: true, data: employee_list };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -174,7 +176,7 @@ export class EmployeesGetService {
|
||||||
|
|
||||||
let module_access_array: Modules[] = [];
|
let module_access_array: Modules[] = [];
|
||||||
if (employee.user.user_module_access) {
|
if (employee.user.user_module_access) {
|
||||||
module_access_array = toStringFromBoolean(employee.user.user_module_access);
|
module_access_array = toKeysFromBoolean(employee.user.user_module_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
const company_name = toStringFromCompanyCode(employee.company_code);
|
const company_name = toStringFromCompanyCode(employee.company_code);
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from "@nestjs/common";
|
||||||
import { PrismaService } from "src/prisma/prisma.service";
|
import { PrismaService } from "src/prisma/prisma.service";
|
||||||
|
|
||||||
import { toBooleanFromString } from "src/common/mappers/module-access.mapper";
|
import { Modules } from "src/common/mappers/module-access.mapper";
|
||||||
import { EmailToIdResolver } from "src/common/mappers/email-id.mapper";
|
import { EmailToIdResolver } from "src/common/mappers/email-id.mapper";
|
||||||
import { toDateFromString } from "src/common/utils/date-utils";
|
import { toDateFromString } from "src/common/utils/date-utils";
|
||||||
import { Result } from "src/common/errors/result-error.factory";
|
import { Result } from "src/common/errors/result-error.factory";
|
||||||
|
|
||||||
import { toCompanyCodeFromString } from "src/identity-and-account/employees/employee.utils";
|
import { toCompanyCodeFromString } from "src/identity-and-account/employees/employee.utils";
|
||||||
import { EmployeeDetailedDto } from "src/identity-and-account/employees/employee-detailed.dto";
|
import { EmployeeDetailedDto } from "src/identity-and-account/employees/employee-detailed.dto";
|
||||||
|
import { toBooleanFromKeys } from "src/common/utils/boolean-utils";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class EmployeesUpdateService {
|
export class EmployeesUpdateService {
|
||||||
|
|
@ -22,7 +23,7 @@ export class EmployeesUpdateService {
|
||||||
|
|
||||||
const company_code = toCompanyCodeFromString(dto.company_name);
|
const company_code = toCompanyCodeFromString(dto.company_name);
|
||||||
const supervisor_id = await this.toIdFromFullName(dto.supervisor_full_name);
|
const supervisor_id = await this.toIdFromFullName(dto.supervisor_full_name);
|
||||||
const normalized_access = await toBooleanFromString(dto.user_module_access);
|
const normalized_access = toBooleanFromKeys<Modules>(dto.user_module_access);
|
||||||
const last_work_day = dto.last_work_day ? toDateFromString(dto.last_work_day) : null;
|
const last_work_day = dto.last_work_day ? toDateFromString(dto.last_work_day) : null;
|
||||||
|
|
||||||
await this.prisma.$transaction(async (tx) => {
|
await this.prisma.$transaction(async (tx) => {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||||
import { Modules, Users } from '@prisma/client';
|
import { Modules, Users } from '@prisma/client';
|
||||||
import { toStringFromBoolean } from 'src/common/mappers/module-access.mapper';
|
import { toKeysFromBoolean } from 'src/common/utils/boolean-utils';
|
||||||
import { PrismaService } from 'src/prisma/prisma.service';
|
import { PrismaService } from 'src/prisma/prisma.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|
@ -29,7 +29,7 @@ export abstract class AbstractUserService {
|
||||||
}
|
}
|
||||||
|
|
||||||
let module_access: Modules[] = [];
|
let module_access: Modules[] = [];
|
||||||
if (user.user_module_access !== null) module_access = toStringFromBoolean(user.user_module_access);
|
if (user.user_module_access !== null) module_access = toKeysFromBoolean(user.user_module_access);
|
||||||
|
|
||||||
const clean_user = {
|
const clean_user = {
|
||||||
first_name: user.first_name,
|
first_name: user.first_name,
|
||||||
|
|
|
||||||
|
|
@ -11,31 +11,32 @@ export class CsvExportController {
|
||||||
@Get('csv/:year/:period_no')
|
@Get('csv/:year/:period_no')
|
||||||
@ModuleAccessAllowed(ModulesEnum.employee_management)
|
@ModuleAccessAllowed(ModulesEnum.employee_management)
|
||||||
async exportCsv(
|
async exportCsv(
|
||||||
@Query('approved') approved: boolean,
|
@Query('approved') approved: string,
|
||||||
@Query('shifts') shifts: boolean,
|
@Query('shifts') shifts: string,
|
||||||
@Query('expenses') expenses: boolean,
|
@Query('expenses') expenses: string,
|
||||||
@Query('holiday') holiday: boolean,
|
@Query('holiday') holiday: string,
|
||||||
@Query('vacation') vacation: boolean,
|
@Query('vacation') vacation: string,
|
||||||
@Query('targo') targo: boolean,
|
@Query('targo') targo: string,
|
||||||
@Query('solucom') solucom: boolean,
|
@Query('solucom') solucom: string,
|
||||||
@Param('year') year: number,
|
@Param('year') year: number,
|
||||||
@Param('period_no') period_no: number,
|
@Param('period_no') period_no: number,
|
||||||
@Res() response: Response,
|
@Res() response: Response,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
console.log({ targo, solucom });
|
||||||
const rows = await this.csvService.collectTransaction(
|
const rows = await this.csvService.collectTransaction(
|
||||||
year,
|
year,
|
||||||
period_no,
|
period_no,
|
||||||
{
|
{
|
||||||
approved: approved ?? false,
|
approved: approved === 'true',
|
||||||
types: {
|
types: {
|
||||||
shifts: shifts ?? false,
|
shifts: shifts === 'true',
|
||||||
expenses: expenses ?? false,
|
expenses: expenses === 'true',
|
||||||
holiday: holiday ?? false,
|
holiday: holiday === 'true',
|
||||||
vacation: vacation ?? false,
|
vacation: vacation === 'true',
|
||||||
},
|
},
|
||||||
companies: {
|
companies: {
|
||||||
targo: targo ?? false,
|
targo: targo === 'true',
|
||||||
solucom: solucom ?? false,
|
solucom: solucom === 'true',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ export class CsvExportService {
|
||||||
filters: Filters,
|
filters: Filters,
|
||||||
// approved: boolean = true
|
// approved: boolean = true
|
||||||
): Promise<CsvRow[]> {
|
): Promise<CsvRow[]> {
|
||||||
|
console.log('data received: ', filters)
|
||||||
//fetch period
|
//fetch period
|
||||||
const period = await this.prisma.payPeriods.findFirst({
|
const period = await this.prisma.payPeriods.findFirst({
|
||||||
where: { pay_year: year, pay_period_no: period_no },
|
where: { pay_year: year, pay_period_no: period_no },
|
||||||
|
|
@ -25,7 +26,7 @@ export class CsvExportService {
|
||||||
const start = period.period_start;
|
const start = period.period_start;
|
||||||
const end = period.period_end;
|
const end = period.period_end;
|
||||||
|
|
||||||
//fetch company codes from .env
|
//fetch company codes
|
||||||
const company_codes = this.resolveCompanyCodes(filters.companies);
|
const company_codes = this.resolveCompanyCodes(filters.companies);
|
||||||
if (company_codes.length === 0) throw new BadRequestException('No company selected');
|
if (company_codes.length === 0) throw new BadRequestException('No company selected');
|
||||||
|
|
||||||
|
|
@ -272,9 +273,10 @@ export class CsvExportService {
|
||||||
out.push(code_no);
|
out.push(code_no);
|
||||||
}
|
}
|
||||||
if (companies.solucom) {
|
if (companies.solucom) {
|
||||||
const code_no = 251585;
|
const code_no = 271585;
|
||||||
out.push(code_no);
|
out.push(code_no);
|
||||||
}
|
}
|
||||||
|
console.log('company codes = ', out);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user