-
Notifications
You must be signed in to change notification settings - Fork 109
Resolves #1537 - #1539: First pass at the review collection, with some endpoints for testing #1549
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const router = require('express').Router() | ||
const controller = require('./review-object.controller') | ||
const mw = require('../../middleware/middleware') | ||
|
||
router.get('/review/org/:identifier', mw.useRegistry(), mw.validateUser, mw.onlySecretariat, controller.getReviewObjectByOrgIdentifier) | ||
router.get('/review/orgs', mw.useRegistry(), mw.validateUser, mw.onlySecretariat, controller.getAllReviewObjects) | ||
|
||
router.put('/review/org/:uuid', mw.useRegistry(), mw.validateUser, mw.onlySecretariat, controller.updateReviewObjectByReviewUUID) | ||
|
||
router.post('/review/org/', mw.useRegistry(), mw.validateUser, mw.onlySecretariat, controller.createReviewObject) | ||
|
||
|
||
module.exports = router |
80 changes: 80 additions & 0 deletions
80
src/controller/review-object.controller/review-object.controller.js
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
|
||
const validateUUID = require('uuid').validate | ||
async function getReviewObjectByOrgIdentifier (req, res, next) { | ||
const repo = req.ctx.repositories.getReviewObjectRepository() | ||
const identifier = req.params.identifier | ||
const identifierIsUUID = validateUUID(identifier) | ||
if (!identifier) { | ||
return res.status(400).json({ message: 'Missing identifier parameter' }) | ||
} | ||
let value | ||
// We may want this to be something different, but for now we are just testing | ||
if (identifierIsUUID) { | ||
value = await repo.getOrgReviewObjectByOrgUUID(identifier) | ||
} else { | ||
value = await repo.getOrgReviewObjectByOrgShortname(identifier) | ||
} | ||
return res.status(200).json(value) | ||
} | ||
|
||
async function getAllReviewObjects (req, res, next) { | ||
const repo = req.ctx.repositories.getReviewObjectRepository() | ||
const value = await repo.getAllReviewObjects() | ||
return res.status(200).json(value) | ||
} | ||
|
||
async function updateReviewObjectByReviewUUID (req, res, next) { | ||
const repo = req.ctx.repositories.getReviewObjectRepository() | ||
const UUID = req.params.uuid | ||
const orgRepo = req.ctx.repositories.getBaseOrgRepository() | ||
const body = req.body | ||
|
||
const result = orgRepo.validateOrg(body.new_review_data) | ||
if (!result.isValid) { | ||
return res.status(400).json({ message: 'Invalid new_review_data', errors: result.errors }) | ||
} | ||
|
||
const value = await repo.updateReviewOrgObject(body, UUID) | ||
|
||
if (!value) { | ||
return res.status(404).json({ message: `No review object found with UUID ${UUID}` }) | ||
} | ||
return res.status(200).json(value) | ||
} | ||
|
||
async function createReviewObject (req, res, next) { | ||
const repo = req.ctx.repositories.getReviewObjectRepository() | ||
const orgRepo = req.ctx.repositories.getBaseOrgRepository() | ||
const body = req.body | ||
|
||
if (body.uuid) { | ||
return res.status(400).json({ message: 'Do not pass in a uuid key when creating a review object' }) | ||
} | ||
|
||
if (!body.target_object_uuid) { | ||
return res.status(400).json({ message: 'Missing required field target_object_uuid' }) | ||
} | ||
|
||
if (!body.new_review_data) { | ||
return res.status(400).json({ message: 'Missing required field new_review_data' }) | ||
} | ||
|
||
// Validate the data going into "new_review_data" | ||
const result = orgRepo.validateOrg(body.new_review_data) | ||
if (!result.isValid) { | ||
return res.status(400).json({ message: 'Invalid new_review_data', errors: result.errors }) | ||
} | ||
|
||
const value = await repo.createReviewOrgObject(body) | ||
|
||
if (!value) { | ||
return res.status(500).json({ message: 'Failed to create review object' }) | ||
} | ||
return res.status(200).json(value) | ||
} | ||
module.exports = { | ||
getReviewObjectByOrgIdentifier, | ||
getAllReviewObjects, | ||
updateReviewObjectByReviewUUID, | ||
createReviewObject | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const mongoose = require('mongoose') | ||
const aggregatePaginate = require('mongoose-aggregate-paginate-v2') | ||
const MongoPaging = require('mongo-cursor-pagination') | ||
|
||
const schema = { | ||
uuid: String, | ||
target_object_uuid: String, | ||
status: String, | ||
new_review_data: Object // This should be a object containing the new org data in the format of the base org model or one of its descriminators (e.g. CNAOrg, ADPOrg) | ||
} | ||
|
||
const ReviewOrgSchema = new mongoose.Schema(schema, { collection: 'ReviewObject', timestamps: { createdAt: 'created', updatedAt: 'last_updated' } }) | ||
|
||
ReviewOrgSchema.plugin(aggregatePaginate) | ||
|
||
// Cursor pagination | ||
ReviewOrgSchema.plugin(MongoPaging.mongoosePlugin) | ||
const ReviewObject = mongoose.model('ReviewObject', ReviewOrgSchema) | ||
module.exports = ReviewObject |
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
const ReviewObjectModel = require('../model/reviewobject') | ||
const BaseRepository = require('./baseRepository') | ||
const BaseOrgRepository = require('./baseOrgRepository') | ||
const uuid = require('uuid') | ||
|
||
class ReviewObjectRepository extends BaseRepository { | ||
async findOneByOrgShortName (orgShortName, options = {}) { | ||
const baseOrgRepository = new BaseOrgRepository() | ||
const org = await baseOrgRepository.findOneByShortName(orgShortName) | ||
if (!org) { | ||
throw new Error(`No organization found with short name ${orgShortName}`) | ||
} | ||
const reviewObject = await ReviewObjectModel.find({ target_object_uuid: org.UUID }, null, options) | ||
|
||
return reviewObject || null | ||
} | ||
|
||
async findOneByUUID (UUID, options = {}) { | ||
const reviewObject = await ReviewObjectModel.findOne({ uuid: UUID }, null, options) | ||
return reviewObject || null | ||
} | ||
|
||
async getAllReviewObjects (options = {}) { | ||
const reviewObjects = await ReviewObjectModel.find({}, null, options) | ||
return reviewObjects || [] | ||
} | ||
|
||
async deleteReviewObjectByUUID (UUID, options = {}) { | ||
const result = await ReviewObjectModel.deleteOne({ uuid: UUID }, options) | ||
return result.deletedCount | ||
} | ||
|
||
async getOrgReviewObjectByOrgShortname (orgShortName, options = {}) { | ||
const baseOrgRepository = new BaseOrgRepository() | ||
const org = await baseOrgRepository.findOneByShortName(orgShortName) | ||
if (!org) { | ||
throw new Error(`No organization found with short name ${orgShortName}`) | ||
} | ||
const reviewObject = await ReviewObjectModel.findOne({ target_object_uuid: org.UUID }, null, options) | ||
|
||
return reviewObject || null | ||
} | ||
|
||
async getOrgReviewObjectByOrgUUID (orgUUID, options = {}) { | ||
const baseOrgRepository = new BaseOrgRepository() | ||
const org = await baseOrgRepository.findOneByUUID(orgUUID) | ||
if (!org) { | ||
throw new Error(`No organization found with UUID ${orgUUID}`) | ||
} | ||
const reviewObject = await ReviewObjectModel.findOne({ target_object_uuid: org.UUID }, null, options) | ||
|
||
return reviewObject || null | ||
} | ||
|
||
async createReviewOrgObject (body, options = {}) { | ||
console.log('Creating review object for organization:', body.target_object_uuid) | ||
body.uuid = uuid.v4() | ||
const reviewObject = new ReviewObjectModel(body) | ||
const result = await reviewObject.save(options) | ||
return result.toObject() | ||
} | ||
|
||
async updateReviewOrgObject (body, UUID, options = {}) { | ||
console.log('Updating review object with UUID:', UUID) | ||
const reviewObject = await this.findOneByUUID(UUID, options) | ||
|
||
// For each item waiting for approval, for testing we are going to just do shortname | ||
reviewObject.new_review_data.short_name = body.new_review_data.short_name || reviewObject.new_review_data.short_name | ||
|
||
const result = await reviewObject.save(options) | ||
return result.toObject() | ||
} | ||
} | ||
|
||
module.exports = ReviewObjectRepository |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.