Last active
June 28, 2022 18:40
-
-
Save IvsonEmidio/5a1dbfcc743274d68020f98a0bfbddf4 to your computer and use it in GitHub Desktop.
Zeus Controller Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Request, Response } from "express"; | |
import { pool } from "database"; | |
export class UserController { | |
public async create(req: Request, res: Response) { | |
const { name, password, email } = req.body; | |
if (!name) { | |
return res.status(400).json({ message: "Field name cannot be empty" }); | |
} | |
if (!password) { | |
return res | |
.status(400) | |
.json({ message: "Field password cannot be empty" }); | |
} | |
if (!email) { | |
return res.status(400).json({ message: "Field email cannot be empty" }); | |
} | |
const addUser = await pool.query(`INSERT...`); | |
if (addUser) { | |
return res.status(201).json({ message: "User created successfully" }); | |
} else { | |
return res.status(500).json({ message: "Internal server error" }); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment