From d56887bafb802d3d0d8513c9817ed16a18eb7f04 Mon Sep 17 00:00:00 2001 From: Miodec Date: Wed, 16 Jun 2021 00:45:49 +0100 Subject: [PATCH] added check name function, using requrie instead of imports --- backend/api/controllers/user.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/backend/api/controllers/user.js b/backend/api/controllers/user.js index 69ac0422c..95785c753 100644 --- a/backend/api/controllers/user.js +++ b/backend/api/controllers/user.js @@ -1,6 +1,11 @@ -import UsersDAO from "../../dao/usersDAO"; -import BotDAO from "../../dao/botDAO"; -import { isUsernameValid } from "../../handlers/validation"; +const UsersDAO = require("../../dao/user"); +const BotDAO = require("../../dao/bot"); +const { isUsernameValid } = require("../../handlers/validation"); + + +// import UsersDAO from "../../dao/user"; +// import BotDAO from "../../dao/bot"; +// import { isUsernameValid } from "../../handlers/validation"; class UserController { static async createNewUser(req, res, next) { @@ -16,7 +21,7 @@ class UserController { static async updateName(req, res, next) { try { const { name } = req.body; - if (!isUsernameValid(name)) return next("Username unavailable!"); + if (!isUsernameValid(name)) return next("Username invalid!"); await UsersDAO.updateName(); return res.sendStatus(200); } catch (e) { @@ -24,6 +29,18 @@ class UserController { } } + static async checkName(req, res, next) { + try { + const { name } = req.body; + if (!isUsernameValid(name)) return next("Username invalid"); + const available = await UsersDAO.isNameAvailable(name); + if(!available) return next("Username unavailable"); + return res.sendStatus(200); + } catch (e) { + return next(e); + } + } + static async getUser(req, res, next) { try { const { uid } = req.decodedToken;