fix(expense): allow creation of expense with optionally-provided employee email

This commit is contained in:
Nic D 2026-02-24 08:31:24 -05:00
parent 2936b84b47
commit b7cf7d7208
2 changed files with 11 additions and 5 deletions

View File

@ -18,9 +18,13 @@ export class ExpenseController {
@Post('create') @Post('create')
@ModuleAccessAllowed(ModulesEnum.timesheets) @ModuleAccessAllowed(ModulesEnum.timesheets)
create(@Access('email') email: string, @Body() dto: ExpenseDto): Promise<Result<ExpenseDto, string>> { create(
@Body() dto: ExpenseDto,
@Access('email') email: string,
@Query('employee_email') employee_email?: string,
): Promise<Result<ExpenseDto, string>> {
if (!email) throw new UnauthorizedException('Unauthorized User'); if (!email) throw new UnauthorizedException('Unauthorized User');
return this.createService.createExpense(dto, email); return this.createService.createExpense(dto, email, employee_email);
} }
@Patch('update') @Patch('update')

View File

@ -21,10 +21,12 @@ export class ExpenseCreateService {
//_________________________________________________________________ //_________________________________________________________________
// CREATE // CREATE
//_________________________________________________________________ //_________________________________________________________________
async createExpense(dto: ExpenseDto, email: string): Promise<Result<ExpenseDto, string>> { async createExpense(dto: ExpenseDto, email: string, employee_email?: string): Promise<Result<ExpenseDto, string>> {
try { try {
const accountEmail = employee_email ?? email;
//fetch employee_id using req.user.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 }; if (!employee_id.success) return { success: false, error: employee_id.error };
//normalize strings and dates and Parse numbers //normalize strings and dates and Parse numbers
@ -68,7 +70,7 @@ export class ExpenseCreateService {
// notify timesheet approval observers of changes // notify timesheet approval observers of changes
this.payPeriodEventService.emit({ this.payPeriodEventService.emit({
employee_email: email, employee_email: accountEmail,
event_type: 'expense', event_type: 'expense',
action: 'create', action: 'create',
}); });