diff --git a/addon/services/crud.js b/addon/services/crud.js index 9f08f91..c0c6d9b 100644 --- a/addon/services/crud.js +++ b/addon/services/crud.js @@ -198,6 +198,7 @@ export default class CrudService extends Service { // set the model uri endpoint const modelEndpoint = dasherize(pluralize(modelName)); + const exportParams = options.params ?? {}; this.modalsManager.show('modals/export-form', { title: `Export ${pluralize(modelName)}`, @@ -215,8 +216,10 @@ export default class CrudService extends Service { `${modelEndpoint}/export`, { format, + ...exportParams, }, { + method: 'POST', fileName: `${modelEndpoint}-${formatDate(new Date(), 'yyyy-MM-dd-HH:mm')}.${format}`, } ) diff --git a/addon/services/fetch.js b/addon/services/fetch.js index ae67c32..2f094e1 100644 --- a/addon/services/fetch.js +++ b/addon/services/fetch.js @@ -598,12 +598,18 @@ export default class FetchService extends Service { */ download(path, query = {}, options = {}) { const headers = Object.assign(this.getHeaders(), options.headers ?? {}); + const method = options.method ?? 'GET'; + const credentials = options.credentials ?? this.credentials; + const baseUrl = `${options.host || this.host}/${options.namespace || this.namespace}`; + const params = method.toUpperCase() === 'GET' ? `?${!isBlank(query) ? new URLSearchParams(query).toString() : ''}` : ''; + const body = method.toUpperCase() !== 'GET' ? JSON.stringify(query) : {}; return new Promise((resolve, reject) => { - return fetch(`${options.host || this.host}/${options.namespace || this.namespace}/${path}?${!isBlank(query) ? new URLSearchParams(query).toString() : ''}`, { - method: 'GET', - credentials: options.credentials || this.credentials, + return fetch(`${baseUrl}/${path}${params}`, { + method, + credentials, headers, + body, }) .then((response) => { options.fileName = this.getFilenameFromResponse(response, options.fileName);