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

Commit 2fef69f

Browse files
fix submissionLimit metadata
1 parent a1c9bba commit 2fef69f

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/services/ProcessorService.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,19 @@ async function processUpdate (message) {
509509
for (const metadataKey of _.keys(constants.supportedMetadata)) {
510510
const entry = _.find(message.payload.metadata, meta => meta.name === metadataKey)
511511
if (entry) {
512+
if (metadataKey === 'submissionLimit') {
513+
// data here is JSON stringified
514+
try {
515+
const parsedEntryValue = JSON.parse(entry.value)
516+
if (parsedEntryValue.limit) {
517+
entry.value = parsedEntryValue.count
518+
} else {
519+
entry.value = null
520+
}
521+
} catch (e) {
522+
entry.value = null
523+
}
524+
}
512525
try {
513526
await metadataService.createOrUpdateMetadata(message.payload.legacyId, constants.supportedMetadata[metadataKey], entry.value, _.get(message, 'payload.updatedBy') || _.get(message, 'payload.createdBy'))
514527
} catch (e) {

src/services/metadataService.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const helper = require('../common/helper')
99
const QUERY_GET_ENTRY = 'SELECT value FROM project_info WHERE project_id = %d and project_info_type_id = %d'
1010
const QUERY_CREATE = 'INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (?, ?, ?, ?, CURRENT, ?, CURRENT)'
1111
const QUERY_UPDATE = 'UPDATE project_info SET value = ?, modify_user = ?, modify_date = CURRENT WHERE project_info_type_id = ? AND project_id = ?'
12+
const QUERY_DELETE = 'DELETE FROM project_info WHERE project_id = ? and project_info_type_id = ?'
1213

1314
/**
1415
* Prepare Informix statement
@@ -56,9 +57,15 @@ async function createOrUpdateMetadata (challengeLegacyId, typeId, value, created
5657
// await connection.beginTransactionAsync()
5758
const [existing] = await getMetadataEntry(challengeLegacyId, typeId)
5859
if (existing) {
59-
logger.info(`Metadata ${typeId} exists. Will update`)
60-
const query = await prepare(connection, QUERY_UPDATE)
61-
result = await query.executeAsync([value, createdBy, typeId, challengeLegacyId])
60+
if (value) {
61+
logger.info(`Metadata ${typeId} exists. Will update`)
62+
const query = await prepare(connection, QUERY_UPDATE)
63+
result = await query.executeAsync([value, createdBy, typeId, challengeLegacyId])
64+
} else {
65+
logger.info(`Metadata ${typeId} exists. Will delete`)
66+
const query = await prepare(connection, QUERY_DELETE)
67+
result = await query.executeAsync([challengeLegacyId, typeId])
68+
}
6269
} else {
6370
logger.info(`Metadata ${typeId} does not exist. Will create`)
6471
const query = await prepare(connection, QUERY_CREATE)

0 commit comments

Comments
 (0)