Skip to content

Commit

Permalink
refactor: pull out gatherAuditFunctions
Browse files Browse the repository at this point in the history
  • Loading branch information
jezhiggins committed Aug 13, 2020
1 parent 09ce821 commit 539ae6f
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/components/services/audit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ class AuditService {
this.auditLog = options.bootedServices.storage.models.tymly_rewind

const pgScripts = options.blueprintComponents.pgScripts || {}
const auditFunctions = Object.keys(pgScripts)
.map(script => path.parse(pgScripts[script].filename).name)
.filter(filename => filename.split('-')[0] === 'audit')
.map(filename => {
debug(`Found audit function: ${filename.substring(filename.indexOf('-') + 1)}`)
return filename.substring(filename.indexOf('-') + 1)
})
const auditFunctions = gatherAuditFunctions(pgScripts)
const schemaNames = options.bootedServices.storage.schemaNames

await this.updateTriggers(auditFunctions, schemaNames, options.messages)
Expand Down Expand Up @@ -103,6 +97,16 @@ class AuditService {
} // formatLogs
} // AuditService

function gatherAuditFunctions (pgScripts) {
return Object.keys(pgScripts)
.map(script => path.parse(pgScripts[script].filename).name)
.filter(filename => filename.split('-')[0] === 'audit')
.map(filename => {
debug(`Found audit function: ${filename.substring(filename.indexOf('-') + 1)}`)
return filename.substring(filename.indexOf('-') + 1)
})
} // gatherAuditFunctions

function formatLog (log, model, additionalFields) {
const diffs = formatDiffs(log.diff, model)
const when = formatDate(log.modified)
Expand Down

0 comments on commit 539ae6f

Please sign in to comment.