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

Commit 83f1e4d

Browse files
author
James Cori
committed
HotFix for 0 Legacy ID
1 parent aee1e95 commit 83f1e4d

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/controllers/syncController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async function syncQueuedChallenges () {
3434
try {
3535
for (let i = 0; i < queuedChallenges.items.length; i += 1) {
3636
const item = queuedChallenges.items[i]
37-
if (toString(item.legacyId) !== 'NaN') {
37+
if (toString(item.legacyId) !== 'NaN' && item.legacyId > 0) {
3838
await syncService.syncLegacyId(toNumber(item.legacyId), item.force)
3939
} else {
4040
logger.error(`Sync Failed for Bad Legacy ID: ${item.legacyId}`)

src/scripts/migrations/010-fix-effort-hours.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const config = require('config')
1010
const _ = require('lodash')
1111
const logger = require('../../util/logger')
1212
const challengeService = require('../../services/challengeService')
13-
const { getESClient } = require('../../util/helper')
13+
// const { getESClient } = require('../../util/helper')
14+
const moment = require('moment')
1415
const { execQuery, getEffortHoursFromIfx } = require('../../services/challengeInformixService')
1516

1617
const mapping = {
@@ -41,6 +42,9 @@ const migrationFunction = {
4142
const legacyData = await getEffortHoursFromIfx(legacyIdRow.legacy_id)
4243
// logger.debug(`Legacy Data: ${JSON.stringify(legacyData)}`)
4344
if (legacyData.length > 0) {
45+
if (!challenge.metadata) {
46+
challenge.metadata = []
47+
}
4448
_.forEach(mapping, (mappingValue, key) => {
4549
// logger.debug(`${JSON.stringify(mappingValue)} -> ${key}`)
4650
const v5Index = _.findIndex(challenge.metadata, meta => meta.name === key)
@@ -63,6 +67,8 @@ const migrationFunction = {
6367
}
6468
})
6569
// logger.debug(`Writing Challenge ${JSON.stringify(challenge)}`)
70+
challenge.updated = moment().utc().format()
71+
challenge.updatedBy = 'v5migration'
6672
await challengeService.save(challenge)
6773
}
6874
}
@@ -91,6 +97,7 @@ async function getEffortHoursChallengeIds (page, perPage) {
9197
DISTINCT project_id as legacy_id
9298
FROM project_info
9399
WHERE project_info_type_id in (88, 89, 90)
100+
ORDER BY project_id ASC
94101
`
95102
logger.info(`Effort Hours SQL: ${sql}`)
96103
return execQuery(sql)

src/services/syncService.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ const { challengeStatusOrders } = require('../constants')
1212

1313
async function syncLegacyId (legacyId, force) {
1414
// const legacyId = queuedChallenges.items[i].legacyId
15-
const [v5] = await challengeService.getChallengeFromV5API(legacyId)
15+
let v5
16+
try {
17+
[v5] = await challengeService.getChallengeFromV5API(legacyId)
18+
} catch (e) {
19+
logger.error(`syncLegacyId Failed ${e}`)
20+
return false
21+
}
1622
// see if v5 exists
1723
if (v5) {
1824
const v4Listing = await challengeService.getChallengeListingFromV4ES(legacyId)

0 commit comments

Comments
 (0)