Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds the postgres nulls support #645

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/crud-request/src/types/request-query.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ export type QueryJoinArr = [string, QueryFields?];
export type QuerySort = {
field: string;
order: QuerySortOperator;
nulls?: QuerySortNullsPriority;
};

export type QuerySortArr = [string, QuerySortOperator];

export type QuerySortOperator = 'ASC' | 'DESC';
export type QuerySortNullsPriority = 'NULLS FIRST' | 'NULLS LAST';

type DeprecatedCondOperator =
| 'eq'
Expand Down
8 changes: 6 additions & 2 deletions packages/crud-typeorm/src/typeorm-crud.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,12 @@ export class TypeOrmCrudService<T> extends CrudService<T> {

for (let i = 0; i < sort.length; i++) {
const field = this.getFieldWithAlias(sort[i].field, true);
const checkedFiled = this.checkSqlInjection(field);
params[checkedFiled] = sort[i].order;
const checkedField = this.checkSqlInjection(field);
params[checkedField] = sort[i].order;
if (this.dbName === 'postgres' && sort[i].nulls) {
/* istanbul ignore next */
params[checkedField] += ' ' + sort[i].nulls;
}
}

return params;
Expand Down