From ac702ee870865d4ad2ad677dec9da39b7b796ff4 Mon Sep 17 00:00:00 2001 From: dbarkowsky Date: Tue, 24 Sep 2024 14:08:26 -0700 Subject: [PATCH] add validation checks to update and add --- express-api/src/services/users/usersServices.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/express-api/src/services/users/usersServices.ts b/express-api/src/services/users/usersServices.ts index 58ca09aa4..da7cb6b88 100644 --- a/express-api/src/services/users/usersServices.ts +++ b/express-api/src/services/users/usersServices.ts @@ -212,6 +212,9 @@ const addUser = async (user: User) => { if (resource) { throw new ErrorWithCode('Resource already exists.', 409); } + if (!validateEmail(user.Email)) { + throw new Error('Invalid email.'); + } const retUser = await AppDataSource.getRepository(User).save(user); return retUser; }; @@ -227,6 +230,9 @@ const updateUser = async (user: DeepPartial) => { if (!resource) { throw new ErrorWithCode('Resource does not exist.', 404); } + if (user.Email && !validateEmail(user.Email)) { + throw new Error('Invalid email.'); + } await AppDataSource.getRepository(User).update(user.Id, { ...user, DisplayName: `${user.LastName}, ${user.FirstName}`,