Skip to content

Commit

Permalink
Checks distribution documents length before saving job
Browse files Browse the repository at this point in the history
  • Loading branch information
zrrrzzt committed Mar 22, 2017
1 parent e845320 commit 1690339
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/save-job-distribution.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ module.exports = miss.through((chunck, encoding, callback) => {

if (item.errors.length === 0 && item.sendToDistribution === true) {
console.log(item._id + ': save-job-distribution')
fs.writeFileSync(fileName, JSON.stringify(item.distribution, null, 2))
if (item.distribution.documents.length > 0) {
fs.writeFileSync(fileName, JSON.stringify(item.distribution, null, 2))
} else {
console.log(item._id + ': save-job-distribution - no documents to distribute')
}
} else {
console.log(item._id + ': save-job-distribution - nothing to distribute due to errors')
}
Expand Down
2 changes: 1 addition & 1 deletion lib/setup-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const readyForDistribution = require('./ready-for-distribution')

module.exports = miss.through((chunk, encoding, callback) => {
let item = JSON.parse(chunk)

const now = new Date()
const date = datePadding(now.getDate()) + '.' + datePadding(now.getMonth() + 1) + '.' + now.getFullYear()
const schoolInfo = getSchoolInfo(item.schoolOrganizationNumber.replace(/\D/g, ''))
Expand Down Expand Up @@ -82,5 +81,6 @@ module.exports = miss.through((chunk, encoding, callback) => {
}
item.documentTemplates.push(guardianDocument)
}

return callback(null, JSON.stringify(item))
})

0 comments on commit 1690339

Please sign in to comment.