import parseFileAttachment from './parseFileAttachment' ; import parseBlobAttachment from './parseBlobAttachment' ; import parseXMAAttachment from './parseXMAAttachment' ; import { FileAttachment , XMAAttachment } from '../Attachment' ; export interface Attachments { fileAttachments : FileAttachment [ ] ; mediaAttachments : XMAAttachment [ ] ; } export default function parseAttachments ( attachments ) { const result = { fileAttachments : [ ] , mediaAttachments : [ ] } ; for ( let attachment of attachments ) { if ( attachment . mimeType ) result . fileAttachments . push ( parseFileAttachment ( attachment ) ) ; if ( attachment . mimetype ) result . fileAttachments . push ( parseBlobAttachment ( attachment ) ) ; if ( attachment . xmaGraphQL ) result . mediaAttachments . push ( parseXMAAttachment ( JSON . parse ( attachment . xmaGraphQL ) ) ) ; result . mediaAttachments . push ( { type : 'Unknown' , ... attachment } ) ; } return result ; }