refactor(timesheet): add boolean property to indicate if user has schedule preset or not, used to display set preset buttons on timesheet.
This commit is contained in:
parent
74fe9fc945
commit
17f06e7867
|
|
@ -71,11 +71,12 @@ export class GetTimesheetsOverviewService {
|
|||
//find user infos using the employee_id
|
||||
const employee = await this.prisma.employees.findUnique({
|
||||
where: { id: employee_id.data },
|
||||
include: { user: true },
|
||||
include: { schedule_preset: true, user: true },
|
||||
});
|
||||
if (!employee) return { success: false, error: `EMPLOYEE_NOT_FOUND` }
|
||||
|
||||
//builds employee full name
|
||||
//builds employee details
|
||||
const has_preset_schedule = employee.schedule_preset !== null;
|
||||
const user = employee.user;
|
||||
const employee_fullname = `${user.first_name} ${user.last_name}`.trim();
|
||||
|
||||
|
|
@ -84,7 +85,7 @@ export class GetTimesheetsOverviewService {
|
|||
const timesheets = await Promise.all(rows.map((timesheet) => this.mapOneTimesheet(timesheet)));
|
||||
if (!timesheets) return { success: false, error: 'INVALID_TIMESHEET' }
|
||||
|
||||
return { success: true, data: { employee_fullname, timesheets } };
|
||||
return { success: true, data: { has_preset_schedule, employee_fullname, timesheets } };
|
||||
} catch (error) {
|
||||
return { success: false, error: 'TIMESHEET_NOT_FOUND' }
|
||||
}
|
||||
|
|
@ -100,7 +101,7 @@ export class GetTimesheetsOverviewService {
|
|||
include: {
|
||||
employee: { include: { user: true } },
|
||||
shift: { include: { bank_code: true }, orderBy: { start_time: 'asc' } },
|
||||
expense: { include: { bank_code: true, attachment_record: true }, orderBy: [{ date: 'asc' }, {bank_code_id: 'desc'}] },
|
||||
expense: { include: { bank_code: true, attachment_record: true }, orderBy: [{ date: 'asc' }, { bank_code_id: 'desc' }] },
|
||||
},
|
||||
orderBy: { start_date: 'asc' },
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ export class TimesheetEntity {
|
|||
}
|
||||
|
||||
export class Timesheets {
|
||||
@IsBoolean() has_preset_schedule: boolean;
|
||||
@IsString() employee_fullname: string;
|
||||
@Type(() => Timesheet) timesheets: Timesheet[];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user