feat: add date math for filters #1342

Merged
konrad merged 88 commits from feature/date-math into main 2022-03-28 17:30:43 +00:00
3 changed files with 28 additions and 8 deletions
Showing only changes of commit db47c1f10c - Show all commits

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') {
konrad marked this conversation as resolved Outdated

Why using here toISOString() and not just return the object?

Why using here `toISOString()` and not just return the object?

Because if I pass the object, it gets serialized as {} which is not what we want. This might be the wrong place to do that though.

I think we could move the entire conversion to the service?

Because if I pass the object, it gets serialized as `{}` which is not what we want. This might be the wrong place to do that though. I think we could move the entire conversion to the service?

Yes that makes sense

Yes that makes sense

Done.

Done.
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