Skip to content

Commit

Permalink
moved delete station in to helper folder
Browse files Browse the repository at this point in the history
  • Loading branch information
nikiwycherley committed May 8, 2024
1 parent cbfab1f commit a8187ab
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
11 changes: 1 addition & 10 deletions lib/functions/dts-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@ const invokeLambda = require('../helpers/invoke-lambda')
const Joi = require('joi')
const axios = require('axios')
const { HTTP_NOT_FOUND } = require('../constants')

async function deleteStation (stationId) {
try {
await pg('station_display_time_series').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
}
}
const deleteStation = require('../helpers/imtd-api').deleteStation

async function insertStation (stationDataArray) {
try {
Expand Down
14 changes: 14 additions & 0 deletions lib/helpers/imtd-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const logger = require('./logging')
const pg = require('./db')

async function deleteStation (stationId) {
try {
await pg('station_display_time_series').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
}
}

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

const logInfoCalls = logger.info.getCalls()
console.log('NW: ', logInfoCalls)

expect(logInfoCalls.length).to.equal(4)
expect(logInfoCalls.length).to.equal(3)
expect(logInfoCalls[2].args[0]).to.equal('Station 1001 not found (HTTP Status: 404)')
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 a8187ab

Please sign in to comment.