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

Add TA role #272

Merged
merged 1 commit into from
Feb 10, 2023
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
11 changes: 11 additions & 0 deletions migrations/20230210083201-edit-nb-log-role-enum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.sequelize.query("ALTER TYPE enum_nb_logs_role ADD VALUE 'TA'")
},

down: async (queryInterface, Sequelize) => {
}

};
11 changes: 11 additions & 0 deletions migrations/20230210083349-edit-spotlight-log-role-enum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.sequelize.query("ALTER TYPE enum_spotlight_logs_role ADD VALUE 'TA'")
},

down: async (queryInterface, Sequelize) => {
}

};
17 changes: 17 additions & 0 deletions migrations/20230210194915-insert-nb-configs-11.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.bulkInsert('nb_configs', [
{
name: 'SHOW_INDICATOR_FOR_TA_COMMENT',
value: 'true',
description: 'Enable/Disable indicator for TA comment in the list (sidebar)'
},
])
},

down: async (queryInterface, Sequelize) => {
}
};

8 changes: 6 additions & 2 deletions models/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ module.exports = function (models) {
)
);
},
createAnnotation: function (location, head, instructors, sessionUserId, follows) {
createAnnotation: function (location, head, instructors, tas, sessionUserId, follows) {
let annotation = {}
let range = location.HtmlLocation;

Expand All @@ -166,6 +166,7 @@ module.exports = function (models) {
annotation.author = head.Author.id;
annotation.authorName = head.Author.first_name + " " + head.Author.last_name;
annotation.instructor = instructors.has(head.Author.id);
annotation.ta = tas.has(head.Author.id);
annotation.html = head.content;
annotation.hashtags = head.Tags.map(tag => tag.tag_type_id);
annotation.people = head.TaggedUsers.map(userTag => userTag.id);
Expand All @@ -175,6 +176,7 @@ module.exports = function (models) {
annotation.spotlight = head.Spotlight
annotation.media = head.Media
annotation.replyRequestedByMe = head.ReplyRequesters.reduce((bool, user) => bool || user.id == sessionUserId, false);
annotation.replyRequestedByTA = head.ReplyRequesters.reduce((bool, user) => bool || tas.has(user.id), false);
annotation.replyRequestCount = head.ReplyRequesters.length;
annotation.starredByMe = head.Starrers.reduce((bool, user) => bool || user.id == sessionUserId, false);
annotation.starCount = head.Starrers.length;
Expand All @@ -191,7 +193,7 @@ module.exports = function (models) {

return annotation
},
createAnnotationFromThread: function (htmlLocation, head, seenUsers, instructors, sessionUserId, follows) {
createAnnotationFromThread: function (htmlLocation, head, seenUsers, instructors, tas, sessionUserId, follows) {
let annotation = {}
let range = htmlLocation;

Expand All @@ -208,6 +210,7 @@ module.exports = function (models) {
annotation.author = head.Author.id;
annotation.authorName = head.Author.first_name + " " + head.Author.last_name;
annotation.instructor = instructors.has(head.Author.id);
annotation.ta = tas.has(head.Author.id);
annotation.html = head.content;
annotation.hashtags = head.Tags.map(tag => tag.tag_type_id);
annotation.people = head.TaggedUsers.map(userTag => userTag.id);
Expand All @@ -217,6 +220,7 @@ module.exports = function (models) {
annotation.spotlight = head.Spotlight
annotation.media = head.Media;
annotation.replyRequestedByMe = sessionUserId ? head.ReplyRequesters.reduce((bool, user) => bool || user.id == sessionUserId, false) : undefined;
annotation.replyRequestedByTA = sessionUserId ? head.ReplyRequesters.reduce((bool, user) => bool || tas.has(user.id), false) : undefined;
annotation.replyRequestCount = head.ReplyRequesters.length;
annotation.starredByMe = sessionUserId ? head.Starrers.reduce((bool, user) => bool || user.id == sessionUserId, false) : undefined;
annotation.starCount = head.Starrers.length;
Expand Down
64 changes: 42 additions & 22 deletions routes/annotations.js

Large diffs are not rendered by default.

86 changes: 81 additions & 5 deletions routes/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ router.post('/edit', (req, res) => {

/**
* Get all classes for which current user is an instructor.
* @name GET/api/classes/create
* @name GET/api/classes/instructor
*/
router.get('/instructor', (req, res) => {
User.findByPk(req.user.id).then((user) =>
Expand All @@ -58,6 +58,18 @@ router.get('/instructor', (req, res) => {
});
});

/**
* Get all classes for which current user is an ta.
* @name GET/api/classes/ta
*/
router.get('/ta', (req, res) => {
User.findByPk(req.user.id).then((user) =>
user.getTAClasses()
).then((classes) => {
res.status(200).json(classes);
});
});

/**
* Get all classes for which current user is a student.
* @name GET/api/classes/student
Expand All @@ -78,7 +90,7 @@ router.get('/student', (req, res) => {

/**
* Get all instructors for a given class
* @name GET/api/classes/studentList/:id
* @name GET/api/classes/instructorList/:id
* @param id: id of the class
*/
router.get('/instructorList/:id', (req, res) => {
Expand All @@ -94,6 +106,19 @@ router.get('/instructorList/:id', (req, res) => {
});
});

/**
* Get all tas for a given class
* @name GET/api/classes/taList/:id
* @param id: id of the class
*/
router.get('/taList/:id', (req, res) => {
Class.findByPk(req.params.id,
{ include: [{ association: 'ClassTAs', attributes: ['id', 'username', 'first_name', 'last_name', 'email'] }] })
.then((nb_class) => {
res.status(200).json(nb_class.ClassTAs);
});
});

/**
* Get all students for a given class
* @name GET/api/classes/studentList/:id
Expand All @@ -114,6 +139,9 @@ router.get('/studentList/:id', (req, res) => {
association: 'Instructors',
required: true,
where: { id: req.user.id }
},
{
association: 'ClassTAs',
}
]
})
Expand Down Expand Up @@ -158,14 +186,13 @@ router.get('/studentList/:id', (req, res) => {

router.get('/usersList/:id', (req, res) => {
Class.findByPk(req.params.id,
{ include: [{ association: 'Instructors', attributes: ['id', 'username', 'first_name', 'last_name', 'email']}, {association: 'GlobalSection',
{ include: [{ association: 'Instructors', attributes: ['id', 'username', 'first_name', 'last_name', 'email']}, { association: 'ClassTAs', attributes: ['id', 'username', 'first_name', 'last_name', 'email']}, {association: 'GlobalSection',
include: [{
association: 'MemberStudents',
attributes: ['id', 'username', 'first_name', 'last_name', 'email']
}]}]})
.then((nb_class) => {
res.status(200).json({instructors: nb_class.Instructors, students: nb_class.GlobalSection.MemberStudents});

res.status(200).json({instructors: nb_class.Instructors, tas: nb_class.ClassTAs, students: nb_class.GlobalSection.MemberStudents});
});
});

Expand Down Expand Up @@ -214,6 +241,53 @@ router.delete('/instructor/:courseid/:userid', (req, res) => {
});
});

/**
* Add an ta to a given class
* @name POST/api/classes/ta/:id
* @param id: id of the class
*/
router.post('/ta/:id', (req, res) => {
Class.findByPk(req.params.id, {
include: [
{ association: 'Instructors', required: true, where: { id: req.user.id } },
{ association: 'ClassTAs' }]
})
.then(nb_class => {
if (!nb_class) {
res.status(401).json(null);
}
else {
User.findByPk(req.body.id).then(user =>
nb_class.addClassTAs(user)
).then(() => res.status(200).json(null));
}
});
});

/**
* Remove an ta from a given class
* @name DELETE/api/classes/ta/:courseid/:userid
* @param courseid: id of the class
* @param userid: id of the user to remove
*/
router.delete('/ta/:courseid/:userid', (req, res) => {
Class.findByPk(req.params.courseid, {
include: [
{ association: 'Instructors', required: true, where: { id: req.user.id } },
{ association: 'ClassTAs' }]
})
.then(nb_class => {
if (!nb_class) {
res.status(401).json(null);
}
else {
User.findByPk(req.params.userid).then(user =>
nb_class.removeClassTAs(user)
).then(() => res.status(200).json(null));
}
});
});

/**
* Add a student to a given class
* @name POST/api/classes/student/:id
Expand Down Expand Up @@ -261,6 +335,8 @@ router.post('/user/:id', (req, res) => {
}).then((user) => {
if (req.body.role === "instructor") {
nb_class.addInstructor(user)
} else if (req.body.role === "ta") {
nb_class.addClassTAs(user)
} else if (req.body.role === "student") {
utils.addStudentToSection(nb_class, user, req.body.section)
}
Expand Down
Loading