While working on a personal project, I find myself dealing with multiple conditions. I'm wondering if there's a more efficient way to handle this as the current code appears somewhat messy with all these IFELSE statements.
public static async handleLiquidations(request : Request, response: Response){
const id = request.params.code;
const {month, year , ...optional} = request.body;
let msg = "";
if(!!month && !!year ){
const liquidationsController = new LiquidationsController();
if(optional.amountToReport){
liquidationsController.updateAmountToReport(month,year,optional.amountToReport);
} else {
msg += "missing amount to report";
} if (optional.comments) {
liquidationsController.updateComments();
} else {
msg += "missing comments";
} if (optional.startDate) {
liquidationsController.updateStartDate();
} else {
msg += "missing start date";
} if (optional.endDate) {
liquidationsController.updateEndDate();
} else {
msg += "missing end date";
}
response.status(200);
response.json({optional, msg});
return;
} else {
errorResponse(response,403,"Required arguments are missing")
}
}