Skip to content

Commit

Permalink
add validation checks to update and add
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarkowsky committed Sep 24, 2024
1 parent 7f99795 commit ac702ee
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions express-api/src/services/users/usersServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -227,6 +230,9 @@ const updateUser = async (user: DeepPartial<User>) => {
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}`,
Expand Down

0 comments on commit ac702ee

Please sign in to comment.