chore: move converting params to service
This commit is contained in:
parent
a8ee54d626
commit
db47c1f10c
3 changed files with 28 additions and 8 deletions
|
@ -45,10 +45,6 @@ export function objectToCamelCase(object) {
|
||||||
*/
|
*/
|
||||||
export function objectToSnakeCase(object) {
|
export function objectToSnakeCase(object) {
|
||||||
|
|
||||||
if (object instanceof Date) {
|
|
||||||
return object.toISOString()
|
|
||||||
}
|
|
||||||
|
|
||||||
// When calling recursively, this can be called without being and object or array in which case we just return the value
|
// When calling recursively, this can be called without being and object or array in which case we just return the value
|
||||||
if (typeof object !== 'object') {
|
if (typeof object !== 'object') {
|
||||||
return object
|
return object
|
||||||
|
|
|
@ -2,6 +2,31 @@ import axios from 'axios'
|
||||||
import {objectToSnakeCase} from '@/helpers/case'
|
import {objectToSnakeCase} from '@/helpers/case'
|
||||||
import {getToken} from '@/helpers/auth'
|
import {getToken} from '@/helpers/auth'
|
||||||
|
|
||||||
|
function convertObject(o) {
|
||||||
|
if (o instanceof Date) {
|
||||||
|
return o.toISOString()
|
||||||
|
}
|
||||||
|
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
function prepareParams(params) {
|
||||||
|
if (typeof params !== 'object') {
|
||||||
|
return params
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const p in params) {
|
||||||
|
if (Array.isArray(params[p])) {
|
||||||
|
params[p] = params[p].map(convertObject)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
params[p] = convertObject(params[p])
|
||||||
|
}
|
||||||
|
|
||||||
|
return objectToSnakeCase(params)
|
||||||
|
}
|
||||||
|
|
||||||
export default class AbstractService {
|
export default class AbstractService {
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
@ -292,7 +317,7 @@ export default class AbstractService {
|
||||||
const finalUrl = this.getReplacedRoute(url, model)
|
const finalUrl = this.getReplacedRoute(url, model)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await this.http.get(finalUrl, {params})
|
const response = await this.http.get(finalUrl, {params: prepareParams(params)})
|
||||||
const result = this.modelGetFactory(response.data)
|
const result = this.modelGetFactory(response.data)
|
||||||
result.maxRight = Number(response.headers['x-max-right'])
|
result.maxRight = Number(response.headers['x-max-right'])
|
||||||
return result
|
return result
|
||||||
|
@ -331,7 +356,7 @@ export default class AbstractService {
|
||||||
const finalUrl = this.getReplacedRoute(this.paths.getAll, model)
|
const finalUrl = this.getReplacedRoute(this.paths.getAll, model)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await this.http.get(finalUrl, {params: params})
|
const response = await this.http.get(finalUrl, {params: prepareParams(params)})
|
||||||
this.resultCount = Number(response.headers['x-pagination-result-count'])
|
this.resultCount = Number(response.headers['x-pagination-result-count'])
|
||||||
this.totalPages = Number(response.headers['x-pagination-total-pages'])
|
this.totalPages = Number(response.headers['x-pagination-total-pages'])
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,6 @@ import {useI18n} from 'vue-i18n'
|
||||||
import TaskModel from '@/models/task'
|
import TaskModel from '@/models/task'
|
||||||
import {formatDate} from '@/helpers/time/formatDate'
|
import {formatDate} from '@/helpers/time/formatDate'
|
||||||
import {setTitle} from '@/helpers/setTitle'
|
import {setTitle} from '@/helpers/setTitle'
|
||||||
import {objectToSnakeCase} from '@/helpers/case'
|
|
||||||
|
|
||||||
import Fancycheckbox from '@/components/input/fancycheckbox.vue'
|
import Fancycheckbox from '@/components/input/fancycheckbox.vue'
|
||||||
import SingleTaskInList from '@/components/tasks/partials/singleTaskInList.vue'
|
import SingleTaskInList from '@/components/tasks/partials/singleTaskInList.vue'
|
||||||
|
@ -202,7 +201,7 @@ async function loadPendingTasks(from: string, to: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.value = await store.dispatch('tasks/loadTasks', objectToSnakeCase(params))
|
tasks.value = await store.dispatch('tasks/loadTasks', params)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: this modification should happen in the store
|
// FIXME: this modification should happen in the store
|
||||||
|
|
Loading…
Reference in a new issue