Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
McNaBry committed Nov 13, 2024
1 parent 760fd3e commit bb91088
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
6 changes: 3 additions & 3 deletions services/user/src/controller/user-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ export async function updateUser(req: Request, res: Response) {
const salt = bcrypt.genSaltSync(10);
const updatedUser = (await _updateUserById(
userId,
username ?? user.username,
email ?? user.email,
password ? bcrypt.hashSync(password, salt) : user.password
username ?? user.username,
email ?? user.email,
password ? bcrypt.hashSync(password, salt) : user.password,
)) as User;
handleSuccess(res, 200, `Updated data for user ${userId}`, formatUserResponse(updatedUser));
} catch (err) {
Expand Down
32 changes: 17 additions & 15 deletions services/user/src/types/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,23 @@ export const registrationSchema = z.object({
password: passwordSchema,
});

export const updateUserSchema = z.object({
username: usernameSchema.optional(),
email: emailSchema.optional(),
password: passwordSchema.optional(),
}).superRefine((data, ctx) => {
if (!data.username && !data.email && !data.password) {
// If none of the variables are present, assign error to each one
// Granular control over which is missing is not needed
ctx.addIssue({
path: ['username', 'password', 'email'],
message: UserValidationErrors.REQUIRED,
code: z.ZodIssueCode.custom,
});
}
});
export const updateUserSchema = z
.object({
username: usernameSchema.optional(),
email: emailSchema.optional(),
password: passwordSchema.optional(),
})
.superRefine((data, ctx) => {
if (!data.username && !data.email && !data.password) {
// If none of the variables are present, assign error to each one
// Granular control over which is missing is not needed
ctx.addIssue({
path: ['username', 'password', 'email'],
message: UserValidationErrors.REQUIRED,
code: z.ZodIssueCode.custom,
});
}
});

export const updateUsernameAndEmailSchema = z.object({
username: usernameSchema,
Expand Down

0 comments on commit bb91088

Please sign in to comment.