Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/controllers/activityController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const Activity = require('../models/activity');
const LessonPlan = require('../models/lessonPlan');
const Subject = require('../models/subject');
const Atom = require('../models/atom');

const activityController = function () {
// Get all activities
const getActivities = async (req, res) => {
Expand Down
37 changes: 28 additions & 9 deletions src/controllers/bmdashboard/bmIssueController.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,37 @@ const bmIssueController = function (BuildingIssue, injuryIssue) {
query.projectId = { $in: filteredProjectIds };
}

const issues = await BuildingIssue.find(query)
.select('issueTitle issueDate projectId')
.populate({
path: 'projectId',
select: 'projectName name',
})
let issues = await BuildingIssue.find(query)
.select('issueTitle issueDate _id')
.populate('projectId')
.lean();

const grouped = buildGroupedIssues(issues);
const response = buildLongestOpenResponse(grouped);
issues = issues.map((issue) => {
const durationInMonths = getDurationOpenMonths(issue.issueDate);
return {
issueName: issue.issueTitle && issue.issueTitle.length > 0 ? issue.issueTitle[0] : null,
durationInMonths,
issueId: issue._id.toString(),
projectId: issue.projectId?._id?.toString() || issue.projectId?.toString(),
projectName: issue.projectId?.name || null,
};
});

const sortedIssues = issues
.sort((a, b) => b.durationInMonths - a.durationInMonths)
.map(({ issueName, durationInMonths, issueId, projectId, projectName }) => ({
issueName,
durationOpen: durationInMonths,
issueId,
projectId,
projectName,
}));

console.log(
`[getLongestOpenIssues] Total issues found: ${issues.length}, Returning: ${sortedIssues.length} issues`,
);

res.json(response);
res.json(sortedIssues);
} catch (error) {
res.status(500).json({ message: 'Error fetching longest open issues' });
}
Expand Down
1 change: 0 additions & 1 deletion src/helpers/overviewReportHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,6 @@ const overviewReportHelper = function () {
}

async function getTasksStats(startDate, endDate, comparisonStartDate, comparisonEndDate) {

if (comparisonStartDate && comparisonEndDate) {
const taskStats = await Task.aggregate([
{
Expand Down
1 change: 0 additions & 1 deletion src/routes/kitchenandinventory/KIInventoryRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ const router = function () {
};

module.exports = router;

6 changes: 3 additions & 3 deletions src/scripts/seedKIInventoryItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,12 @@ async function seed() {

// Quick stats summary
const total = inserted.length;
const critical = inserted.filter(i => i.presentQuantity <= i.reorderAt * 0.5).length;
const critical = inserted.filter((i) => i.presentQuantity <= i.reorderAt * 0.5).length;
const low = inserted.filter(
i => i.presentQuantity <= i.reorderAt && i.presentQuantity > i.reorderAt * 0.5,
(i) => i.presentQuantity <= i.reorderAt && i.presentQuantity > i.reorderAt * 0.5,
).length;
const preserved = inserted.filter(
i =>
(i) =>
i.category === 'INGREDIENT' &&
new Date(i.expiryDate) >= new Date(Date.now() + 365 * 24 * 60 * 60 * 1000),
).length;
Expand Down
Loading