Commit 7c83f8b0 authored by Pavel Mishakov's avatar Pavel Mishakov

some fixes

parent cd4ef015
...@@ -48,10 +48,8 @@ export class UserController { ...@@ -48,10 +48,8 @@ export class UserController {
} }
public checkToken = async (req: Request, res: Response): Promise<void> => { public checkToken = async (req: Request, res: Response): Promise<void> => {
const user = await User.findOne({token: req.get('Authorization')}) const user = await User.findOne({token: req.get('Authorization')})
console.log(user)
if(!user) { if(!user) {
res.status(200).send({ res.status(200).send({
status: EStatuses.OK, status: EStatuses.OK,
......
...@@ -12,7 +12,6 @@ import { UserController } from './controllers/user' ...@@ -12,7 +12,6 @@ import { UserController } from './controllers/user'
import { mongo } from './repository/mongo' import { mongo } from './repository/mongo'
dotenv.config() dotenv.config()
class App { class App {
private app: Express private app: Express
constructor() { constructor() {
......
...@@ -244,9 +244,18 @@ export class Mongo implements IDataBase { ...@@ -244,9 +244,18 @@ export class Mongo implements IDataBase {
public createUser = async (userDto: IUserDto): Promise<IResponse<IUser | undefined>> => { public createUser = async (userDto: IUserDto): Promise<IResponse<IUser | undefined>> => {
try { try {
const exists = await User.exists({username: userDto.username})
if (exists) {
return {
status: EStatuses.NOT_OK,
result: undefined,
message: '[ERROR] User already registered'
}
}
const user = new User(userDto) const user = new User(userDto)
// @ts-ignore // @ts-ignore
user.generateToken() user.generateToken()
// user.token = '1234'
const data = await user.save() const data = await user.save()
return { return {
status: EStatuses.OK, status: EStatuses.OK,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment