Skip to content

Commit 92e91bc

Browse files
author
Chahat Gupta
committed
Amended folder delete api to delete children at time of parent delete
1 parent 296b851 commit 92e91bc

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/routes/mock_folder.routes.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,16 @@ router.delete('/:id', async (req: Request, res: Response): Promise<void> => {
9090
const response: ApiResponse = ApiResponse.error((deleteError as Error).message)
9191
res.status(500).json(response)
9292
} else {
93-
const response: ApiResponse = ApiResponse.success(null, `Document with id ${req.params.id} removed`)
94-
res.status(200).json(response)
93+
// also delete mocks associated to that folder
94+
Mock.deleteMany({ parentId: req.params.id }, (deleteError: mongoose.CallbackError) => {
95+
if (deleteError) {
96+
const response: ApiResponse = ApiResponse.error((deleteError as Error).message)
97+
res.status(500).json(response)
98+
} else {
99+
const response: ApiResponse = ApiResponse.success(null, `Document with id ${req.params.id} removed`)
100+
res.status(200).json(response)
101+
}
102+
})
95103
}
96104
})
97105
} catch (error: unknown) {

0 commit comments

Comments
 (0)