node-express-realworld-example-app
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
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(),
}),
}