Skip to content

Commit

Permalink
Fix eslint problems
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Makaha <rafael.makaha@gmail.com>
Co-authored-by: João Vítor Morandi <joao.lemos4000@gmail.com>
Co-authored-by: Antonio Ruan <ruanmoura13@outlook.com>
  • Loading branch information
3 people committed Dec 14, 2020
1 parent 67af50a commit c8b242b
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 33 deletions.
4 changes: 3 additions & 1 deletion src/controller/CommentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class CommentController {
.send({ error: `Error while deleting topic.\n${err}` });
}
}

static async likeComment(req, res) {
try {
const user = await User.findById(req.userId);
Expand Down Expand Up @@ -104,6 +105,7 @@ class CommentController {
return res.status(400).send({ error: `Error while commenting.${err}` });
}
}

static async dislikeComment(req, res) {
try {
const comment = await Comment.findById(req.params.commentId);
Expand All @@ -121,7 +123,7 @@ class CommentController {
if (index > -1) {
comment.likes.splice(index, 1);
}

comment.save();
await Like.findByIdAndRemove(like._id);
const topicTrue = await Topic.findById(comment.topic).populate([
Expand Down
14 changes: 7 additions & 7 deletions src/controller/MyPlantsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MyPlantsController {
try {
const user = await User.findById(req.userId);
const plant = await Plant.findById(req.params.plantId);

const result = myPlantSchema.validate({ nickname: req.body.nickname });
if (result.error) {
return res.status(400).send(result.error);
Expand All @@ -52,7 +52,7 @@ class MyPlantsController {
});
await user.myPlants.push(myPlant._id);
await user.save();

return res.status(200).send({ myPlant });
} catch (err) {
return res
Expand All @@ -65,7 +65,7 @@ class MyPlantsController {
try {
const user = await User.findById(req.params.userId);
const index = user.myPlants.indexOf(req.params.myPlantId);

if (index > -1) {
const myPlant = await MyPlant.findById(req.params.myPlantId);
return res.send({
Expand All @@ -87,14 +87,14 @@ class MyPlantsController {
static async updatePlant(req, res) {
try {
const newNick = req.body;

const result = myPlantSchema.validate(newNick);
if (result.error) {
return res
.status(400)
.send({ error: `Error while editing plant. ${result.error}` });
}

const myPlant = await MyPlant.findOneAndUpdate(
{ _id: req.params.myPlantId },
newNick,
Expand All @@ -103,7 +103,7 @@ class MyPlantsController {
new: true,
}
);

const newUser = await User.findById(myPlant.user).populate([
{ path: 'topics', populate: 'plants' },
{ path: 'myPlants', populate: 'plant' },
Expand Down Expand Up @@ -134,7 +134,7 @@ class MyPlantsController {
{ path: 'myPlants', populate: 'plant' },
{ path: 'favorites', populate: 'plant' },
]);

return res.send(newUser);
} catch (err) {
return res
Expand Down
8 changes: 4 additions & 4 deletions src/controller/PlantController.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ class PlantController {
// Listagem de Todas as plantas
static async fetchAll(req, res) {
try {
const plants = await Plant.find().sort({ "topics": -1 }).populate([
{ path: 'topics' },
]);
return res.send( plants );
const plants = await Plant.find()
.sort({ topics: -1 })
.populate([{ path: 'topics' }]);
return res.send(plants);
} catch (err) {
return res.status(400).send({ error: 'Loading plants failed' });
}
Expand Down
34 changes: 17 additions & 17 deletions src/controller/TopicController.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ class TopicController {
try {
const user = await User.findById(req.userId);
const plant = await Plant.findById(req.params.plantId);

const result = topicSchema.validate(req.body);

if (result.error) {
return res
.status(400)
.send({ error: `Error while creating topic. ${result.error}` });
}

const topic = await Topic.create({
...req.body,
user: req.userId,
plant: req.params.plantId,
});

await topic.save();

user.topics.push(topic);
await user.save();

plant.topics.push(topic);
await plant.save();

return res.send({ topic });
} catch (err) {
return res
Expand All @@ -43,7 +43,7 @@ class TopicController {
static async updateTopic(req, res) {
try {
const topic = await Topic.findById(req.params.topicId);

const newData = req.body;

if (!('title' in newData)) {
Expand All @@ -60,7 +60,7 @@ class TopicController {
.status(400)
.send({ error: `Error while creating topic. ${result.error}` });
}

const topicNew = await Topic.findOneAndUpdate(
{ _id: req.params.topicId },
newData,
Expand All @@ -86,20 +86,20 @@ class TopicController {
const topic = await Topic.findById(req.params.topicId);
const user = await User.findById(topic.user);
const plant = await Plant.findById(topic.plant);

const indexAtUser = user.topics.indexOf(req.params.topicId);
const indexAtPlant = plant.topics.indexOf(req.params.topicId);

if (indexAtUser > -1) {
user.topics.splice(indexAtUser, 1);
}
if (indexAtPlant > -1) {
plant.topics.splice(indexAtPlant, 1);
}

user.save();
plant.save();

await Topic.findByIdAndRemove(req.params.topicId, {
useFindAndModify: false,
});
Expand Down Expand Up @@ -133,15 +133,15 @@ class TopicController {
{ path: 'user' },
{ path: 'plant' },
]);

return res.send(topic);
} catch (err) {
return res
.status(400)
.send({ error: `Error while find topic id.\n${err}` });
}
}

static async likeTopic(req, res) {
try {
const user = await User.findById(req.userId);
Expand Down Expand Up @@ -170,12 +170,13 @@ class TopicController {
return res.send(topictrue);
}
console.log(topic.likes.length);

return res.send(topic);
} catch (err) {
return res.status(400).send({ error: `Error while commenting.${err}` });
}
}

static async dislikeTopic(req, res) {
try {
const topic = await Topic.findById(req.params.topicId).populate([
Expand Down Expand Up @@ -205,7 +206,6 @@ class TopicController {
}
}


static async refreshTopicContents(res, topicId) {
const topicTrue = await Topic.findById(topicId).populate(
defaultTopicPopulate
Expand Down
1 change: 0 additions & 1 deletion src/models/Plant.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const mongoose = require('mongoose');
const User = require('./User');

const PlantSchema = new mongoose.Schema({
scientificName: {
Expand Down
2 changes: 1 addition & 1 deletion src/models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const userSchema = new Schema({
type: String,
required: true,
},
photo:{
photo: {
type: String,
},
email: {
Expand Down
1 change: 0 additions & 1 deletion src/routes/commentRoutes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const express = require('express');
const { auth } = require('../lib/auth');
const CommentController = require('../controller/CommentController');
const LikeController = require('../controller/LikeController');

const router = new express.Router();

Expand Down
1 change: 0 additions & 1 deletion src/routes/topicRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const express = require('express');
const { auth } = require('../lib/auth');
const TopicController = require('../controller/TopicController');


const router = new express.Router();
router.post('/create/:plantId', auth, TopicController.createTopic);
router.put('/update/:topicId', TopicController.updateTopic);
Expand Down

0 comments on commit c8b242b

Please sign in to comment.