Skip to content

Instantly share code, notes, and snippets.

@sambhav2612
Created February 25, 2022 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sambhav2612/138793fff55538c95105a6b5f388f6a0 to your computer and use it in GitHub Desktop.
Save sambhav2612/138793fff55538c95105a6b5f388f6a0 to your computer and use it in GitHub Desktop.
// sharing as much as code possible
async getReferralReportMetaData(
_id: string,
type: string,
from: string,
to: string,
): Promise<any> {
return {
referralsRequested: await this.applicantStageMappingService.getLatentApplicationCountPerStage(
{
$match: {
'applicant.requester': { $ne: null },
[type === 'top'
? 'applicant.organization'
: 'applicant.requester']: ObjectId(_id),
},
},
'REFERRAL_REQUESTED',
from,
to,
),
referralsReceived: await this.applicantStageMappingService.getLatentApplicationCountPerStage(
{
$match: {
[type === 'top'
? 'applicant.organization'
: 'applicant.referrer']: ObjectId(_id),
},
},
{ $ne: 'REQUEST_WITHDRAWN' },
from,
to,
),
requestsWithdrawn: await this.applicantStageMappingService.getLatentApplicationCountPerStage(
{
$match: {
'applicant.requester': { $ne: null },
[type === 'top'
? 'applicant.organization'
: 'applicant.requester']: ObjectId(_id),
},
},
'REQUEST_WITHDRAWN',
from,
to,
),
referralsWithdrawn: await this.applicantStageMappingService.getLatentApplicationCountPerStage(
{
$match: {
'applicant.requester': { $ne: null },
[type === 'top'
? 'applicant.organization'
: 'applicant.referrer']: ObjectId(_id),
},
},
'REQUEST_WITHDRAWN',
from,
to,
),
referralsAccepted: await this.applicantStageMappingService.getLatentApplicationCountPerStage(
{
$match: {
[type === 'top'
? 'applicant.organization'
: 'applicant.referrer']: ObjectId(_id),
},
},
{
$nin: [
'REFERRAL_REQUESTED',
'REQUEST_WITHDRAWN',
'REJECTED_BY_EMPLOYEE',
],
},
from,
to,
),
referralsRejected: await this.applicantStageMappingService.getLatentApplicationCountPerStage(
{
$match: {
[type === 'top'
? 'applicant.organization'
: 'applicant.referrer']: ObjectId(_id),
},
},
'REJECTED_BY_EMPLOYEE',
from,
to,
),
referralsHired: await this.applicantStageMappingService.getLatentApplicationCountPerStage(
{
$match: {
[type === 'top'
? 'applicant.organization'
: 'applicant.referrer']: ObjectId(_id),
},
},
'HIRED',
from,
to,
),
referralTAT: await this.getReferralTAT(_id, type),
};
}
// primary service method being called
async getReferralReport(from: string, to: string): Promise<any> {
return await Promise.all(
(
(await this.organizationService.findAllOrganizationsForReports()) || []
).map(async ({ _id, name, createdAt, ats_integrated }) => {
const accounts = await this.accountService.getAccountsByOrganizations([
_id,
]);
return {
_id,
name,
createdAt,
ats_integrated,
teamSize: await this.accountService.getTeamSizeForOrganization(_id),
teamConnections: await this.potentialApplicantService.getConnectionCount(
(accounts || []).map(({ _id }) => _id),
[],
),
...(await this.getReferralReportMetaData(_id, 'top', from, to)),
accounts: await Promise.all(
(accounts || []).map(async ({ _id, name, createdAt, role }) => ({
_id,
name,
role,
createdAt,
connectionCount: await this.potentialApplicantService.getConnectionCount(
[_id],
[],
),
...(await this.getReferralReportMetaData(_id, 'inner', from, to)),
})),
),
};
}),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment