Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicates of shared TT #102

Merged
merged 2 commits into from
Apr 6, 2020
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
2 changes: 1 addition & 1 deletion client/src/components/layout/ShareTimeTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ const ShareTimeTable = (props) => {
<>
<div key={item._id}>
<p>TT name: {item.name}</p>
<p>{item.ownerId === null ? "Student name unavailable" : "By: " + item.ownerId.name}</p>
<p>{"By: " + item.ownerId.name}</p>
<p>Date: {item.date.substr(0, item.date.indexOf('T'))}</p>
<p>Time: {item.date.substr(item.date.indexOf('T') + 1, 9)}</p>
<Link
Expand Down
9 changes: 4 additions & 5 deletions routes/api/timetable.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const express = require("express");
const router = express.Router();
const { check, query, validationResult } = require("express-validator");

const loggedIn = require("../../middleware/auth");

const TimeTable = require("../../models/TimeTable");

router.post(
Expand Down Expand Up @@ -100,10 +98,10 @@ router.get(
res.status(422).json({ errors: errors.array() });
} else {
try {
await TimeTable.find({ isShared: true })
await TimeTable.find({ isShared: true, ownerId: {$not: { $eq: req.user.id}} })
.populate({
path: "ownerId",
match: { branch: { $in: req.query.branch }, year: req.query.year },
match: { branch: req.query.branch, year: req.query.year },
select: "name"
})
.exec((error, docs) => {
Expand All @@ -112,7 +110,8 @@ router.get(
} else {
let TTList = [];
for (let TT of docs) {
TTList.push(TT);
if(TT.ownerId !== null)
TTList.push(TT);
}
res.json(TTList);
}
Expand Down