import { sortBy } from 'lodash' ; import { IRestApiResponse } from 'superdesk-api' ; import { IStorageDestinationItem } from '../interfaces' ; import { superdeskApi } from '../apis' ; import { getApiErrorMessage , isSamsApiError } from '../utils/api' ; const RESOURCE = 'sams/destinations' ; export function getAllStorageDestinations ( ) { const { gettext } = superdeskApi . localization ; const { notify } = superdeskApi . ui ; return superdeskApi . dataApi . query ( RESOURCE , 1 , { field : 'name' , direction : 'ascending' } , { } ) . then ( ( response ) => { return sortBy < IStorageDestinationItem > ( response ?. _items ?? [ ] , [ '_id' ] ) ; } ) . catch ( ( error ) => { if ( isSamsApiError ( error ) ) { notify . error ( getApiErrorMessage ( error ) ) ; } else { notify . error ( gettext ( 'Failed to load all storage destinations' ) ) ; } return Promise . reject ( error ) ; } ) ; }