Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporary fix for mongoose return types #71

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 12 additions & 6 deletions src/server/actions/Agencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,21 @@ export async function updateService(
*/
export async function deleteAgency(id: string): Promise<Agency | null> {
await dbConnect();
const deletedAgency = await AgencyModel.findByIdAndDelete(id).catch(
// A mongoose update changed the return type of findByIdAndDelete
// https://github.com/Automattic/mongoose/issues/14233
// Should be fixed in the next 7.6.x release
const deletedAgency = (await AgencyModel.findByIdAndDelete(id).catch(
(error) => {
mongoErrorHandler(error);
}
);
)) as unknown as Agency;
if (!deletedAgency) {
throw new JSendResponse({
status: 'fail',
data: { message: 'Agency not found' },
});
}
return deletedAgency as Agency;
return deletedAgency;
}

/**
Expand All @@ -243,18 +246,21 @@ export async function deleteAgency(id: string): Promise<Agency | null> {
*/
export async function deleteService(id: string): Promise<Service | null> {
await dbConnect();
const deletedService = await ServiceModel.findByIdAndDelete(id).catch(
// A mongoose update changed the return type of findByIdAndDelete
// https://github.com/Automattic/mongoose/issues/14233
// Should be fixed in the next 7.6.x release
const deletedService = (await ServiceModel.findByIdAndDelete(id).catch(
(error) => {
mongoErrorHandler(error);
}
);
)) as unknown as Service;
if (!deletedService) {
throw new JSendResponse({
status: 'fail',
data: { message: 'Service not found' },
});
}
return deletedService as Service;
return deletedService;
}

/**
Expand Down