chore: move converting params to service
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
kolaente 2022-02-27 17:21:07 +01:00
parent a8ee54d626
commit db47c1f10c
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 28 additions and 8 deletions

View File

@ -45,10 +45,6 @@ export function objectToCamelCase(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
if (typeof object !== 'object') {
return object

View File

@ -2,6 +2,31 @@ import axios from 'axios'
import {objectToSnakeCase} from '@/helpers/case'
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 {
/////////////////////////////
@ -292,7 +317,7 @@ export default class AbstractService {
const finalUrl = this.getReplacedRoute(url, model)
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)
result.maxRight = Number(response.headers['x-max-right'])
return result
@ -331,7 +356,7 @@ export default class AbstractService {
const finalUrl = this.getReplacedRoute(this.paths.getAll, model)
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.totalPages = Number(response.headers['x-pagination-total-pages'])

View File

@ -53,7 +53,6 @@ import {useI18n} from 'vue-i18n'
import TaskModel from '@/models/task'
import {formatDate} from '@/helpers/time/formatDate'
import {setTitle} from '@/helpers/setTitle'
import {objectToSnakeCase} from '@/helpers/case'
import Fancycheckbox from '@/components/input/fancycheckbox.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