Compare commits

..

No commits in common. "refactor/update-med-calls" and "main" have entirely different histories.

4 changed files with 11 additions and 19 deletions

View file

@ -1,6 +1,6 @@
import express from 'express'; import express from 'express';
import { databaseServices } from '../index.js'; import { databaseServices } from '../index.js';
import { baseMedicationInformationSchema, fullMedicationInformationSchema } from '../validations/medications.js'; import { fullMedicationInformationSchema } from '../validations/medications.js';
export const medicationRouter = express.Router(); export const medicationRouter = express.Router();
@ -17,13 +17,10 @@ medicationRouter.get('/', async (req, res) => {
} }
}); });
medicationRouter.post('/base/', async (req, res) => { medicationRouter.get('/base/', async (req, res) => {
let data; let data;
const body = req?.body;
try { try {
await baseMedicationInformationSchema.validate(body); data = await databaseServices.getBaseMedications();
data = await databaseServices.getBaseMedications(body);
res.status(200); res.status(200);
} catch (err) { } catch (err) {
data = { Error: err?.message }; data = { Error: err?.message };

View file

@ -1,10 +1,10 @@
import { paramyxRunQuery } from '../../paramyxConnection.js'; import { paramyxRunQuery } from '../../paramyxConnection.js';
export const medicationHelpers = { export const medicationHelpers = {
getBaseMedications: async (region) => { getBaseMedications: async () => {
const [medList, medRoutes] = await Promise.all([ const [medList, medRoutes] = await Promise.all([
paramyxRunQuery('SELECT * FROM medications WHERE $1 = ANY(region)', [region]), paramyxRunQuery('SELECT * FROM medications'),
paramyxRunQuery('SELECT * FROM medication_routes WHERE region = $1', [region]) paramyxRunQuery('SELECT * FROM medication_routes')
]); ]);
const medMap = {}; const medMap = {};

View file

@ -11,10 +11,9 @@ const getMedications = async () => {
} }
}; };
const getBaseMedications = async (body) => { const getBaseMedications = async () => {
const { region } = body;
try { try {
const dataResp = medicationHelpers.getBaseMedications(region); const dataResp = medicationHelpers.getBaseMedications();
return dataResp; return dataResp;
} catch (err) { } catch (err) {
console.log('GET BASE MEDICATIONS ERROR: ', err); console.log('GET BASE MEDICATIONS ERROR: ', err);
@ -22,8 +21,8 @@ const getBaseMedications = async (body) => {
} }
} }
const getFullMedicationInformation = async (body) => { const getFullMedicationInformation = async (drug) => {
const { drugId } = body; const { drugId } = drug;
try { try {
const dataResp = medicationHelpers.getFullMedicationInformation(drugId); const dataResp = medicationHelpers.getFullMedicationInformation(drugId);
return dataResp; return dataResp;

View file

@ -1,9 +1,5 @@
import * as Yup from 'yup'; import * as Yup from 'yup';
export const baseMedicationInformationSchema = Yup.object().shape({
region: Yup.string().required("region is required")
});
export const fullMedicationInformationSchema = Yup.object().shape({ export const fullMedicationInformationSchema = Yup.object().shape({
drugId: Yup.string().required("drugId is required") drugId: Yup.string().required("drugId is required"),
}); });