Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion service/.env.sample
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
PII_DB_URL_KZ=
CLINICAL_DB_URL_KZ=
MASTER_DB_URL=

USER_API_URL=

NODE_ENV=
PORT=

KAFKAJS_NO_PARTITIONER_WARNING=
21 changes: 13 additions & 8 deletions service/middlewares/populateMiddleware.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { getUserByID } from "#queries/users";
import fetch from "node-fetch";

const USER_API_URL = process.env.USER_API_URL;
const USER_API_LOCAL_HOST = "http://localhost:3010";

export const populateUser = async (req, res, next) => {
const country = req.header("x-country-alpha-2");
const user_id = req.header("x-user-id");

const user = await getUserByID(country, user_id)
.then((res) => res.rows[0])
.catch((err) => {
throw err;
});
const user = await fetch(`${USER_API_URL}/user/v1/user/${user_id}`, {
headers: {
...req.headers,
host: USER_API_LOCAL_HOST,
"Content-type": "application/json",
},
})
.then((raw) => raw.json())
.catch(console.log);

req.user = user;

return next();
};
13 changes: 0 additions & 13 deletions service/queries/users.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
import { getDBPool } from "#utils/dbConfig";

export const getUserByID = async (poolCountry, user_id) =>
await getDBPool("piiDb", poolCountry).query(
`
SELECT user_id, country_id, type, client_detail_id, notification_preference_id, password
FROM "user"
WHERE deleted_at is NULL AND user_id = $1
ORDER BY created_at DESC
LIMIT 1;

`,
[user_id]
);

export const getClientsDetailsForUpcomingConsultationsQuery = async ({
poolCountry,
clientIds,
Expand Down