Skip to content

Commit

Permalink
Add api validation
Browse files Browse the repository at this point in the history
  • Loading branch information
santiq committed May 4, 2019
1 parent ffe0221 commit 4b2251b
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions src/api/routes/auth.ts
Expand Up @@ -3,25 +3,41 @@ import { Container } from 'typedi';
import AuthService from '../../services/auth';
import { IUserInputDTO } from '../../interfaces/IUser';
import middlewares from '../middlewares';
import { celebrate, Joi } from 'celebrate';

const route = Router();

export default (app) => {

app.use('/auth', route);

route.post('/signup', async (req: Request, res: Response, next: NextFunction) => {
try {
const authServiceInstance = Container.get(AuthService);
const { user, token } = await authServiceInstance.SignUp(req.body as IUserInputDTO);
return res.json({ user, token }).status(201);
} catch (e) {
console.log('🔥 error ', e);
return next(e);
}
route.post('/signup',
celebrate({
body: Joi.object({
name: Joi.string().required(),
email: Joi.string().required(),
password: Joi.string().required(),
}),
}),
async (req: Request, res: Response, next: NextFunction) => {
try {
const authServiceInstance = Container.get(AuthService);
const { user, token } = await authServiceInstance.SignUp(req.body as IUserInputDTO);
return res.json({ user, token }).status(201);
} catch (e) {
console.log('🔥 error ', e);
return next(e);
}
});

route.post('/signin', async (req: Request, res: Response, next: NextFunction) => {
route.post('/signin',
celebrate({
body: Joi.object({
email: Joi.string().required(),
password: Joi.string().required(),
}),
}),
async (req: Request, res: Response, next: NextFunction) => {
try {
const { email, password } = req.body;
const authServiceInstance = Container.get(AuthService);
Expand Down

0 comments on commit 4b2251b

Please sign in to comment.