feat(server): Errors from postgresql are also now in a unified response style
Some checks are pending
Create and publish a Docker image / build-and-push-server (push) Waiting to run
Create and publish a Docker image / build-and-push-chart (push) Waiting to run
Create and publish a Docker image / build-and-push-CR (push) Waiting to run
Deploy docs / deploy (push) Waiting to run

This commit is contained in:
Данил 2024-11-08 15:29:03 +03:00
parent 0ae8fe3dea
commit cd01af2eac

View file

@ -12,34 +12,44 @@ module.exports = async function getRateRoute(fastify) {
} }
let rate_res; let rate_res;
if (query['date']) try {
rate_res = await rate.getDay(
query['from_currency'],
query['conv_currency'],
query['date'],
);
else if (query['start_date'] && query['end_date'])
rate_res = await rate.getPeriod(
query['from_currency'],
query['conv_currency'],
query['start_date'],
query['end_date'],
);
else
return res.status(400).send({
status: 400,
message:
'The date or period field is incorrect. ' +
"There must be fields 'date' or 'start_date' and 'end_date'. " +
'Read more in the documentation',
});
if (typeof rate_res !== "object") return res.status(400).send({ if (query['date'])
status: 400, rate_res = await rate.getDay(
message: rate_res, query['from_currency'],
}); query['conv_currency'],
else return res.status(200).send( query['date'],
rate_res );
) else if (query['start_date'] && query['end_date'])
rate_res = await rate.getPeriod(
query['from_currency'],
query['conv_currency'],
query['start_date'],
query['end_date'],
);
else
return res.status(400).send({
status: 400,
message:
'The date or period field is incorrect. ' +
"There must be fields 'date' or 'start_date' and 'end_date'. " +
'Read more in the documentation',
});
if (typeof rate_res !== "object") return res.status(400).send({
status: 400,
message: rate_res,
});
else return res.status(200).send(
rate_res
)
} catch (err) {
fastify.log.error(err.message);
res.status(500).send({
status: 500,
message: err.message
})
}
}); });
}; };