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

Effort hours #45

Merged
merged 2 commits into from
Feb 15, 2021
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
96 changes: 96 additions & 0 deletions src/scripts/migrations/010-fix-effort-hours.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* Populate the following properties on the challenges:
* - metadata.effortHoursEstimate
* - metadata.effortHoursOffshore
* - metadata.effortHoursOnshore
*/
global.Promise = require('bluebird')

const config = require('config')
const _ = require('lodash')
const logger = require('../../util/logger')
const challengeService = require('../../services/challengeService')
const { getESClient } = require('../../util/helper')
const { getEffortHoursFromIfx } = require('../../services/challengeInformixService')

const mapping = {
effortHoursEstimate: 88,
effortHoursOffshore: 89,
effortHoursOnshore: 90
}

const migrationFunction = {
run: async () => {
const perPage = config.get('MIGRATION_SCRIPT_BATCH_SIZE')
let finish = false
let page = 0
let batch = 1

while (!finish) {
logger.info(`Batch-${batch} - Loading challenges`)
const challenges = await getChallengesMissingData(page, perPage)
logger.info(`Found ${challenges.length} challenges`)
if (challenges.length > 0) {
for (const challenge of challenges) {
challenge.legacy.migration = 10
const legacyData = await getEffortHoursFromIfx(challenge.legacyId)
if (legacyData.length > 0) {
_.keys(mapping, (key) => {
const v5Index = _.findIndex(challenge.metadata, meta => meta.name === key)
const legacyIndex = _.findIndex(legacyData, entry => entry.project_info_type_id === mapping[key])
if (v5Index === -1) {
challenge.metadata.push({
name: key,
value: legacyData[legacyIndex].value
})
} else {
challenge.metadata[v5Index].value = legacyData[legacyIndex].value
}
})
await challengeService.save(challenge)
}
}
} else {
finish = true
}
page++
batch++
}
}
}

async function getChallengesMissingData (page = 0, perPage = 10) {
const esQuery = {
index: config.get('ES.CHALLENGE_ES_INDEX'),
type: config.get('ES.CHALLENGE_ES_TYPE'),
size: perPage,
from: page * perPage,
body: {
query: {
range: {
'legacy.migration': {
lt: 10
}
}
}
}
}
// logger.debug(`ES Query ${JSON.stringify(esQuery)}`)
// Search with constructed query
let docs
try {
docs = await getESClient().search(esQuery)
} catch (e) {
// Catch error when the ES is fresh and has no data
docs = {
hits: {
total: 0,
hits: []
}
}
}
// Extract data from hits
return _.map(docs.hits.hits, item => (item._source))
}

module.exports = migrationFunction
17 changes: 16 additions & 1 deletion src/services/challengeInformixService.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ const helper = require('../util/helper')
// const getErrorService = require('./errorService')
const { executeQueryAsync } = require('../util/informixWrapper')

/**
* Get effort hours for a legacyId
* @param {Number} legacyId the legacy ID
*/
async function getEffortHoursFromIfx (legacyId) {
const sql = `SELECT LIMIT 1
project_info_type_id,
value,
FROM project_info
WHERE project_id = ${legacyId} and project_info_type_id in (88, 89, 90)
`
return execQuery(sql)
}

/**
* Gets the copilot payment for a legacyId
* @param {Number} legacyId the legacy ID
Expand Down Expand Up @@ -683,5 +697,6 @@ module.exports = {
getCopilotPaymentFromIfx,
createCopilotPaymentInIfx,
updateCopilotPaymentInIfx,
deleteCopilotPaymentFromIfx
deleteCopilotPaymentFromIfx,
getEffortHoursFromIfx
}
17 changes: 17 additions & 0 deletions src/services/challengeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,23 @@ async function buildV5Challenge (legacyId, challengeListing, challengeDetails) {
})
metadata.push(..._.compact(allMetadata))

const effortHoursMapping = {
effortHoursEstimate: 88,
effortHoursOffshore: 89,
effortHoursOnshore: 90
}

const legacyEffortHoursData = await challengeInformixService.getEffortHoursFromIfx(legacyId)
if (legacyEffortHoursData.length > 0) {
_.keys(effortHoursMapping, (key) => {
const legacyIndex = _.findIndex(legacyEffortHoursData, entry => entry.project_info_type_id === effortHoursMapping[key])
metadata.push({
name: key,
value: legacyEffortHoursData[legacyIndex].value
})
})
}

const events = []
if (challengeListing.events && challengeListing.events.length > 0) {
for (const event of challengeListing.events) {
Expand Down