-
Notifications
You must be signed in to change notification settings - Fork 8
Feat/assign reviewers #959
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
Changes from all commits
dc75ef0
80a9369
b2b10b1
6bb5af3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
|
|
||
| const TAG = `[ HACKER.MIDDLEWARE.js ]`; | ||
| const mongoose = require("mongoose"); | ||
| const ObjectId = mongoose.Types.ObjectId; | ||
| const { HACKER_REVIEWER_STATUS_NONE } = require("../constants/general.constant"); | ||
| const { HACKER_REVIEWER_STATUSES } = require("../constants/general.constant"); | ||
| const { HACKER_REVIEWER_NAMES } = require("../constants/general.constant"); | ||
|
|
@@ -740,6 +741,97 @@ async function updateBatchHacker(req, res, next) { | |
| next(); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Updates a hacker that is specified by req.params.id, and then sets req.email | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make this comment accurate? i think it's just copy pasted? |
||
| * to the email of the hacker, found in Account. | ||
| * Assigns reviewers to hackers in a batch process. | ||
| * @param {*} req | ||
| * @param {*} res | ||
| * @param {*} next | ||
| */ | ||
| async function assignReviewers(req, res, next) { | ||
| try { | ||
| console.log('Starting assignReviewers'); | ||
|
|
||
| // const REVIEWER_NAMES = HACKER_REVIEWER_NAMES.filter(name => name !== ''); // get all non-empty reviewer names | ||
| const REVIEWER_NAMES = req.body.names; | ||
| console.log('Reviewer names:', REVIEWER_NAMES); | ||
|
|
||
| const cutoff = new Date('2025-11-27T17:23:59.000Z'); // EDIT: set your desired cutoff date here | ||
| const cutoffObjectId = new ObjectId(Math.floor(cutoff.getTime() / 1000).toString(16) + "0000000000000000"); | ||
|
|
||
| const hackerModel = require('../models/hacker.model'); | ||
|
|
||
| // find all hackers created before the cutoff date | ||
| const hackers = await hackerModel.find({ | ||
| _id: { $lte: cutoffObjectId } | ||
| }).select('_id'); | ||
|
|
||
| console.log('Found hackers:', hackers.length); | ||
|
|
||
| // get counts | ||
| const hackerCount = hackers.length; | ||
| const revwiewerCount = REVIEWER_NAMES.length; | ||
|
|
||
| if (hackerCount === 0) { | ||
| console.log('No hackers found for reviewer assignment.'); | ||
|
|
||
| req.body = { | ||
| success: true, | ||
| assigned: 0, | ||
| reviewers: revwiewerCount, | ||
| assignments: [] | ||
| } | ||
|
|
||
| return next(); | ||
| } | ||
|
|
||
| console.log(`Found ${hackerCount} assignable reviewers.`); | ||
|
|
||
| let assignments = []; | ||
| let hackerIndex = 0; | ||
| let updatePromises = []; | ||
|
|
||
| // assign reviewers to hackers | ||
| for (const hacker of hackers) { | ||
| const assignedReviewer1 = REVIEWER_NAMES[hackerIndex % revwiewerCount]; | ||
| const assignedReviewer2 = REVIEWER_NAMES[(hackerIndex + 1) % revwiewerCount]; | ||
|
|
||
| assignments.push({ hackerId: hacker._id, reviewer: assignedReviewer1, reviewer2: assignedReviewer2 }); | ||
|
|
||
| updatePromises.push( | ||
| Services.Hacker.updateOne(hacker._id, { reviewerName: assignedReviewer1, reviewerName2: assignedReviewer2 }) | ||
| ); | ||
|
|
||
| hackerIndex++; | ||
| } | ||
|
|
||
| // exec all updates | ||
| await Promise.all(updatePromises); | ||
|
|
||
| console.log(`Completed reviewer assignment at ${new Date().toISOString()}`); | ||
| console.log(`Assignments:`, assignments); | ||
|
|
||
| req.body = { | ||
| success: true, | ||
| assigned: hackerCount, | ||
| reviewers: revwiewerCount, | ||
| assignments: assignments | ||
| } | ||
|
|
||
| return next(); | ||
|
|
||
| } catch (error) { | ||
| console.error('Error during reviewer assignment:', error); | ||
| return next({ | ||
| status: 500, | ||
| message: Constants.Error.GENERIC_500_MESSAGE, | ||
| data: { error: error } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Sets req.body.status to Accepted for next middleware, and store req.params.id as req.hackerId | ||
| * @param {{params:{id: string}, body: *}} req | ||
|
|
@@ -911,6 +1003,7 @@ module.exports = { | |
| ), | ||
| updateHacker: Middleware.Util.asyncMiddleware(updateHacker), | ||
| updateBatchHacker: Middleware.Util.asyncMiddleware(updateBatchHacker), | ||
| assignReviewers: Middleware.Util.asyncMiddleware(assignReviewers), | ||
| parseAccept: parseAccept, | ||
| parseAcceptBatch: parseAcceptBatch, | ||
| parseAcceptEmail: parseAcceptEmail, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -299,6 +299,32 @@ module.exports = { | |
| Controllers.Hacker.updatedHacker | ||
| ); | ||
|
|
||
| /** | ||
| * @api {post} /hacker/assignReviewers update a hacker's reviewer status | ||
| * @apiName patchAssignReviewers | ||
| * @apiGroup Hacker | ||
| * @apiVersion 0.0.9 | ||
| * | ||
| * @apiParam (body) None | ||
| * @apiSuccess {string} message Success message | ||
| * @apiSuccess {object} data Hacker object | ||
| * @apiSuccessExample {object} Success-Response: | ||
| * { | ||
| * "message": "Assigned reviewers to hackers", | ||
| * } | ||
| * @apiPermission Administrator | ||
| */ | ||
| hackerRouter.route("/assignReviewers").post( | ||
| // Middleware.Validator.RouteParam.idValidator, | ||
| // Middleware.Auth.ensureAuthenticated(), | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's try to enable the auth ones at least
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should also add this route to the Hackboard role "excludes"
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wait i just realized if we're running this as a script for now we can't have these on |
||
| // Middleware.Auth.ensureAuthorized([Services.Hacker.findById]), | ||
| // Middleware.Validator.Hacker.updateReviewerStatusValidator, | ||
| // Middleware.parseBody.middleware, | ||
| // Middleware.Hacker.parsePatch, | ||
| Middleware.Hacker.assignReviewers, | ||
| Controllers.Hacker.assignedReviewers | ||
| ); | ||
|
|
||
| /** | ||
| * @api {patch} /hacker/reviewerStatus/:id update a hacker's reviewer status | ||
| * @apiName patchHackerReviewerStatus | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is all commented out, can we just delete it? is there a reason to keep?