mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-03-12 23:20:25 +08:00
added check name function, using requrie instead of imports
This commit is contained in:
parent
ecef2da2eb
commit
d56887bafb
1 changed files with 21 additions and 4 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue