Skip to content

Commit

Permalink
refactored deleting a station
Browse files Browse the repository at this point in the history
  • Loading branch information
nikiwycherley committed May 8, 2024
1 parent 8f36696 commit 183fe4b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/functions/imtd-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ async function getData (stationId) {
await insertThresholds(stationId, thresholds)
} else {
await deleteThresholds(stationId, tableName)
logger.info(`Deleted data for RLOI id ${stationId}`)
}
} catch (error) {
logger.error(`Could not process data for station ${stationId} (${error.message})`)
Expand Down
9 changes: 1 addition & 8 deletions lib/helpers/imtd-api.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
const logger = require('./logging')
const pg = require('./db')

async function deleteStation (stationId, tableName) {
try {
await pg(tableName).where({ station_id: stationId }).delete()
logger.info(`Deleted data for RLOI id ${stationId}`)
} catch (error) {
logger.error(`Error deleting data for station ${stationId}`, error)
throw error
}
await pg(tableName).where({ station_id: stationId }).delete()
}

module.exports = { deleteStation }
5 changes: 3 additions & 2 deletions test/unit/functions/imtd-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ experiment('imtd processing', () => {
await handler()

const logInfoCalls = logger.info.getCalls()
expect(logInfoCalls.length).to.equal(3)
console.log(logInfoCalls)
expect(logInfoCalls.length).to.equal(4)
expect(logInfoCalls[2].args[0]).to.equal('Station 1001 not found (HTTP Status: 404)')
// expect(logInfoCalls[3].args[0]).to.equal('Deleted thresholds for RLOI id 1001')
expect(logInfoCalls[3].args[0]).to.equal('Deleted data for RLOI id 1001')

const logErrorCalls = logger.error.getCalls()
expect(logErrorCalls.length).to.equal(0)
Expand Down

0 comments on commit 183fe4b

Please sign in to comment.