@@ -5,15 +5,16 @@ import {
5
5
extractIntegerValue
6
6
} from "./helpers" ;
7
7
import isEqual from "lodash.isequal" ;
8
+ import { GenericDictionnary } from "./VDUSTypes"
8
9
9
10
/*
10
11
This function take a object in parameter that is often a form of filtering field
11
12
all this field are filtered before being used to be transformed as a query url
12
13
if localName is true it will no replace the param key with the real used for backend query
13
14
if localName is false the name will be replaced by the correct one sended to backend
14
15
*/
15
- function generateQueryFromObject ( object , schema , localName = true ) {
16
- let queryUrl = { } ;
16
+ function generateQueryFromObject ( object : GenericDictionnary , schema ?: GenericDictionnary , localName : Boolean = true ) : GenericDictionnary {
17
+ let queryUrl : GenericDictionnary = { } ;
17
18
for ( let [ key , value ] of Object . entries ( object ) ) {
18
19
// We do not want to send a default value
19
20
if ( isValueDefault ( value , key , schema ) ) {
@@ -32,7 +33,7 @@ function generateQueryFromObject(object, schema, localName = true) {
32
33
return queryUrl ;
33
34
}
34
35
35
- function getDefaultValueForParam ( param , schema ) {
36
+ function getDefaultValueForParam ( param : string , schema ?: GenericDictionnary ) : any {
36
37
if ( schema && schema [ param ] ) {
37
38
// if there is a defautl value we change the condition to is non equality
38
39
if ( schema [ param ] . default ) {
@@ -51,9 +52,9 @@ function getDefaultValueForParam(param, schema) {
51
52
return null ;
52
53
}
53
54
54
- function isValueDefault ( value , param , schema ) {
55
+ function isValueDefault ( value : any , param : string , schema ?: GenericDictionnary ) : boolean {
55
56
// Default is string
56
- let isValueDefault = value === "" ;
57
+ let isValueDefault : boolean = value === "" ;
57
58
58
59
if ( schema && schema [ param ] ) {
59
60
// if there is a defautl value we change the condition to is non equality
@@ -84,14 +85,14 @@ function isValueDefault(value, param, schema) {
84
85
Transform query parameter from vue router to two javascript objects representing the filtering form and the options
85
86
*/
86
87
function readFormAndOptionsFromLocalQuery (
87
- query ,
88
- form ,
89
- options ,
90
- schema ,
91
- removedParam = [ ]
92
- ) {
93
- let newOptions = { } ;
94
- let newForm = { } ;
88
+ query : GenericDictionnary ,
89
+ form : GenericDictionnary ,
90
+ options : GenericDictionnary ,
91
+ schema ?: GenericDictionnary ,
92
+ removedParam : Array < string > = [ ]
93
+ ) : { newOptions : GenericDictionnary , newForm : GenericDictionnary } {
94
+ let newOptions : GenericDictionnary = { } ;
95
+ let newForm : GenericDictionnary = { } ;
95
96
for ( let param in query ) {
96
97
if ( typeof form [ param ] !== "undefined" ) {
97
98
newForm [ param ] = convertParamIfTypeInSchema ( query , param , schema ) ;
@@ -113,7 +114,7 @@ function readFormAndOptionsFromLocalQuery(
113
114
return { newOptions, newForm } ;
114
115
}
115
116
116
- function convertParamIfTypeInSchema ( query , param , schema , prefix = "" ) {
117
+ function convertParamIfTypeInSchema ( query : GenericDictionnary , param : string , schema ?: GenericDictionnary , prefix : string = "" ) : any {
117
118
if ( ! schema || ! schema [ param ] || ! schema [ param ] . type ) {
118
119
return query [ prefix + param ] ;
119
120
}
@@ -133,9 +134,9 @@ function convertParamIfTypeInSchema(query, param, schema, prefix = "") {
133
134
return query [ prefix + param ] ;
134
135
}
135
136
136
- function getRemovedKeyBetweenTwoObject ( originalObject , newObject ) {
137
- const originalObjectKeys = Object . keys ( originalObject ) ;
138
- const newObjectKeys = Object . keys ( newObject ) ;
137
+ function getRemovedKeyBetweenTwoObject ( originalObject : GenericDictionnary , newObject : GenericDictionnary ) : Array < string > {
138
+ const originalObjectKeys : Array < string > = Object . keys ( originalObject ) ;
139
+ const newObjectKeys : Array < string > = Object . keys ( newObject ) ;
139
140
return originalObjectKeys . filter (
140
141
originalKey => ! newObjectKeys . includes ( originalKey )
141
142
) ;
0 commit comments