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

Commit eef5e98

Browse files
author
James Cori
committed
Fixing the Insert query
1 parent 3445b59 commit eef5e98

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/scripts/sync-terms.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const logger = require('../common/logger')
77
const helper = require('../common/helper')
88

99
const QUERY_GET_ENTRIES = 'SELECT user_id FROM user_terms_of_use_xref WHERE terms_of_use_id = %d'
10-
const QUERY_INSERT_ENTRY = 'INSERT INTO user_terms_of_use_xref (user_id, terms_of_use_id, create_date, modify_date) VALUES (?, ?, ?, ?)'
10+
const QUERY_INSERT_ENTRY = 'INSERT INTO user_terms_of_use_xref (user_id, terms_of_use_id, create_date, modify_date) VALUES (?, ?, CURRENT, CURRENT)'
1111

1212
/**
1313
* Prepare Informix statement
@@ -49,9 +49,12 @@ async function createEntry (termsOfUseId, memberId) {
4949
let result = null
5050
try {
5151
// await connection.beginTransactionAsync()
52-
const currentDateIso = new Date().toISOString().replace('T', ' ').replace('Z', '').split('.')[0]
5352
const query = await prepare(connection, QUERY_INSERT_ENTRY)
54-
result = await query.executeAsync([termsOfUseId, memberId, currentDateIso, currentDateIso])
53+
if (config.SYNC_V5_WRITE_ENABLED) {
54+
result = await query.executeAsync([memberId, termsOfUseId])
55+
} else {
56+
logger.debug(`INSERT INTO user_terms_of_use_xref (user_id, terms_of_use_id, create_date, modify_date) VALUES (${memberId}, ${termsOfUseId}, CURRENT, CURRENT)`)
57+
}
5558
// await connection.commitTransactionAsync()
5659
} catch (e) {
5760
logger.error(`Error in 'createEntry' ${e}, rolling back transaction`)
@@ -114,12 +117,7 @@ async function main () {
114117
logger.debug(`Found ${legacyIntries.length} users`)
115118
for (const memberId of v5Entries) {
116119
if (legacyIntries.indexOf(memberId) === -1) {
117-
if (config.SYNC_V5_WRITE_ENABLED) {
118-
await createEntry(legacyTermId, memberId)
119-
} else {
120-
const currentDateIso = new Date().toISOString().replace('T', ' ').replace('Z', '').split('.')[0]
121-
logger.debug(`INSERT INTO user_terms_of_use_xref (user_id, terms_of_use_id, create_date, modify_date) VALUES (${legacyTermId}, ${memberId}, ${currentDateIso}, ${currentDateIso})`)
122-
}
120+
await createEntry(legacyTermId, memberId)
123121
}
124122
}
125123
logger.info('Completed!')

0 commit comments

Comments
 (0)