From 83c79bebc02134c864df0f5a0cd830e4cb579812 Mon Sep 17 00:00:00 2001 From: david-rocca Date: Tue, 9 Dec 2025 13:03:30 -0500 Subject: [PATCH 1/3] Added a feature for the approval to be able to pass in an object during the Joint approval process --- .../review-object.controller.js | 3 ++- src/repositories/reviewObjectRepository.js | 11 +++++++++-- .../registry-org/registryOrgWithJointReviewTest.js | 11 ++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) 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..bb426b2ee 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,7 +130,13 @@ 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' diff --git a/test/integration-tests/registry-org/registryOrgWithJointReviewTest.js b/test/integration-tests/registry-org/registryOrgWithJointReviewTest.js index 9e6e66ada..1ad56f6c5 100644 --- a/test/integration-tests/registry-org/registryOrgWithJointReviewTest.js +++ b/test/integration-tests/registry-org/registryOrgWithJointReviewTest.js @@ -147,24 +147,25 @@ 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) }) }) }) From d75327d3e99356ec6232af03797770cb97ab686e Mon Sep 17 00:00:00 2001 From: david-rocca Date: Tue, 9 Dec 2025 14:14:23 -0500 Subject: [PATCH 2/3] deleting the review object after it is written to the org --- src/repositories/reviewObjectRepository.js | 9 +++++---- .../registry-org/registryOrgWithJointReviewTest.js | 2 -- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/repositories/reviewObjectRepository.js b/src/repositories/reviewObjectRepository.js index bb426b2ee..799e21312 100644 --- a/src/repositories/reviewObjectRepository.js +++ b/src/repositories/reviewObjectRepository.js @@ -138,11 +138,12 @@ class ReviewObjectRepository extends BaseRepository { } 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) + return updatedOrg ? updatedOrg.toObject() : null } } diff --git a/test/integration-tests/registry-org/registryOrgWithJointReviewTest.js b/test/integration-tests/registry-org/registryOrgWithJointReviewTest.js index 1ad56f6c5..0145a125b 100644 --- a/test/integration-tests/registry-org/registryOrgWithJointReviewTest.js +++ b/test/integration-tests/registry-org/registryOrgWithJointReviewTest.js @@ -155,7 +155,6 @@ describe('Testing Joint approval', () => { .send(newBody) .then((res) => { expect(res).to.have.status(200) - expect(res.body.status).to.equal('approved') }) // Verify that the org was updated with the new body values await chai.request(app) @@ -311,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 () => { From 00a4bdf0cc248861970d4a536574736d65d2ac72 Mon Sep 17 00:00:00 2001 From: Chris Berger Date: Tue, 9 Dec 2025 15:11:36 -0500 Subject: [PATCH 3/3] Missing session options --- src/repositories/reviewObjectRepository.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/repositories/reviewObjectRepository.js b/src/repositories/reviewObjectRepository.js index 799e21312..048038722 100644 --- a/src/repositories/reviewObjectRepository.js +++ b/src/repositories/reviewObjectRepository.js @@ -142,7 +142,7 @@ class ReviewObjectRepository extends BaseRepository { await this.deleteReviewObjectByUUID(UUID, options) // Return the updated organization - const updatedOrg = await baseOrgRepository.findOneByUUID(reviewObject.target_object_uuid) + const updatedOrg = await baseOrgRepository.findOneByUUID(reviewObject.target_object_uuid, options) return updatedOrg ? updatedOrg.toObject() : null } }