lib/model/instance/form-partial.js
// the def should end up (draft v current).
the def should end up (draft v current).
the def should end up ( draft v current ) .
createNew(publish = false) {
    const form = Form.fromData(this);
    const additional = (publish === true) ? { publishedAt: new Date() } : { draftToken: generateToken() };
    return Promise.all([
      this.key.map((k) => k.ensure()).orElse(resolve(null)),
      getFormFields(this.xml)
    ])
      .then(([ keyId, fields ]) => Promise.all([
        forms.create(form.with({ def: Object.assign({ keyId }, additional) }), publish),
        expectedFormAttachments(this.xml)
      ])
        .then(itemsetsHack(Blob, this.itemsets, 1))
        .then(([ savedForm, expectedAttachments ]) => {
          const withIds = (data) =>
            Object.assign({ formId: savedForm.id, formDefId: savedForm.def.id }, data);
          return Promise.all([
            simply.insert('form_attachments', expectedAttachments.map(withIds)),
            simply.insert('form_fields', fields.map(withIds))
          ]).then(always(savedForm));
        }));
  }
createNew ( publish = false ) { const form = Form . fromData ( this ) ; const additional = ( publish === true ) ? { publishedAt : new Date ( ) } : { draftToken : generateToken ( ) } ; return Promise . all ( [ this . key . map ( ( k ) => k . ensure ( ) ) . orElse ( resolve ( null ) ) , getFormFields ( this . xml ) ] ) . then ( ( [ keyId , fields ] ) => Promise . all ( [ forms . create ( form . with ( { def : Object . assign ( { keyId } , additional ) } ) , publish ) , expectedFormAttachments ( this . xml ) ] ) . then ( itemsetsHack ( Blob , this . itemsets , 1 ) ) . then ( ( [ savedForm , expectedAttachments ] ) => { const withIds = ( data ) => Object . assign ( { formId : savedForm . id , formDefId : savedForm . def . id } , data ) ; return Promise . all ( [ simply . insert ( 'form_attachments' , expectedAttachments . map ( withIds ) ) , simply . insert ( 'form_fields' , fields . map ( withIds ) ) ] ) . then ( always ( savedForm ) ) ; } ) ) ; }
the def should end up (draft v current).
the def should end up ( draft v current ) .