fix(database): parse sort
This commit is contained in:
parent
e36e3283a2
commit
adfac15aba
1
.gitignore
vendored
1
.gitignore
vendored
@ -11,3 +11,4 @@ db.sqlite
|
||||
coverage
|
||||
.umi
|
||||
/uploads
|
||||
.env.test
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { Appends, Except, FindOptions } from './repository';
|
||||
import FilterParser from './filter-parser';
|
||||
import { FindAttributeOptions, ModelCtor, Op } from 'sequelize';
|
||||
import { Database } from './database';
|
||||
import { Collection } from './collection';
|
||||
import { Database } from './database';
|
||||
import FilterParser from './filter-parser';
|
||||
import { Appends, Except, FindOptions } from './repository';
|
||||
|
||||
const debug = require('debug')('noco-database');
|
||||
|
||||
@ -61,8 +61,10 @@ export class OptionsParser {
|
||||
* @protected
|
||||
*/
|
||||
protected parseSort(filterParams) {
|
||||
const sort = this.options?.sort || [];
|
||||
|
||||
let sort = this.options?.sort || [];
|
||||
if (typeof sort === 'string') {
|
||||
sort = sort.split(',');
|
||||
}
|
||||
const orderParams = sort.map((sortKey: string) => {
|
||||
const direction = sortKey.startsWith('-') ? 'DESC' : 'ASC';
|
||||
const sortField: Array<any> = sortKey.replace('-', '').split('.');
|
||||
|
@ -49,7 +49,7 @@ export type Filter = any;
|
||||
export type Appends = string[];
|
||||
export type Except = string[];
|
||||
export type Fields = string[];
|
||||
export type Sort = string[];
|
||||
export type Sort = string[] | string;
|
||||
|
||||
export type WhiteList = string[];
|
||||
export type BlackList = string[];
|
||||
|
Loading…
Reference in New Issue
Block a user