Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ 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

try {
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()
Expand Down
20 changes: 14 additions & 6 deletions src/repositories/reviewObjectRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})
Expand Down Expand Up @@ -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 () => {
Expand Down
Loading