item.contacts.forEach(function (contact) { console.log(item._id + ': search-contact: ' + contact.fullName) var getPrivatePerson = { generator: 'get-private-persons-id', personalIdNumber: contact.personalIdNumber } var options = getMetadata(getPrivatePerson) options.p360 = config.p360 p360(options, function (err, data) { if (err) { console.error(JSON.stringify(err)) return callback(err) } else { item.contacts[i].exists = false var privatePersons = data.GetPrivatePersonsResult.PrivatePersons if (Array.isArray(privatePersons.PrivatePersonBase)) { item.contacts[i].exists = true console.log(item._id + ': search-contact: ' + contact.fullName + ': exists in p360') // result = data.GetPrivatePersonsResult.PrivatePersons.PrivatePersonBase[0] } i++ if (item.contacts.length === i) { return callback(null, JSON.stringify(item)) } } }) })
var openCase = miss.through(function (chunck, encoding, callback) { var item = JSON.parse(chunck) console.log(item._id + ': open-case') if (!item.caseNumber) { console.log(item._id + ': open-case: case doesnt exist') return callback(null, JSON.stringify(item)) } var openThisCase = { generator: 'skoleskyss-open-case', caseNumber: item.caseNumber } var options = getMetadata(openThisCase) options.p360 = config.p360 p360(options, function (err, data) { if (err) { console.error(JSON.stringify(err)) return callback(err) } else { console.log(item._id + ': open-case: opened case: ' + item.caseNumber) return callback(null, JSON.stringify(item)) } }) })
var addNote = miss.through(function (chunck, encoding, callback) { var item = JSON.parse(chunck) console.log(item._id + ': add-note-documents') item.dsfNote = false var i = 0 var value = false item.documents.forEach(function (document) { if (document.type === 'note-dsf') { item.dsfNote = true value = i } i++ }) // Checks if note exists if (!item.dsfNote && !value) { console.log(item._id + ': add-note-documents: skipping - not set') return callback(null, JSON.stringify(item)) } var addThisDocuments = { generator: 'minelev-add-note-document', title: item.documents[value].title, personalIdNumber: item.person.id, contacts: item.contacts, schoolName: item.school.name, schoolOrgNumber: item.school.orgId, caseNumber: item.caseNumber, file: item.documents[value].data, fileTitle: item.documents[value].title } var options = getMetadata(addThisDocuments) options.p360 = config.p360 p360(options, function (err, data) { if (err) { console.error(JSON.stringify(err)) return callback(err) } else { console.log(item._id + ': add-note-documents: added document number: ' + data.CreateDocumentResult.DocumentNumber) return callback(null, JSON.stringify(item)) } }) })