-
-
Save sambhav2612/138793fff55538c95105a6b5f388f6a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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