const router = require('express-promise-router')() const parseJSON = require('body-parser').json() const db = require('../db') const {validationResult} = require('express-validator') const validate = require('./middleware/validators') const registerValidation = [validate.emailRestrictions, validate.passwordRestrictions, validate.bothPasswordsMatch, validate.checkEmailNotUsed] router.post('/', parseJSON, registerValidation, async (req, res) => { const errors = validationResult(req) if(!errors.isEmpty()) return res.status(422).json({errors: errors.array()}) const user = await db.user.register( req.body.email, req.body.password ) // TODO: Create session res.json(user) }) module.exports = router;