Skip to content

Commit

Permalink
Merge branch 'development' into feature/US-387-cache-client-data
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-ivanovv committed Jan 15, 2023
2 parents 997598c + 8f3c819 commit b017a97
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
18 changes: 18 additions & 0 deletions service/controllers/clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import AWS from "aws-sdk";
import bcrypt from "bcryptjs";

import {
getClientByIdQuery,
updateClientDataQuery,
checkIfEmailIsUsedQuery,
deleteClientDataQuery,
Expand All @@ -19,6 +20,23 @@ const AWS_SECRET_ACCESS_KEY = process.env.AWS_SECRET_ACCESS_KEY;
const AWS_REGION = process.env.AWS_REGION;
const AWS_BUCKET_NAME = process.env.AWS_BUCKET_NAME;

export const getClientById = async ({ country, language, clientId }) => {
return await getClientByIdQuery({
poolCountry: country,
clientId,
})
.then((res) => {
if (res.rowCount === 0) {
throw clientNotFound(language);
} else {
return res.rows[0];
}
})
.catch((err) => {
throw err;
});
};

export const updateClientData = async ({
country,
language,
Expand Down
1 change: 1 addition & 0 deletions service/controllers/consultation.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const getAllConsultations = async ({ country, language, client_id }) => {

response.push({
consultation_id: consultation.consultation_id,
chat_id: consultation.chat_id,
provider_detail_id: consultation.provider_detail_id,
provider_name: `${providerName} ${
providerPatronym ? providerPatronym + " " : ""
Expand Down
13 changes: 13 additions & 0 deletions service/queries/clients.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import { getDBPool } from "#utils/dbConfig";

export const getClientByIdQuery = async ({ poolCountry, clientId }) =>
await getDBPool("piiDb", poolCountry).query(
`
SELECT client_detail_id, name, surname, nickname, email, image
FROM client_detail
WHERE client_detail_id = $1
LIMIT 1;
`,
[clientId]
);

export const getClientByUserID = async (poolCountry, user_id) =>
await getDBPool("piiDb", poolCountry).query(
`
Expand Down
26 changes: 26 additions & 0 deletions service/routes/v1/ClientRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import express from "express";
import { populateClient, populateUser } from "#middlewares/populateMiddleware";

import {
getClientByIdSchema,
updateClientDataSchema,
deleteClientDataSchema,
updateClientImageSchema,
Expand All @@ -11,6 +12,7 @@ import {
} from "#schemas/clientSchemas";

import {
getClientById,
updateClientData,
deleteClientData,
updateClientImage,
Expand All @@ -30,6 +32,30 @@ router.get("/", populateClient, async (req, res) => {
res.status(200).send(clientData);
});

router.get("/by-id", async (req, res, next) => {
/**
* #route GET /client/v1/client/by-id
* #desc Get client data by id
*/

const country = req.header("x-country-alpha-2");
const language = req.header("x-language-alpha-2");

const clientId = req.query.clientId;

return await getClientByIdSchema
.noUnknown(true)
.strict()
.validate({
country,
language,
clientId,
})
.then(getClientById)
.then((result) => res.status(200).send(result))
.catch(next);
});

router.put("/", populateClient, async (req, res, next) => {
/**
* #route PUT /client/v1/client
Expand Down
6 changes: 6 additions & 0 deletions service/schemas/clientSchemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,9 @@ export const updateClientDataProcessingSchema = yup.object().shape({
language: yup.string().required(),
dataProcessing: yup.boolean().required(),
});

export const getClientByIdSchema = yup.object().shape({
clientId: yup.string().uuid().required(),
country: yup.string().required(),
language: yup.string().required(),
});

0 comments on commit b017a97

Please sign in to comment.