-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'pre-STAG' into fix/partner-registrations-and-participan…
…t-filters-save
- Loading branch information
Showing
111 changed files
with
2,135 additions
and
4,627 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,112 +1,138 @@ | ||
const express = require('express') | ||
const _ = require('lodash') | ||
const { | ||
hasPermission, | ||
hasRole, | ||
} = require('../../common/middleware/permissions') | ||
const { hasToken } = require('../../common/middleware/token') | ||
const asyncHandler = require('express-async-handler') | ||
const { Auth } = require('@hackjunction/shared') | ||
|
||
const router = express.Router() | ||
const Registration = require('../registration/model') | ||
const { UserProfile } = require('../user-profile/model') | ||
const DiscordService = require('../../common/services/discord') | ||
|
||
router.route('/').get((req, res) => { | ||
return res.status(200).send('DEVTOOLS HERE') | ||
}) | ||
|
||
router.route('/anonymize-db').get(async (req, res) => { | ||
const registrations = await Registration.find({}) | ||
|
||
const updates = registrations.map(registration => { | ||
return { | ||
updateOne: { | ||
filter: { | ||
_id: registration._id, | ||
}, | ||
update: { | ||
$set: { | ||
'answers.email': `juuso.lappalainen+${Math.floor( | ||
Math.random() * 1000000 | ||
)}@hackjunction.com`, | ||
router.route('/').get( | ||
hasToken, | ||
hasRole(Auth.Roles.SUPER_ADMIN), | ||
asyncHandler(async (req, res) => { | ||
return res.status(200).send('DEVTOOLS ENABLED') | ||
}), | ||
) | ||
|
||
router.route('/anonymize-db').get( | ||
hasToken, | ||
hasRole(Auth.Roles.SUPER_ADMIN), | ||
asyncHandler(async (req, res) => { | ||
const registrations = await Registration.find({}) | ||
let anonymizeResults = [] | ||
let errors = [] | ||
const updates = registrations.map(registration => { | ||
return { | ||
updateOne: { | ||
filter: { | ||
_id: registration._id, | ||
}, | ||
}, | ||
}, | ||
} | ||
}) | ||
|
||
await Registration.bulkWrite(updates) | ||
|
||
const userProfiles = await UserProfile.find({}) | ||
|
||
const userUpdates = userProfiles.map(userProfile => { | ||
return { | ||
updateOne: { | ||
filter: { | ||
_id: userProfile._id, | ||
}, | ||
update: { | ||
$set: { | ||
email: `juuso.lappalainen+${Math.floor( | ||
Math.random() * 1000000 | ||
)}@hackjunction.com`, | ||
update: { | ||
$set: { | ||
'answers.email': `anon+${Math.floor( | ||
Math.random() * 1000000, | ||
)}@hackjunction.com`, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
}) | ||
|
||
await UserProfile.bulkWrite(userUpdates) | ||
|
||
return res.status(200).send('OK') | ||
}) | ||
|
||
// This isn't in use at the moment | ||
router.route('/test-discord').get(async (req, res) => { | ||
await DiscordService.initialize() | ||
res.status(200).send('Initialized') | ||
}) | ||
|
||
router.route('/sync-user-profiles').get(async (req, res) => { | ||
const registrations = await Registration.find({}) | ||
const userProfiles = await UserProfile.find({}) | ||
|
||
const updates = [] | ||
} | ||
}) | ||
await Registration.bulkWrite(updates) | ||
.then(result => { | ||
anonymizeResults.push(result) | ||
}) | ||
.catch(err => { | ||
errors.push(err) | ||
}) | ||
|
||
userProfiles.forEach(user => { | ||
const registration = _.find( | ||
registrations, | ||
reg => reg.user === user.userId | ||
) | ||
const userProfiles = await UserProfile.find({}) | ||
|
||
if (registration && registration.answers) { | ||
updates.push({ | ||
const userUpdates = userProfiles.map(userProfile => { | ||
return { | ||
updateOne: { | ||
filter: { | ||
userId: user.userId, | ||
_id: userProfile._id, | ||
}, | ||
update: { | ||
$set: { | ||
roles: registration.answers.roles, | ||
skills: registration.answers.skills, | ||
recruitmentOptions: | ||
registration.answers.recruitmentOptions, | ||
}, | ||
$addToSet: { | ||
registrations: { | ||
registration: registration._id, | ||
status: registration.status, | ||
event: registration.event, | ||
}, | ||
email: `anon+${Math.floor( | ||
Math.random() * 1000000, | ||
)}@hackjunction.com`, | ||
}, | ||
}, | ||
}, | ||
} | ||
}) | ||
|
||
await UserProfile.bulkWrite(userUpdates) | ||
.then(result => { | ||
anonymizeResults.push(result) | ||
}) | ||
.catch(err => { | ||
errors.push(err) | ||
}) | ||
} | ||
}) | ||
|
||
return UserProfile.bulkWrite(updates) | ||
.then(result => { | ||
return res.status(200).json(result) | ||
}) | ||
.catch(err => { | ||
return res.status(500).json(err) | ||
if (errors.length > 0) { | ||
return res.status(500).json(errors) | ||
} | ||
return res.status(200).json(anonymizeResults) | ||
}), | ||
) | ||
|
||
router.route('/sync-user-profiles').get( | ||
hasToken, | ||
hasRole(Auth.Roles.SUPER_ADMIN), | ||
asyncHandler(async (req, res) => { | ||
const registrations = await Registration.find({}) | ||
const userProfiles = await UserProfile.find({}) | ||
|
||
const updates = [] | ||
|
||
userProfiles.forEach(user => { | ||
const registration = _.find( | ||
registrations, | ||
reg => reg.user === user.userId, | ||
) | ||
|
||
if (registration && registration.answers) { | ||
updates.push({ | ||
updateOne: { | ||
filter: { | ||
userId: user.userId, | ||
}, | ||
update: { | ||
$set: { | ||
roles: registration.answers.roles, | ||
skills: registration.answers.skills, | ||
recruitmentOptions: | ||
registration.answers.recruitmentOptions, | ||
}, | ||
$addToSet: { | ||
registrations: { | ||
registration: registration._id, | ||
status: registration.status, | ||
event: registration.event, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
} | ||
}) | ||
}) | ||
return UserProfile.bulkWrite(updates) | ||
.then(result => { | ||
return res.status(200).json(result) | ||
}) | ||
.catch(err => { | ||
return res.status(500).json(err) | ||
}) | ||
}), | ||
) | ||
|
||
module.exports = router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.