Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. createJournal: flow(function* () {
  2. try {
  3. self.status = 'loading'
  4. const id = getRoot(self).masterStore.id
  5. const { api: apiService } = getEnv<Environment>(self)
  6. const result: GetJournalByEquipmentIdResult = yield apiService.createJournal(id, self.journal)
  7. const { journalStore } = getRoot(self)
  8. if (result.kind === 'ok') {
  9. if (getRoot(self).photosStore.imageIsSelected) {
  10. const journalID = result.result[0].id
  11. const equipmentID = getRoot(self).masterStore.id
  12. const promises = []
  13. const images = getRoot(self).photosStore.getImages
  14. for (let i = 0; i < images.length; i++)
  15. promises.push(apiService.addJournalAttachment(journalID, equipmentID, images[i]))
  16. const res = yield Promise.all(promises)
  17. let newEntry = self.journal.entry
  18. res.forEach((result, ind) => {
  19. if (result.kind !== 'ok') alert('At least one of the images was not uploaded')
  20. else {
  21. const attachmentId = result.result[0].attachment_id
  22. newEntry += `<p><img alt="journal image" title="${attachmentId}"></p>`
  23. }
  24. })
  25. self.journal.entry = newEntry
  26. const updateJournalRes = yield apiService.updateJournal(
  27. id,
  28. journalID,
  29. self.journal,
  30. )
  31. getRoot(self).photosStore.clean()
  32. }
  33. getRoot(self).navigationStore.goBack()
  34. self.clear()
  35. self.status = 'done'
  36. journalStore.nextStep()
  37. journalStore.clearJournal()
  38. } else {
  39. self.status = 'error'
  40. }
  41. } catch (err) {
  42. self.status = 'error'
  43. }
  44. }),
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement