Skip to content

Commit

Permalink
fixed import issues
Browse files Browse the repository at this point in the history
  • Loading branch information
phucd5 committed Oct 28, 2023
1 parent 096011f commit 975f74f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
13 changes: 10 additions & 3 deletions server/controllers/auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import UserModel from "../models/User.js";
import { handleServerError, handleSuccess } from "../utils/handlers.js";
import {
handleServerError,
handleSuccess,
handleNotFound,
handleBadRequest,
} from "../utils/handlers.js";
import bcrypt from "bcrypt";

export const register = async (req, res) => {
Expand Down Expand Up @@ -28,10 +33,12 @@ export const login = async (req, res) => {
try {
const { inputLogin, password } = req.body;

const user = await User.findOne({
$or: [{ email: inputLogin }, { username: inputLogin }],
const user = await UserModel.findOne({
$or: [{ email: inputLogin }, { userName: inputLogin }],
});

console.log(inputLogin);

if (!user) {
return handleNotFound(res, "User not found");
}
Expand Down
37 changes: 20 additions & 17 deletions server/controllers/reply.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import ReplyModel from "../models/Reply.js";
import { handleServerError, handleSuccess } from '../utils/handlers.js';
import { handleServerError, handleSuccess } from "../utils/handlers.js";

// Reply to a message
export const reply_to_message = async (req, res) => {
try {
const reply = await ReplyModel.create({
parent_message: req.body.message_id,
content: req.body.content,
}).exec();
handleSuccess(res, reply);
} catch (err) {
handleServerError(res, err);
}
try {
const reply = await ReplyModel.create({
parent_message: req.body.message_id,
content: req.body.content,
}).exec();
handleSuccess(res, reply);
} catch (err) {
handleServerError(res, err);
}
};

// changes value of like field in ReplySchema to true.
export const like_reply = async (req, res) => {
try {
const reply = await ReplyModel.findByIdAndUpdate(req.body._id, {likes: true}, {new: true}).exec();
handleSuccess(res, reply);
} catch (err) {
handleServerError(res, err);
}
try {
const reply = await ReplyModel.findByIdAndUpdate(
req.body._id,
{ likes: true },
{ new: true }
).exec();
handleSuccess(res, reply);
} catch (err) {
handleServerError(res, err);
}
};

7 changes: 6 additions & 1 deletion server/controllers/user.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import UserModel from "../models/User.js";
import { handleBadRequest } from "../utils/handlers.js";
import {
handleServerError,
handleSuccess,
handleNotFound,
handleBadRequest,
} from "../utils/handlers.js";

export const getUserById = async (req, res) => {
try {
Expand Down

0 comments on commit 975f74f

Please sign in to comment.