Skip to content

Commit 83c79be

Browse files
committed
Added a feature for the approval to be able to pass in an object during the Joint approval process
1 parent 5aae371 commit 83c79be

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/controller/review-object.controller/review-object.controller.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ async function approveReviewObject (req, res, next) {
4343
const repo = req.ctx.repositories.getReviewObjectRepository()
4444
const userRepo = req.ctx.repositories.getBaseUserRepository()
4545
const UUID = req.params.uuid
46+
const body = req.body
4647
const session = await mongoose.startSession()
4748
let value
4849

4950
try {
5051
session.startTransaction()
5152
const requestingUserUUID = await userRepo.getUserUUID(req.ctx.user, req.ctx.org, { session })
5253

53-
value = await repo.approveReviewOrgObject(UUID, requestingUserUUID, { session })
54+
value = await repo.approveReviewOrgObject(UUID, requestingUserUUID, { session }, body)
5455
await session.commitTransaction()
5556
} catch (updateErr) {
5657
await session.abortTransaction()

src/repositories/reviewObjectRepository.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const ReviewObjectModel = require('../model/reviewobject')
22
const BaseRepository = require('./baseRepository')
33
const BaseOrgRepository = require('./baseOrgRepository')
44
const uuid = require('uuid')
5+
const _ = require('lodash')
56

67
class ReviewObjectRepository extends BaseRepository {
78
async findOneByOrgShortName (orgShortName, options = {}) {
@@ -115,7 +116,7 @@ class ReviewObjectRepository extends BaseRepository {
115116
return result.toObject()
116117
}
117118

118-
async approveReviewOrgObject (UUID, requestingUserUUID, options = {}) {
119+
async approveReviewOrgObject (UUID, requestingUserUUID, options = {}, newReviewData) {
119120
console.log('Approving review object with UUID:', UUID)
120121
const reviewObject = await this.findOneByUUID(UUID, options)
121122
if (!reviewObject) {
@@ -129,7 +130,13 @@ class ReviewObjectRepository extends BaseRepository {
129130
}
130131

131132
// We need to trigger the org to update
132-
await baseOrgRepository.updateOrgFull(org.short_name, reviewObject.new_review_data, options, false, requestingUserUUID, false, true)
133+
let dataToUpdate
134+
if (newReviewData && Object.keys(newReviewData).length) {
135+
dataToUpdate = _.merge(org.toObject(), newReviewData)
136+
} else {
137+
dataToUpdate = reviewObject.new_review_data
138+
}
139+
await baseOrgRepository.updateOrgFull(org.short_name, dataToUpdate, options, false, requestingUserUUID, false, true)
133140

134141
reviewObject.status = 'approved'
135142

test/integration-tests/registry-org/registryOrgWithJointReviewTest.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,24 +147,25 @@ describe('Testing Joint approval', () => {
147147
expect(res.body.hard_quota).to.equal(10000)
148148
})
149149
})
150-
it('Secretariat can approve the ORG review', async function () {
150+
it('Secretariat can approve the ORG review with body parameter', async function () {
151+
const newBody = { short_name: 'final_non_secretariat_org', hard_quota: 20000 }
151152
await chai.request(app)
152153
.put(`/api/review/org/${reviewUUID}/approve`)
153154
.set(secretariatHeaders)
155+
.send(newBody)
154156
.then((res) => {
155157
expect(res).to.have.status(200)
156158
expect(res.body.status).to.equal('approved')
157159
})
158-
})
159-
it('Check to see if the org was fully updated', async () => {
160+
// Verify that the org was updated with the new body values
160161
await chai.request(app)
161162
.get(`/api/registryOrg/${orgUUID}`)
162163
.set(secretariatHeaders)
163164
.then((res, err) => {
164165
expect(err).to.be.undefined
165166
expect(res).to.have.status(200)
166-
expect(res.body.short_name).to.equal('new_non_secretariat_org')
167-
expect(res.body.hard_quota).to.equal(10000)
167+
expect(res.body.short_name).to.equal('final_non_secretariat_org')
168+
expect(res.body.hard_quota).to.equal(20000)
168169
})
169170
})
170171
})

0 commit comments

Comments
 (0)