diff --git a/src/controller/review-object.controller/review-object.controller.js b/src/controller/review-object.controller/review-object.controller.js index 44717797e..a54ff6d66 100644 --- a/src/controller/review-object.controller/review-object.controller.js +++ b/src/controller/review-object.controller/review-object.controller.js @@ -43,6 +43,7 @@ async function approveReviewObject (req, res, next) { const repo = req.ctx.repositories.getReviewObjectRepository() const userRepo = req.ctx.repositories.getBaseUserRepository() const UUID = req.params.uuid + const body = req.body const session = await mongoose.startSession() let value @@ -50,7 +51,7 @@ async function approveReviewObject (req, res, next) { session.startTransaction() const requestingUserUUID = await userRepo.getUserUUID(req.ctx.user, req.ctx.org, { session }) - value = await repo.approveReviewOrgObject(UUID, requestingUserUUID, { session }) + value = await repo.approveReviewOrgObject(UUID, requestingUserUUID, { session }, body) await session.commitTransaction() } catch (updateErr) { await session.abortTransaction() diff --git a/src/repositories/reviewObjectRepository.js b/src/repositories/reviewObjectRepository.js index 1a3c24ef5..048038722 100644 --- a/src/repositories/reviewObjectRepository.js +++ b/src/repositories/reviewObjectRepository.js @@ -2,6 +2,7 @@ const ReviewObjectModel = require('../model/reviewobject') const BaseRepository = require('./baseRepository') const BaseOrgRepository = require('./baseOrgRepository') const uuid = require('uuid') +const _ = require('lodash') class ReviewObjectRepository extends BaseRepository { async findOneByOrgShortName (orgShortName, options = {}) { @@ -115,7 +116,7 @@ class ReviewObjectRepository extends BaseRepository { return result.toObject() } - async approveReviewOrgObject (UUID, requestingUserUUID, options = {}) { + async approveReviewOrgObject (UUID, requestingUserUUID, options = {}, newReviewData) { console.log('Approving review object with UUID:', UUID) const reviewObject = await this.findOneByUUID(UUID, options) if (!reviewObject) { @@ -129,13 +130,20 @@ class ReviewObjectRepository extends BaseRepository { } // We need to trigger the org to update - await baseOrgRepository.updateOrgFull(org.short_name, reviewObject.new_review_data, options, false, requestingUserUUID, false, true) + let dataToUpdate + if (newReviewData && Object.keys(newReviewData).length) { + dataToUpdate = _.merge(org.toObject(), newReviewData) + } else { + dataToUpdate = reviewObject.new_review_data + } + await baseOrgRepository.updateOrgFull(org.short_name, dataToUpdate, options, false, requestingUserUUID, false, true) - reviewObject.status = 'approved' + // Delete the review object after approval + await this.deleteReviewObjectByUUID(UUID, options) - await reviewObject.save({ options }) - const result = reviewObject.toObject() - return result + // Return the updated organization + const updatedOrg = await baseOrgRepository.findOneByUUID(reviewObject.target_object_uuid, options) + return updatedOrg ? updatedOrg.toObject() : null } } diff --git a/test/integration-tests/registry-org/registryOrgWithJointReviewTest.js b/test/integration-tests/registry-org/registryOrgWithJointReviewTest.js index 9e6e66ada..0145a125b 100644 --- a/test/integration-tests/registry-org/registryOrgWithJointReviewTest.js +++ b/test/integration-tests/registry-org/registryOrgWithJointReviewTest.js @@ -147,24 +147,24 @@ describe('Testing Joint approval', () => { expect(res.body.hard_quota).to.equal(10000) }) }) - it('Secretariat can approve the ORG review', async function () { + it('Secretariat can approve the ORG review with body parameter', async function () { + const newBody = { short_name: 'final_non_secretariat_org', hard_quota: 20000 } await chai.request(app) .put(`/api/review/org/${reviewUUID}/approve`) .set(secretariatHeaders) + .send(newBody) .then((res) => { expect(res).to.have.status(200) - expect(res.body.status).to.equal('approved') }) - }) - it('Check to see if the org was fully updated', async () => { + // Verify that the org was updated with the new body values await chai.request(app) .get(`/api/registryOrg/${orgUUID}`) .set(secretariatHeaders) .then((res, err) => { expect(err).to.be.undefined expect(res).to.have.status(200) - expect(res.body.short_name).to.equal('new_non_secretariat_org') - expect(res.body.hard_quota).to.equal(10000) + expect(res.body.short_name).to.equal('final_non_secretariat_org') + expect(res.body.hard_quota).to.equal(20000) }) }) }) @@ -310,7 +310,6 @@ describe('Testing Joint approval', () => { .set(secretariatHeaders) .then((res) => { expect(res).to.have.status(200) - expect(res.body.status).to.equal('approved') }) }) it('Check to see if the org was fully updated', async () => {