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')
@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');
return this.createService.createExpense(dto, email);
return this.createService.createExpense(dto, email, employee_email);
}
@Patch('update')

View File

@ -21,10 +21,12 @@ export class ExpenseCreateService {
//_________________________________________________________________
// 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 {
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',
});