SHARE
TWEET

Untitled

a guest Oct 21st, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {Request, Response} from "express"
  2. import { AuthService } from "../services/Auth"
  3.  
  4. const authService = new AuthService()
  5.  
  6. /**
  7.  *
  8.  * @param req
  9.  * @param res
  10.  */
  11. export async function register(req: Request, res: Response) {
  12.     const { email, password, firstName, lastName } = req.body
  13.     try {
  14.         const result = await authService.register(firstName, lastName, email, password)
  15.         console.log(`User: ${email} has been created`)
  16.  
  17.         res.json({
  18.             message: "User created",
  19.             data: result
  20.         })
  21.     } catch(err) {
  22.         console.log(err)
  23.         if(String(err).includes("Username taken")) {
  24.             return res.status(400).json({
  25.                 error: true,
  26.                 message: "Email is taken"
  27.             })
  28.         }
  29.         res.status(500).json({
  30.             error: true,
  31.             message: "An internal server error has occurred"
  32.         })
  33.     }
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top