Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- createJournal: flow(function* () {
- try {
- self.status = 'loading'
- const id = getRoot(self).masterStore.id
- const { api: apiService } = getEnv<Environment>(self)
- const result: GetJournalByEquipmentIdResult = yield apiService.createJournal(id, self.journal)
- const { journalStore } = getRoot(self)
- if (result.kind === 'ok') {
- if (getRoot(self).photosStore.imageIsSelected) {
- const journalID = result.result[0].id
- const equipmentID = getRoot(self).masterStore.id
- const promises = []
- const images = getRoot(self).photosStore.getImages
- for (let i = 0; i < images.length; i++)
- promises.push(apiService.addJournalAttachment(journalID, equipmentID, images[i]))
- const res = yield Promise.all(promises)
- let newEntry = self.journal.entry
- res.forEach((result, ind) => {
- if (result.kind !== 'ok') alert('At least one of the images was not uploaded')
- else {
- const attachmentId = result.result[0].attachment_id
- newEntry += `<p><img alt="journal image" title="${attachmentId}"></p>`
- }
- })
- self.journal.entry = newEntry
- const updateJournalRes = yield apiService.updateJournal(
- id,
- journalID,
- self.journal,
- )
- getRoot(self).photosStore.clean()
- }
- getRoot(self).navigationStore.goBack()
- self.clear()
- self.status = 'done'
- journalStore.nextStep()
- journalStore.clearJournal()
- } else {
- self.status = 'error'
- }
- } catch (err) {
- self.status = 'error'
- }
- }),
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement