diff --git a/src/time-and-attendance/expenses/expense.controller.ts b/src/time-and-attendance/expenses/expense.controller.ts index b63594f..ee55592 100644 --- a/src/time-and-attendance/expenses/expense.controller.ts +++ b/src/time-and-attendance/expenses/expense.controller.ts @@ -18,9 +18,13 @@ export class ExpenseController { @Post('create') @ModuleAccessAllowed(ModulesEnum.timesheets) - create(@Access('email') email: string, @Body() dto: ExpenseDto): Promise> { + create( + @Body() dto: ExpenseDto, + @Access('email') email: string, + @Query('employee_email') employee_email?: string, + ): Promise> { if (!email) throw new UnauthorizedException('Unauthorized User'); - return this.createService.createExpense(dto, email); + return this.createService.createExpense(dto, email, employee_email); } @Patch('update') diff --git a/src/time-and-attendance/expenses/services/expense-create.service.ts b/src/time-and-attendance/expenses/services/expense-create.service.ts index a69b7a3..1a9668b 100644 --- a/src/time-and-attendance/expenses/services/expense-create.service.ts +++ b/src/time-and-attendance/expenses/services/expense-create.service.ts @@ -21,10 +21,12 @@ export class ExpenseCreateService { //_________________________________________________________________ // CREATE //_________________________________________________________________ - async createExpense(dto: ExpenseDto, email: string): Promise> { + async createExpense(dto: ExpenseDto, email: string, employee_email?: string): Promise> { try { + const accountEmail = employee_email ?? email; + //fetch employee_id using req.user.email - const employee_id = await this.emailResolver.findIdByEmail(email); + const employee_id = await this.emailResolver.findIdByEmail(accountEmail); if (!employee_id.success) return { success: false, error: employee_id.error }; //normalize strings and dates and Parse numbers @@ -68,7 +70,7 @@ export class ExpenseCreateService { // notify timesheet approval observers of changes this.payPeriodEventService.emit({ - employee_email: email, + employee_email: accountEmail, event_type: 'expense', action: 'create', });