fix(database): parse sort

This commit is contained in:
chenos 2022-02-15 17:36:32 +08:00
parent e36e3283a2
commit adfac15aba
3 changed files with 9 additions and 6 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ db.sqlite
coverage
.umi
/uploads
.env.test

View File

@ -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('.');

View File

@ -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[];