'use strict'

var miss = require('mississippi')
var getMetadata = require('tfk-arkiv-metadatagenerator')
var p360 = require('p360')
var config = require('../config')

var addContact = miss.through(function (chunck, encoding, callback) {
  var item = JSON.parse(chunck)

  console.log(item._id + ': add-private-person')

  var i = 0
  item.contacts.forEach(function (contact) {
    console.log(item._id + ': add-private-person: ' + contact.fullName)

    // If contact exist skip step
    if (contact.exists === true) {
      console.log(item._id + ': add-private-person: ' + contact.fullName + ': Did not update private person')
      i++
      if (item.contacts.length === i) {
        return callback(null, JSON.stringify(item))
      }
      return
    }

    var addPrivatePerson = {
      generator: 'add-private-person',
      firstName: contact.firstName,
      middleName: contact.middleName,
      lastName: contact.lastName,
      personalIdNumber: contact.personalIdNumber,
      email: contact.email,
      phone: contact.phone,
      streetAddress: contact.address,
      zipCode: contact.zip,
      zipPlace: contact.city,
      area: 'Telemark'
    }

    var options = getMetadata(addPrivatePerson)
    options.p360 = config.p360

    p360(options, function (err, data) {
      if (err) {
        console.error(JSON.stringify(err))
        return callback(err)
      } else {
        i++
        console.log(item._id + ': add-private-person: ' + contact.fullName + ': Created private person')
        if (item.contacts.length === i) {
          return callback(null, JSON.stringify(item))
        }
      }
    })
  })
})

module.exports = addContact

@@ -477,24 +477,26 @@
 ip step%0A    
+//
 if (contact.
@@ -514,24 +514,26 @@
 true) %7B%0A    
+//
   console.lo
@@ -626,24 +626,26 @@
 erson')%0A    
+//
   i++%0A      
@@ -638,24 +638,26 @@
 //  i++%0A    
+//
   if (item.c
@@ -680,24 +680,26 @@
 == i) %7B%0A    
+//
     return c
@@ -738,24 +738,26 @@
 m))%0A    
+//
   %7D%0A    
   return
@@ -744,24 +744,26 @@
   //  %7D%0A    
+//
   return%0A   
@@ -759,24 +759,26 @@
  return%0A    
+//
 %7D%0A%0A    var a
@@ -1493,17 +1493,28 @@
 me + ': 
-C
+Updated or c
 reated p

Update add-private-person.js