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: 2 additions & 2 deletions service/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ export const updateNotificationPreferences = async ({
});
};

export const getTwilioToken = async ({ userId, consultationId }) => {
const token = videoToken(userId, consultationId, TWILIO_CONFIG);
export const getTwilioToken = async ({ user_id, consultationId }) => {
const token = videoToken(user_id, consultationId, TWILIO_CONFIG);

return { token: token.toJwt() };
};
Expand Down
2 changes: 1 addition & 1 deletion service/queries/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const getProviderUserByEmail = async (poolCountry, email) =>
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
SELECT user_id, country_id, type, client_detail_id, provider_detail_id, notification_preference_id, password
FROM "user"
WHERE user_id = $1
AND deleted_at IS NULL
Expand Down
30 changes: 23 additions & 7 deletions service/routes/v1/UserRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,30 @@ router.patch("/password", securedRoute, async (req, res, next) => {
return await changePasswordSchema
.noUnknown(true)
.strict(true)
.validate({ country, language, user_id, ...payload })
.validate({ ...payload, country, language, user_id })
.then(changeUserPassword)
.then((result) => res.status(200).send(result))
.catch(next);
});

router.get("/:id", async (req, res, next) => {
/**
* #route GET /user/v1/user/:id
* #desc Get user data by ID (Internal use only)
*/
const country = req.header("x-country-alpha-2");
const language = req.header("x-language-alpha-2");
const { id } = req.params;

return await getUserByIdSchema
.noUnknown(true)
.strict(true)
.validate({ country, language, user_id: id })
.then(getSharedUserData)
.then((result) => res.status(200).send(result))
.catch(next);
});

router
.route("/notification-preferences")
.get(securedRoute, async (req, res, next) => {
Expand Down Expand Up @@ -87,13 +105,12 @@ router
const language = req.header("x-language-alpha-2");

const notification_preference_id = req.user.notification_preference_id;

const payload = req.body;

return await updateNotificationPreferencesSchema
.noUnknown(true)
.strict(true)
.validate({ country, language, notification_preference_id, ...payload })
.validate({ ...payload, country, language, notification_preference_id })
.then(updateNotificationPreferences)
.then((result) => res.status(200).send(result))
.catch(next);
Expand All @@ -109,14 +126,13 @@ router
const country = req.header("x-country-alpha-2");
const language = req.header("x-language-alpha-2");

const userId = req.user.user_id;

const user_id = req.user.user_id;
const consultationId = req.query.consultationId;

return await getTwilioTokenSchema
.noUnknown(true)
.strict(true)
.validate({ country, language, userId, consultationId })
.validate({ country, language, user_id, consultationId })
.then(getTwilioToken)
.then((result) => res.status(200).send(result))
.catch(next);
Expand All @@ -135,7 +151,7 @@ router.route("/add-contact-form").post(async (req, res, next) => {
return await addContactFormSchema
.noUnknown(true)
.strict(true)
.validate({ country, language, ...payload })
.validate({ ...payload, country, language })
.then(addContactForm)
.then((result) => res.status(200).send(result))
.catch(next);
Expand Down
2 changes: 1 addition & 1 deletion service/routes/v1/authRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ router.post("/refresh-token", async (req, res, next) => {
return await refreshAccessTokenSchema
.noUnknown(true)
.strict()
.validate({ country, language, ...payload })
.validate({ ...payload, country, language })
.then(refreshAccessToken)
.then((result) => res.status(200).send(result))
.catch(next);
Expand Down
5 changes: 2 additions & 3 deletions service/routes/v1/rescueRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ router
const country = req.header("x-country-alpha-2");
const language = req.header("x-language-alpha-2");

const { email } = req.query;
const { type } = req.query;
const { email, type } = req.query;

return await initForgotPasswordSchema
.noUnknown(true)
Expand All @@ -46,7 +45,7 @@ router
return await resetForgotPasswordSchema
.noUnknown(true)
.strict(true)
.validate({ country, language, ...payload })
.validate({ ...payload, country, language })
.then(resetForgotPassword)
.then((result) => res.status(200).send(result))
.catch(next);
Expand Down
28 changes: 10 additions & 18 deletions service/schemas/userSchemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ export const createUserSchema = (language) =>
["client", "provider"]
);

export const changePasswordSchema = yup.object().shape({
country: yup.string().required(),
language: yup.string().required(),
user_id: yup.string().uuid().required(),
export const changePasswordSchema = getUserByIdSchema.shape({
oldPassword: yup.string().required(),
newPassword: yup.string().matches(PASSWORD_REGEX).required(),
});
Expand All @@ -108,22 +105,17 @@ export const getNotificationPreferencesSchema = yup.object().shape({
notification_preference_id: yup.string().uuid().required(),
});

export const updateNotificationPreferencesSchema = yup.object().shape({
country: yup.string().required(),
language: yup.string().required(),
notification_preference_id: yup.string().uuid().required(),
email: yup.boolean().required(),
consultationReminder: yup.boolean().required(),
consultationReminderMin: yup.number().positive().max(60).required(),
inPlatform: yup.boolean().required(),
push: yup.boolean().required(),
});
export const updateNotificationPreferencesSchema =
getNotificationPreferencesSchema.shape({
email: yup.boolean().required(),
consultationReminder: yup.boolean().required(),
consultationReminderMin: yup.number().positive().max(60).required(),
inPlatform: yup.boolean().required(),
push: yup.boolean().required(),
});

export const getTwilioTokenSchema = yup.object().shape({
country: yup.string().required(),
language: yup.string().required(),
export const getTwilioTokenSchema = getUserByIdSchema.shape({
consultationId: yup.string().uuid().required(),
userId: yup.string().uuid().required(),
});

export const addContactFormSchema = yup.object().shape({
Expand Down