@@ -9,7 +9,7 @@ import isEqual from "lodash.isequal";
9
9
import { GenericDictionnary , VDUSDatatableOptions , VDUSFormSchema } from "./VDUSTypes"
10
10
11
11
const getDefaultValueForParam = ( param : string , schema ?: VDUSFormSchema ) : any => {
12
- if ( schema && schema [ param ] ) {
12
+ if ( schema ?. [ param ] ) {
13
13
// if there is a defautl value we change the condition to is non equality
14
14
if ( schema [ param ] . default ) {
15
15
// TODO default value for array need to be stringify ?
@@ -31,7 +31,7 @@ const isValueDefault = (value: any, param: string, schema?: VDUSFormSchema): boo
31
31
// Default is string
32
32
let isValueDefault : boolean = value === "" ;
33
33
34
- if ( schema && schema [ param ] ) {
34
+ if ( schema ?. [ param ] ) {
35
35
// if there is a defautl value we change the condition to is non equality
36
36
if ( typeof ( schema [ param ] . default ) !== "undefined" ) {
37
37
// We have a special case for nullBoolean because we can have null value that is not the default
@@ -79,18 +79,36 @@ const generateQueryFromObject = (object: GenericDictionnary, schema?: VDUSFormSc
79
79
80
80
// by default the quey key is the same that the form key
81
81
let queryKey = key ;
82
+ let queryValue = value ;
82
83
// But this can be overrided if name attribute is defined in the param schema
83
- if ( ! localName && schema && schema [ key ] && schema [ key ] . name ) {
84
+ if ( ! localName && schema ?. [ key ] ? .name ) {
84
85
queryKey = ( schema [ key ] . name as string ) ; // typescript error because .name can be undefined but if check it before
85
86
}
86
87
87
- queryUrl [ queryKey ] = value ;
88
+ // As ordering key is a special key where other key can be specified inside its value we need to check for each ordernig key if there is a different server name
89
+ if ( key === 'ordering' && ! localName && value && Array . isArray ( value ) ) {
90
+ queryValue = value . map ( ( orderItem : string ) => {
91
+ let prefix = ""
92
+ // If we have a desc order we need to remove the - to match with the schema
93
+ if ( orderItem . startsWith ( "-" ) ) {
94
+ orderItem = orderItem . replace ( "-" , "" ) ;
95
+ prefix = "-"
96
+ }
97
+ // Look if we have a specific server name for this attribute in the schema.
98
+ if ( schema ?. [ orderItem ] ?. name ) {
99
+ orderItem = ( schema [ orderItem ] . name as string )
100
+ }
101
+ // Do not forget to add the prefix to have the correct ordering
102
+ return `${ prefix } ${ orderItem } ` ;
103
+ } )
104
+ }
105
+ queryUrl [ queryKey ] = queryValue ;
88
106
}
89
107
return queryUrl ;
90
108
}
91
109
92
110
const convertParamIfTypeInSchema = ( query : GenericDictionnary , param : string , schema ?: VDUSFormSchema , prefix = "" ) : any => {
93
- if ( ! schema || ! schema [ param ] || ! schema [ param ] . type ) {
111
+ if ( ! schema ?. [ param ] ? .type ) {
94
112
return query [ prefix + param ] ;
95
113
}
96
114
if ( schema [ param ] . type === "boolean" ) {
0 commit comments