fix(expense): allow creation of expense with optionally-provided employee email
This commit is contained in:
parent
2936b84b47
commit
b7cf7d7208
|
|
@ -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')
|
||||||
|
|
|
||||||
|
|
@ -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',
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user