@ergool/common
v0.1.57
Published
The common repository for sharing middleware, types, and interfaces across services.
Readme
Code sharing module between different services
Which consists of middleware, events, types, error classes, etc.
The middleware validateRequest and RequestValidationError error classes are used for the express-validator node module.
import { body } from "express-validator";
import { validateRequest, BadRequestError } from "@ergool/common";
router.post(
"/v2/auth/signin",
[
body("email").isEmail(),
body("password").trim().notEmpty(),
],
validateRequest,
async (req: Request, res: Response) => {
.
.
.
if (somethingWrong) throw new BadRequestError("😟");
.
.
.
res.status(200).send();
}
);
The middleware yupValidateRequest and YupRequestValidationError error classes are used for the yup node module.
import * as yup from "yup";
import { yupValidateRequest, BadRequestError } from "@ergool/common";
const schema = yup.object().shape({
body: yup.object({
email: yup
.string()
.label("Email")
.email()
.required(),
password: yup
.string()
.trim()
.label("Password")
.required(),
}),
});
router.post(
"/v2/auth/signin",
yupValidateRequest(schema),
async (req: Request, res: Response) => {
.
.
.
if (somethingWrong) throw new BadRequestError("😟");
.
.
.
res.status(200).send();
}
);
