Skip to content

Commit

Permalink
Resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrpengdev committed Feb 20, 2024
2 parents f0eb025 + ee2aaa5 commit 63f1145
Show file tree
Hide file tree
Showing 78 changed files with 842 additions and 833 deletions.
21 changes: 15 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@types/node": "^8.10.61",
"eslint": "^8.47.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-import-resolver-babel-module": "^5.3.1",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-jsx-a11y": "^6.7.1",
Expand Down
5 changes: 1 addition & 4 deletions src/controllers/actionItemController.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const actionItemController = function (ActionItem) {
_actionItem.assignedTo = req.body.assignedTo;
_actionItem.createdBy = req.body.requestor.requestorId;


_actionItem.save()
.then((result) => {
notificationhelper.notificationcreated(requestorId, assignedTo, _actionItem.description);
Expand All @@ -58,7 +57,6 @@ const actionItemController = function (ActionItem) {
const deleteactionItem = async function (req, res) {
const actionItemId = mongoose.Types.ObjectId(req.params.actionItemId);


const _actionItem = await ActionItem.findById(actionItemId)
.catch((error) => {
res.status(400).send(error);
Expand Down Expand Up @@ -109,10 +107,9 @@ const actionItemController = function (ActionItem) {

_actionItem.save()
.then(res.status(200).send('Saved'))
.catch(error => res.status(400).send(error));
.catch((error) => res.status(400).send(error));
};


return {
getactionItem,
postactionItem,
Expand Down
5 changes: 2 additions & 3 deletions src/controllers/badgeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const escapeRegex = require('../utilities/escapeRegex');
const cache = require('../utilities/nodeCache')();
const logger = require('../startup/logger');


const badgeController = function (Badge) {
/**
* getAllBadges handles badges retrieval.
Expand Down Expand Up @@ -40,7 +39,7 @@ const badgeController = function (Badge) {
cache.setCache('allBadges', results);
res.status(200).send(results);
})
.catch(error => res.status(500).send(error));
.catch((error) => res.status(500).send(error));
};

/**
Expand Down Expand Up @@ -155,7 +154,7 @@ const badgeController = function (Badge) {
}
res.status(201).send(results);
})
.catch(errors => res.status(500).send(errors));
.catch((errors) => res.status(500).send(errors));
});
};

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/bmdashboard/bmConsumableController.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const bmConsumableController = function (BuildingConsumable) {
.then((result) => {
res.status(200).send(result);
})
.catch(error => res.status(500).send(error));
.catch((error) => res.status(500).send(error));
} catch (err) {
res.json(err);
}
Expand Down
17 changes: 8 additions & 9 deletions src/controllers/bmdashboard/bmInventoryTypeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ function bmInventoryTypeController(InvType, MatType, ConsType, ReusType, ToolTyp
MatType
.find()
.exec()
.then(result => res.status(200).send(result))
.catch(error => res.status(500).send(error));
.then((result) => res.status(200).send(result))
.catch((error) => res.status(500).send(error));
} catch (err) {
res.json(err);
}
Expand All @@ -26,8 +26,8 @@ function bmInventoryTypeController(InvType, MatType, ConsType, ReusType, ToolTyp
ToolType
.find()
.exec()
.then(result => res.status(200).send(result))
.catch(error => res.status(500).send(error));
.then((result) => res.status(200).send(result))
.catch((error) => res.status(500).send(error));
} catch (err) {
res.json(err);
}
Expand Down Expand Up @@ -55,7 +55,6 @@ function bmInventoryTypeController(InvType, MatType, ConsType, ReusType, ToolTyp
}
};


async function addMaterialType(req, res) {
const {
name,
Expand Down Expand Up @@ -118,7 +117,7 @@ function bmInventoryTypeController(InvType, MatType, ConsType, ReusType, ToolTyp
});
}
})
.catch(error => res.status(500).send(error));
.catch((error) => res.status(500).send(error));
} catch (error) {
res.status(500).send(error);
}
Expand All @@ -142,8 +141,8 @@ function bmInventoryTypeController(InvType, MatType, ConsType, ReusType, ToolTyp
SelectedType
.find()
.exec()
.then(result => res.status(200).send(result))
.catch(error => res.status(500).send(error));
.then((result) => res.status(200).send(result))
.catch((error) => res.status(500).send(error));
} catch (err) {
res.json(err);
}
Expand Down Expand Up @@ -182,7 +181,7 @@ function bmInventoryTypeController(InvType, MatType, ConsType, ReusType, ToolTyp
});
}
})
.catch(error => res.status(500).send(error));
.catch((error) => res.status(500).send(error));
} catch (error) {
res.status(500).send(error);
}
Expand Down
14 changes: 7 additions & 7 deletions src/controllers/bmdashboard/bmMaterialsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const bmMaterialsController = function (BuildingMaterial) {
},
])
.exec()
.then(results => res.status(200).send(results))
.catch(error => res.status(500).send(error));
.then((results) => res.status(200).send(results))
.catch((error) => res.status(500).send(error));
} catch (err) {
res.json(err);
}
Expand Down Expand Up @@ -74,7 +74,7 @@ const bmMaterialsController = function (BuildingMaterial) {
BuildingMaterial
.create(newDoc)
.then(() => res.status(201).send())
.catch(error => res.status(500).send(error));
.catch((error) => res.status(500).send(error));
return;
}
BuildingMaterial
Expand All @@ -84,7 +84,7 @@ const bmMaterialsController = function (BuildingMaterial) {
)
.exec()
.then(() => res.status(201).send())
.catch(error => res.status(500).send(error));
.catch((error) => res.status(500).send(error));
} catch (error) {
res.status(500).send(error);
}
Expand Down Expand Up @@ -132,7 +132,7 @@ const bmMaterialsController = function (BuildingMaterial) {

)
.then((results) => { res.status(200).send(results); })
.catch(error => res.status(500).send({ message: error }));
.catch((error) => res.status(500).send({ message: error }));
}
};

Expand Down Expand Up @@ -183,7 +183,7 @@ const bmMaterialsController = function (BuildingMaterial) {
res.status(500).send('Stock quantities submitted seems to be invalid');
return;
}
const updatePromises = updateRecordsToBeAdded.map(updateItem => BuildingMaterial.updateOne(
const updatePromises = updateRecordsToBeAdded.map((updateItem) => BuildingMaterial.updateOne(
{ _id: updateItem.updateId },
{
$set: updateItem.set,
Expand All @@ -194,7 +194,7 @@ const bmMaterialsController = function (BuildingMaterial) {
.then((results) => {
res.status(200).send({ result: `Successfully posted log for ${results.length} Material records.` });
})
.catch(error => res.status(500).send(error));
.catch((error) => res.status(500).send(error));
} catch (err) {
res.json(err);
}
Expand Down
29 changes: 14 additions & 15 deletions src/controllers/bmdashboard/bmNewLessonController.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ const bmNewLessonController = function (BuildingNewLesson) {
BuildingNewLesson
.find()
.populate()
.then(result => res.status(200).send(result))
.catch(error => res.status(500).send(error));
.then((result) => res.status(200).send(result))
.catch((error) => res.status(500).send(error));
} catch (err) {
res.json(err);
}
};
const bmPostLessonList = async (req, res) => {
try {
const newLesson = BuildingNewLesson.create(req.body)
.then(result => res.status(201).send(result))
.catch(error => res.status(500).send(error));
.then((result) => res.status(201).send(result))
.catch((error) => res.status(500).send(error));
} catch (err) {
res.json(err);
}
Expand Down Expand Up @@ -47,7 +47,7 @@ const bmNewLessonController = function (BuildingNewLesson) {
// Extract only allowed fields (content, tag, relatedProject and title)
const allowedFields = ['content', 'tags', 'relatedProject', 'title', 'allowedRoles', 'files'];
const filteredUpdateData = Object.keys(updateData)
.filter(key => allowedFields.includes(key))
.filter((key) => allowedFields.includes(key))
.reduce((obj, key) => {
obj[key] = updateData[key];
return obj;
Expand Down Expand Up @@ -87,7 +87,6 @@ const bmNewLessonController = function (BuildingNewLesson) {
// return;
// }


try {
const deletedLesson = await BuildingNewLesson.findByIdAndDelete(lessonId);

Expand All @@ -104,38 +103,38 @@ const bmNewLessonController = function (BuildingNewLesson) {
const likeLesson = async (req, res) => {
const { lessonId } = req.params;
const { userId } = req.body;

try {
const existingLike = await Like.findOne({ user: userId, lesson: lessonId });

if (existingLike) {
// User has already liked the lesson, handle unlike
await Like.findByIdAndDelete(existingLike._id);
await BuildingNewLesson.findByIdAndUpdate(lessonId, { $pull: { likes: existingLike._id } });

// Decrement total likes count
await BuildingNewLesson.findByIdAndUpdate(lessonId, { $inc: { totalLikes: -1 } });

return res.status(200).json({ status: 'success', message: 'Lesson unliked successfully' });
}

// User has not liked the lesson, handle like
const newLike = new Like({ user: userId, lesson: lessonId });
await newLike.save();

await BuildingNewLesson.findByIdAndUpdate(lessonId, { $push: { likes: newLike._id } });

// Increment total likes count
await BuildingNewLesson.findByIdAndUpdate(lessonId, { $inc: { totalLikes: 1 } });

return res.status(200).json({ status: 'success', message: 'Lesson liked successfully' });
} catch (error) {
console.error('Error liking/unliking lesson:', error);
return res.status(500).json({ status: 'error', message: 'Error liking/unliking lesson' });
}
};
return {
bmPostLessonList, bmGetLessonList, bmGetSingleLesson, bmDeleteSingleLesson, bmEditSingleLesson, likeLesson
bmPostLessonList, bmGetLessonList, bmGetSingleLesson, bmDeleteSingleLesson, bmEditSingleLesson, likeLesson,
};
};

Expand Down
6 changes: 3 additions & 3 deletions src/controllers/bmdashboard/bmProjectController.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const bmMProjectController = function (BuildingProject) {
});
res.status(200).send(results);
})
.catch(error => res.status(500).send(error));
.catch((error) => res.status(500).send(error));
} catch (err) {
res.status(500).send(err);
}
Expand All @@ -105,7 +105,7 @@ const bmMProjectController = function (BuildingProject) {
},
])
.exec()
.then(project => res.status(200).send(project))
.then((project) => res.status(200).send(project))
// TODO: uncomment this block to execute the auth check
// authenticate request by comparing userId param with buildingManager id field
// Note: _id has type object and must be converted to string
Expand All @@ -117,7 +117,7 @@ const bmMProjectController = function (BuildingProject) {
// }
// return res.status(200).send(project);
// })
.catch(error => res.status(500).send(error));
.catch((error) => res.status(500).send(error));
} catch (err) {
res.json(err);
}
Expand Down
8 changes: 4 additions & 4 deletions src/controllers/bmdashboard/bmToolController.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ const bmToolController = (BuildingTool) => {
},
])
.exec()
.then(tool => res.status(200).send(tool))
.catch(error => res.status(500).send(error));
.then((tool) => res.status(200).send(tool))
.catch((error) => res.status(500).send(error));
} catch (err) {
res.json(err);
}
Expand Down Expand Up @@ -84,7 +84,7 @@ const bmToolController = (BuildingTool) => {
BuildingTool
.create(newDoc)
.then(() => res.status(201).send())
.catch(error => res.status(500).send(error));
.catch((error) => res.status(500).send(error));
return;
}

Expand All @@ -95,7 +95,7 @@ const bmToolController = (BuildingTool) => {
)
.exec()
.then(() => res.status(201).send())
.catch(error => res.status(500).send(error));
.catch((error) => res.status(500).send(error));
} catch (error) {
res.status(500).send(error);
}
Expand Down
Loading

0 comments on commit 63f1145

Please sign in to comment.