50 lines
No EOL
1.2 KiB
JavaScript
50 lines
No EOL
1.2 KiB
JavaScript
import express from 'express';
|
|
import { databaseServices } from '../index.js';
|
|
import { fullMedicationInformationSchema } from '../validations/medications.js';
|
|
|
|
export const medicationRouter = express.Router();
|
|
|
|
medicationRouter.get('/', async (req, res) => {
|
|
let data;
|
|
try {
|
|
data = await databaseServices.getMedications();
|
|
res.status(200);
|
|
} catch (err) {
|
|
data = { Error: err?.message };
|
|
res.status(500);
|
|
} finally {
|
|
res.send(data);
|
|
}
|
|
});
|
|
|
|
medicationRouter.post('/base/', async (req, res) => {
|
|
let data;
|
|
const body = req?.body;
|
|
|
|
try {
|
|
await fullMedicationInformationSchema.validate(body);
|
|
data = await databaseServices.getBaseMedications(body);
|
|
res.status(200);
|
|
} catch (err) {
|
|
data = { Error: err?.message };
|
|
res.status(500);
|
|
} finally {
|
|
res.send(data);
|
|
}
|
|
});
|
|
|
|
medicationRouter.post('/full/', async (req, res) => {
|
|
let data;
|
|
const body = req?.body;
|
|
|
|
try {
|
|
await fullMedicationInformationSchema.validate(body);
|
|
data = await databaseServices.getFullMedicationInformation(body);
|
|
res.status(200);
|
|
} catch (err) {
|
|
data = { Error: err?.message };
|
|
res.status(500);
|
|
} finally {
|
|
res.send(data);
|
|
}
|
|
}); |