Skip to content

Commit

Permalink
added endpoint to search cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald-pro committed Jan 16, 2024
1 parent 47afaf0 commit 891b0dc
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions routes/processes/case.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,59 @@ router.put("/assign/update/:clinicNumber", async (req, res) => {
}
});

router.get("/search", async (req, res) => {
try {
let clinicNumber = req.query.clinic_number;

let client = await Client.findOne({
where: {
clinic_number: clinicNumber
}
});

if (!client) {
return res.status(404).json({
success: false,
message: `Clinic number ${clinicNumber} does not exist in the system`
});
}

const cases = await caseAssign.findOne({
where: {
client_id: client.id
}
});

if (!cases || cases.length === 0) {
return res.status(400).json({
success: false,
message: `No case found for Client ${clinicNumber}`
});
} else {
const getCases = Array.isArray(cases)
? cases.map(
({
reason_assign,
other_reason,
relationship,
start_date,
end_date
}) => ({
reason_assign,
other_reason,
relationship,
start_date,
end_date
})
)
: [cases];

res.send(getCases);
}
} catch (error) {
console.error(error);
res.status(500).send("Error while getting cases");
}
});

module.exports = router;

0 comments on commit 891b0dc

Please sign in to comment.