Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit 097bde0

Browse files
Merge branch 'develop' into fix-wm-974
2 parents a0847e3 + 4c4dbc3 commit 097bde0

File tree

3 files changed

+81
-9
lines changed

3 files changed

+81
-9
lines changed

config/default.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,18 @@ module.exports = {
6868
SUBMISSION_PHASE_ID: process.env.SUBMISSION_PHASE_ID || '6950164f-3c5e-4bdc-abc8-22aaf5a1bd49',
6969
CHECKPOINT_SUBMISSION_PHASE_ID: process.env.CHECKPOINT_SUBMISSION_PHASE_ID || 'd8a2cdbe-84d1-4687-ab75-78a6a7efdcc8',
7070

71-
V5_TERMS_NDA_ID: process.env.V5_TERMS_NDA_ID || '77f558c1-56fb-427c-b974-61ea0a060ca7',
72-
LEGACY_TERMS_NDA_ID: process.env.LEGACY_TERMS_NDA_ID || 21343,
71+
V5_TERMS_NDA_ID: process.env.V5_TERMS_NDA_ID || 'e5811a7b-43d1-407a-a064-69e5015b4900',
72+
LEGACY_TERMS_NDA_ID: process.env.LEGACY_TERMS_NDA_ID || 21233,
7373

74-
V5_TERMS_STANDARD_ID: process.env.V5_TERMS_STANDARD_ID || 'e5811a7b-43d1-407a-a064-69e5015b4900',
75-
LEGACY_TERMS_STANDARD_ID: process.env.LEGACY_TERMS_STANDARD_ID || 21233,
74+
V5_TERMS_STANDARD_ID: process.env.V5_TERMS_STANDARD_ID || '317cd8f9-d66c-4f2a-8774-63c612d99cd4',
75+
LEGACY_TERMS_STANDARD_ID: process.env.LEGACY_TERMS_STANDARD_ID || 21305,
7676

7777
LEGACY_SUBMITTER_ROLE_ID: process.env.LEGACY_SUBMITTER_ROLE_ID || 1,
7878

7979
COPILOT_PAYMENT_TYPE: process.env.COPILOT_PAYMENT_TYPE || 'copilot',
8080

81+
COPILOT_ROLE_ID: process.env.COPILOT_ROLE_ID || 'cfe12b3f-2a24-4639-9d8b-ec86726f76bd',
82+
8183
// V5 Term UUID
8284
SYNC_V5_TERM_UUID: process.env.SYNC_V5_TERM_UUID || '317cd8f9-d66c-4f2a-8774-63c612d99cd4',
8385
SYNC_V5_WRITE_ENABLED: process.env.SYNC_V5_WRITE_ENABLED === 'true' || false

src/services/ProcessorService.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ async function getGroup (v5GroupId, m2mToken) {
3232
* @param {String} m2mToken token for accessing the API
3333
*/
3434
async function getV5Terms (v5TermsId, m2mToken) {
35+
logger.debug(`Get V5 Terms: ${config.V5_TERMS_API_URL}/${v5TermsId}`)
3536
const response = await helper.getRequest(`${config.V5_TERMS_API_URL}/${v5TermsId}`, m2mToken)
37+
logger.debug(`Get v5 terms response: ${JSON.stringify(response.body)}`)
3638
return response.body
3739
}
3840

@@ -68,13 +70,20 @@ async function associateChallengeGroups (toBeAdded = [], toBeDeleted = [], legac
6870
* @param {String|Number} legacyChallengeId the legacy challenge ID
6971
*/
7072
async function associateChallengeTerms (v5Terms, legacyChallengeId, createdBy, updatedBy) {
73+
// logger.debug(`v5Terms Terms Array: ${JSON.stringify(v5Terms)}`)
7174
const legacyTermsArray = await termsService.getTermsForChallenge(legacyChallengeId)
75+
// logger.debug(`Legacy Terms Array: ${JSON.stringify(legacyTermsArray)}`)
7276
const nda = _.find(v5Terms, e => e.id === config.V5_TERMS_NDA_ID)
7377
const legacyNDA = _.find(legacyTermsArray, e => _.toNumber(e.id) === _.toNumber(config.LEGACY_TERMS_NDA_ID))
7478

7579
const standardTerms = _.find(v5Terms, e => e.id === config.V5_TERMS_STANDARD_ID)
7680
const legacyStandardTerms = _.find(legacyTermsArray, e => _.toNumber(e.id) === _.toNumber(config.LEGACY_TERMS_STANDARD_ID))
7781

82+
// logger.debug(`NDA: ${config.V5_TERMS_NDA_ID} - ${JSON.stringify(nda)}`)
83+
// logger.debug(`Standard Terms: ${config.V5_TERMS_STANDARD_ID} - ${JSON.stringify(standardTerms)}`)
84+
// logger.debug(`Legacy NDA: ${JSON.stringify(legacyNDA)}`)
85+
// logger.debug(`Legacy Standard Terms: ${JSON.stringify(legacyStandardTerms)}`)
86+
7887
const m2mToken = await helper.getM2MToken()
7988
if (standardTerms && standardTerms.id && !legacyStandardTerms) {
8089
logger.debug('Associate Challenge Terms - v5 Standard Terms exist, not in legacy. Adding to Legacy.')
@@ -99,16 +108,27 @@ async function associateChallengeTerms (v5Terms, legacyChallengeId, createdBy, u
99108

100109
/**
101110
* Set the copilot payment on legacy
111+
* @param {String} challengeId the V5 challenge ID
102112
* @param {Number|String} legacyChallengeId the legacy challenge ID
103113
* @param {Array} prizeSets the prizeSets array
104114
* @param {String} createdBy the created by handle
105115
* @param {String} updatedBy the updated by handle
116+
* @param {String} m2mToken the m2m token
106117
*/
107-
async function setCopilotPayment (legacyChallengeId, prizeSets = [], createdBy, updatedBy) {
118+
async function setCopilotPayment (challengeId, legacyChallengeId, prizeSets = [], createdBy, updatedBy, m2mToken) {
108119
try {
109120
const copilotPayment = _.get(_.find(prizeSets, p => p.type === config.COPILOT_PAYMENT_TYPE), 'prizes[0].value', null)
110-
logger.debug(`Setting Copilot Payment: ${copilotPayment} for legacyId ${legacyChallengeId}`)
111-
await copilotPaymentService.setCopilotPayment(legacyChallengeId, copilotPayment, createdBy, updatedBy)
121+
if (copilotPayment) {
122+
logger.debug('Fetching challenge copilot...')
123+
const res = await helper.getRequest(`${config.V5_RESOURCES_API_URL}?challengeId=${challengeId}&roleId=${config.COPILOT_ROLE_ID}`, m2mToken)
124+
const [copilotResource] = res.body
125+
if (!copilotResource) {
126+
logger.warn(`Copilot does not exist for challenge ${challengeId} (legacy: ${legacyChallengeId})`)
127+
return
128+
}
129+
logger.debug(`Setting Copilot Payment: ${copilotPayment} for legacyId ${legacyChallengeId} for copilot ${copilotResource.memberId}`)
130+
await copilotPaymentService.setCopilotPayment(legacyChallengeId, copilotPayment, createdBy, updatedBy)
131+
}
112132
} catch (e) {
113133
logger.error('Failed to set the copilot payment!')
114134
logger.debug(e)
@@ -392,7 +412,7 @@ async function processCreate (message) {
392412
await helper.forceV4ESFeeder(newChallenge.body.result.content.id)
393413
await associateChallengeGroups(saveDraftContestDTO.groupsToBeAdded, saveDraftContestDTO.groupsToBeDeleted, newChallenge.body.result.content.id)
394414
// await associateChallengeTerms(saveDraftContestDTO.termsToBeAdded, saveDraftContestDTO.termsToBeRemoved, newChallenge.body.result.content.id)
395-
await setCopilotPayment(newChallenge.body.result.content.id, _.get(message, 'payload.prizeSets'), _.get(message, 'payload.createdBy'), _.get(message, 'payload.updatedBy'))
415+
await setCopilotPayment(challengeUuid, newChallenge.body.result.content.id, _.get(message, 'payload.prizeSets'), _.get(message, 'payload.createdBy'), _.get(message, 'payload.updatedBy'), m2mToken)
396416
await helper.patchRequest(`${config.V5_CHALLENGE_API_URL}/${challengeUuid}`, {
397417
legacy: {
398418
...message.payload.legacy,
@@ -516,7 +536,7 @@ async function processUpdate (message) {
516536
await helper.putRequest(`${config.V4_CHALLENGE_API_URL}/${message.payload.legacyId}`, { param: _.omit(saveDraftContestDTO, ['groupsToBeAdded', 'groupsToBeDeleted']) }, m2mToken)
517537
await associateChallengeGroups(saveDraftContestDTO.groupsToBeAdded, saveDraftContestDTO.groupsToBeDeleted, message.payload.legacyId)
518538
await associateChallengeTerms(message.payload.terms, message.payload.legacyId, _.get(message, 'payload.createdBy'), _.get(message, 'payload.updatedBy'))
519-
await setCopilotPayment(message.payload.legacyId, _.get(message, 'payload.prizeSets'), _.get(message, 'payload.createdBy'), _.get(message, 'payload.updatedBy'))
539+
await setCopilotPayment(message.payload.id, message.payload.legacyId, _.get(message, 'payload.prizeSets'), _.get(message, 'payload.createdBy'), _.get(message, 'payload.updatedBy'), m2mToken)
520540

521541
// Update metadata in IFX
522542
if (message.payload.metadata && message.payload.metadata.length > 0) {

src/services/copilotPaymentService.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const helper = require('../common/helper')
55

66
const COPILOT_PAYMENT_PROJECT_INFO_ID = 49
77
const COPILOT_PAYMENT_RESOURCE_INFO_ID = 7
8+
const COPILOT_PAYMENT_TYPE_ID = 15
89
const COPILOT_RESOURCE_ROLE_ID = 14
910

1011
const QUERY_GET_COPILOT_RESOURCE_FOR_CHALLENGE = `SELECT limit 1 resource_id as resourceid FROM resource WHERE project_id = %d AND resource_role_id = ${COPILOT_RESOURCE_ROLE_ID}`
@@ -32,6 +33,10 @@ const QUERY_DELETE_COPILOT_PAYMENT = `DELETE FROM project_info WHERE project_inf
3233
const QUERY_UPDATE_COPILOT_RESOURCE_PAYMENT = `UPDATE resource_info SET value = ?, modify_user = ?, modify_date = CURRENT WHERE resource_id = ? AND resource_info_type_id = ${COPILOT_PAYMENT_RESOURCE_INFO_ID}`
3334
// const QUERY_DELETE_COPILOT_RESOURCE_PAYMENT = `DELETE FROM resource_info WHERE resource_id = ? AND resource_info_type_id = ${COPILOT_PAYMENT_RESOURCE_INFO_ID}`
3435

36+
const QUERY_SELECT_PAYMENT_TYPE = `SELECT value FROM resource_info WHERE resource_info_type_id = ${COPILOT_PAYMENT_TYPE_ID} AND resource_id = %d`
37+
const QUERY_INSERT_PAYMENT_TYPE = `INSERT INTO resource_info (resource_id, resource_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (?, "${COPILOT_PAYMENT_TYPE_ID}", ?, ?, CURRENT, ?, CURRENT)`
38+
const QUERY_UPDATE_PAYMENT_TYPE = `UPDATE resource_info SET value = ?, modify_user = ?, modify_date = CURRENT WHERE resource_id = ? AND resource_info_type_id = ${COPILOT_PAYMENT_TYPE_ID}`
39+
3540
/**
3641
* Prepare Informix statement
3742
* @param {Object} connection the Informix connection
@@ -58,6 +63,14 @@ async function setCopilotPayment (challengeLegacyId, amount, createdBy, updatedB
5863
const copilotResourceId = await getCopilotResourceId(connection, challengeLegacyId)
5964
const copilotPayment = await getCopilotPayment(connection, challengeLegacyId)
6065
if (amount != null && amount >= 0) {
66+
// Make sure the payment type is set to manual
67+
// TODO: Figure out why data is not saved in IFX even when there are no errors
68+
// const paymentType = await getCopilotPaymentType(connection, copilotResourceId)
69+
// if (!paymentType) {
70+
// await createCopilotPaymentType(connection, copilotResourceId, 'TRUE', updatedBy || createdBy)
71+
// } else if (_.toLower(_.toString(paymentType.value)) !== 'true') {
72+
// await updateCopilotPaymentType(connection, copilotResourceId, 'TRUE', updatedBy || createdBy)
73+
// }
6174
if (copilotPayment) {
6275
logger.debug(`Copilot payment exists, updating: ${challengeLegacyId}`)
6376
return updateCopilotPayment(connection, copilotResourceId, challengeLegacyId, amount, updatedBy)
@@ -78,6 +91,43 @@ async function setCopilotPayment (challengeLegacyId, amount, createdBy, updatedB
7891
}
7992
}
8093

94+
/**
95+
* Gets the copilot payment type for a legacyId
96+
* @param {Object} connection the connection
97+
* @param {Number} resourceId the resource ID
98+
*/
99+
async function getCopilotPaymentType (connection, resourceId) {
100+
const result = await connection.queryAsync(util.format(QUERY_SELECT_PAYMENT_TYPE, resourceId))
101+
logger.debug(`Result: ${JSON.stringify(result, null, 2)}`)
102+
return _.get(result, '[0]', null)
103+
}
104+
105+
/**
106+
* Create the copilot payment type record
107+
* @param {Object} connection the connection
108+
* @param {Number} resourceId the resource ID
109+
* @param {Boolean} value the value
110+
* @param {String} createdBy the create user handle
111+
*/
112+
async function createCopilotPaymentType (connection, resourceId, value, createdBy) {
113+
const query = await prepare(connection, QUERY_INSERT_PAYMENT_TYPE)
114+
logger.debug(`Create Copilot Payment Type Values: ${[resourceId, value, createdBy, createdBy]}`)
115+
await query.executeAsync([resourceId, value, createdBy, createdBy])
116+
}
117+
118+
/**
119+
* Update the copilot payment type record
120+
* @param {Object} connection the connection
121+
* @param {Number} resourceId the resource ID
122+
* @param {Boolean} value the value
123+
* @param {String} createdBy the create user handle
124+
*/
125+
async function updateCopilotPaymentType (connection, resourceId, value, createdBy) {
126+
const query = await prepare(connection, QUERY_UPDATE_PAYMENT_TYPE)
127+
logger.debug(`Update Copilot Payment Type Values: ${[value, createdBy, resourceId]}`)
128+
await query.executeAsync([value, createdBy, resourceId])
129+
}
130+
81131
/**
82132
* Gets the copilot payment for a legacyId
83133
* @param {Object} connection

0 commit comments

Comments
 (0)