Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #306 from kmcwebdev/development
Browse files Browse the repository at this point in the history
Refactor code to handle new request approver validation and improve s…
  • Loading branch information
csulit authored Sep 30, 2023
2 parents 3b7e8e4 + e924fa1 commit 3f6e180
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { ConfigService } from '@nestjs/config';
import { Injectable, Logger, OnModuleInit } from '@nestjs/common';
import {
HttpException,
HttpStatus,
Injectable,
Logger,
OnModuleInit,
} from '@nestjs/common';
import { catchError, firstValueFrom } from 'rxjs';
import { HttpService } from '@nestjs/axios';
import { EventEmitter2, OnEvent } from '@nestjs/event-emitter';
Expand Down Expand Up @@ -189,6 +195,21 @@ export class ReimbursementMemphisNewRequestService implements OnModuleInit {
const approvers = newRequest.dynamic_approvers.split(',');
approvers.forEach(async (email) => {
await this.pgsql.transaction().execute(async (trx) => {
const IamMyManagerStupidMotherFucker = await trx
.selectFrom('users')
.select('users.email')
.where('users.user_id', '=', newRequest.requestor_id)
.executeTakeFirst();

if (IamMyManagerStupidMotherFucker) {
if (IamMyManagerStupidMotherFucker.email === email) {
throw new HttpException(
'Nope not gonna happen 🤪',
HttpStatus.BAD_REQUEST,
);
}
}

const propelauthUser =
await this.usersApiService.fetchUserInPropelauthByEmail(
email,
Expand Down
6 changes: 5 additions & 1 deletion src/finance/services/reimbursement.for-approval.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ export class ReimbursementForApprovalService {
'users.hrbp_approver_email',
'users.payroll_account',
'finance_reimbursement_requests.created_at',
sql<number>`ts_rank(to_tsvector('english', finance_reimbursement_requests.reference_no || ' ' || coalesce(users.full_name, '') || ' ' || users.email || ' ' ||
coalesce(users.client_name, '') || ' ' || coalesce(users.hrbp_approver_email, '')), plainto_tsquery(${
filter?.text_search || 'r'
}))`.as('rank'),
]);

query = query.where(
Expand Down Expand Up @@ -259,7 +263,7 @@ export class ReimbursementForApprovalService {
if (filter?.text_search) {
query = query.where(
sql`to_tsvector('english', finance_reimbursement_requests.reference_no || ' ' || coalesce(users.full_name, '') || ' ' || users.email || ' ' ||
coalesce(users.client_name, '') || ' ' || coalesce(users.hrbp_approver_email, '')) @@ websearch_to_tsquery(${filter.text_search})`,
coalesce(users.client_name, '') || ' ' || coalesce(users.hrbp_approver_email, '')) @@ plainto_tsquery(${filter.text_search})`,
);
}

Expand Down

0 comments on commit 3f6e180

Please sign in to comment.