node-express-realworld-example-app icon indicating copy to clipboard operation
node-express-realworld-example-app copied to clipboard

Too much repeated code : Using a validation library like Joi or Zod can indeed help improve code readability and provide a DRY code structure

Open sharmag44 opened this issue 11 months ago • 0 comments

const email = input.email?.trim(); const username = input.username?.trim(); const password = input.password?.trim(); const { image, bio, demo } = input;

if (!email) { throw new HttpException(422, { errors: { email: ["can't be blank"] } }); }

if (!username) { throw new HttpException(422, { errors: { username: ["can't be blank"] } }); }

if (!password) { throw new HttpException(422, { errors: { password: ["can't be blank"] } }); }

export const updatePassword = {
  params: Joi.object().keys({
    id: Joi.string().custom(objectId),
  }),
  body: Joi.object().keys({
    password: Joi.string().required(),
    newPassword: Joi.string().required(),
  }),
}

sharmag44 avatar Mar 07 '24 11:03 sharmag44