gothinkster / gothinkster/node-express-realworld-example-app

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
#151 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3.8k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

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"] } });
}

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.