User registration completed
This commit is contained in:
@@ -1,12 +1,36 @@
|
||||
import { Router, Request, Response, NextFunction } from "express";
|
||||
import { Account } from "../models/account.model";
|
||||
import { validateString } from "../scripts/validateHelper";
|
||||
|
||||
export const account = Router()
|
||||
|
||||
account.get("/", (req: Request, res: Response, next: NextFunction)=> {
|
||||
// Request all user from the database
|
||||
account.get("/", (req: Request, res: Response, next: NextFunction) => {
|
||||
Account.findAll()
|
||||
.then(accounts => {
|
||||
res.json(accounts)
|
||||
})
|
||||
.catch(next)
|
||||
})
|
||||
|
||||
// Creating a new user
|
||||
account.post("/", (req: Request, res: Response, next: NextFunction) => {
|
||||
if (!validateString(req.body.username, 4))
|
||||
{
|
||||
res.status(400).send({ error: "Username too short!" })
|
||||
}
|
||||
else if (!validateString(req.body.password, 8))
|
||||
{
|
||||
res.status(400).send({ error: "Password too short!" })
|
||||
}
|
||||
else
|
||||
{
|
||||
Account.create(req.body)
|
||||
.then(account => {
|
||||
res.json(account)
|
||||
res.status(200).send()
|
||||
}).catch(reason => {
|
||||
res.status(400).send({ error: reason })
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -13,7 +13,6 @@ category.get("/", (req: Request, res: Response, next: NextFunction) => {
|
||||
|
||||
category.post("/", (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
console.log(req.body)
|
||||
const category = Category.create(req.body)
|
||||
res.status(201).json(category)
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user