This is powerfull Express wrapper!
import { asyncHandler, Exception } from "@lib";
export const signin = asyncHandler(async (req, res) => {
if (!req.body.user) {
throw Exception.badRequest("user must be provided");
}
});
if we use asyncHandlers we shouldn't use try/catch for catching error and sending this to error hendler middleware.
We are using class-validator for validation.
// dto:
import { IsNotEmpty, IsEmail } from "class-validator";
export class AuthSchema {
@IsEmail()
email: string;
@IsNotEmpty()
password: string;
}
//route
import { validateBody } from "@lib";
import { AuthSchema } from "./dto/auth.dto";
const authRouter = express.Router();
authRouter.post("/signup", validateBody(AuthSchema), signup);