Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/server/actions/Agencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,37 @@ export async function approveAgency(
const agency = await AgencyModel.findById(id).exec();
return agency as Agency;
}

/**
*
* @param id The ID of the agencyInfoForm to reject
* @returns The updated agency
* @throws 404 if no agency is found with the ID
*/
export async function rejectAgency(id: string): Promise<AgencyInfoForm | null> {
await authenticateServerAction();
await dbConnect();

// Set the latency agencyInfoForm to rejected
const updatedAgency = await AgencyInfoFormModel.updateOne(
{ _id: id },
{
$set: { approved: false },
}
).catch((error) => {
mongoErrorHandler(error);
});

if (updatedAgency!.modifiedCount === 0) {
throw new JSendResponse({
status: 'fail',
data: { message: 'AgencyInfoForm not found' },
});
}

return updatedAgency as unknown as AgencyInfoForm;
}

/**
* Handles common MongoDB insertion errors and throws an appropriate ApiError.
* @param error - The error object returned by MongoDB.
Expand Down
23 changes: 12 additions & 11 deletions src/server/models/Agency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,19 @@ AgencySchema.virtual('currentStatus').get(function (this: Agency) {
}
}

const differenceInMilliseconds: number =
currentTime.getTime() - this.updatedAt.getTime();
const differenceInDays: number = Math.floor(
differenceInMilliseconds / (1000 * 3600 * 24)
);
if (differenceInDays < this.updateScheduleInDays - 14) {
return agencyUpdateStatus.Completed;
} else if (differenceInDays < this.updateScheduleInDays) {
return agencyUpdateStatus.NeedsReview;
} else if (differenceInDays >= this.updateScheduleInDays) {
return agencyUpdateStatus.Expired;
// Check latest form for approval
if (this.info.length !== 0) {
return this.info[this.info.length - 1].approved
? agencyUpdateStatus.Completed
: agencyUpdateStatus.Expired;
}

// If there is no info associated with an agency look at the outer status
if (this.approvalStatus) {
return this.approvalStatus;
}

return agencyUpdateStatus.Expired;
});

AgencySchema.virtual('daysSinceEmailSent').get(function () {
Expand Down
1 change: 1 addition & 0 deletions src/utils/conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ function zodLanguagesToTs(data: Inputs): AgencyInfoForm['languages'] {

export function zodFormToTs(data: Inputs): AgencyInfoForm {
const agencyInfo: AgencyInfoForm = {
approved: false,
legalAgencyName: data.legalName,
alsoKnownAs: data.akas.split(' '),
legalOrganizationalStatus: data.legalStatus.split(' '),
Expand Down
1 change: 1 addition & 0 deletions src/utils/types/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface AgencyInfoForm {
_id?: string;
createdAt?: Date;
updatedAt?: Date;
approved: boolean;
legalAgencyName: string;
alsoKnownAs?: string[];
legalOrganizationalStatus: (
Expand Down
1 change: 1 addition & 0 deletions test/testData/testAgency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const testAgency: Agency = {
name: 'This is another agency',
info: [
{
approved: false,
legalAgencyName: 'This is another agency',
alsoKnownAs: [],
legalOrganizationalStatus: ['Non-profit'],
Expand Down