(
query: SelectQueryBuilder<any, any, any>,
model: string,
modelAlias: string,
orderBy: OrArray<OrderBy<Schema, GetModels<Schema>, boolean, boolean>> | undefined,
negated: boolean,
take: number | undefined,
)
| 1100 | } |
| 1101 | |
| 1102 | buildOrderBy( |
| 1103 | query: SelectQueryBuilder<any, any, any>, |
| 1104 | model: string, |
| 1105 | modelAlias: string, |
| 1106 | orderBy: OrArray<OrderBy<Schema, GetModels<Schema>, boolean, boolean>> | undefined, |
| 1107 | negated: boolean, |
| 1108 | take: number | undefined, |
| 1109 | ) { |
| 1110 | if (!orderBy) { |
| 1111 | return query; |
| 1112 | } |
| 1113 | |
| 1114 | let result = query; |
| 1115 | |
| 1116 | const buildFieldRef = (model: string, field: string, modelAlias: string) => { |
| 1117 | const fieldDef = requireField(this.schema, model, field); |
| 1118 | return fieldDef.originModel |
| 1119 | ? this.fieldRef(fieldDef.originModel, field, fieldDef.originModel) |
| 1120 | : this.fieldRef(model, field, modelAlias); |
| 1121 | }; |
| 1122 | |
| 1123 | enumerate(orderBy).forEach((orderBy, index) => { |
| 1124 | for (const [field, value] of Object.entries<any>(orderBy)) { |
| 1125 | if (!value) { |
| 1126 | continue; |
| 1127 | } |
| 1128 | |
| 1129 | // _fuzzyRelevance ordering |
| 1130 | if (field === '_fuzzyRelevance') { |
| 1131 | result = this.applyFuzzyRelevanceOrderBy(result, model, modelAlias, value, negated, buildFieldRef); |
| 1132 | continue; |
| 1133 | } |
| 1134 | |
| 1135 | // _ftsRelevance ordering |
| 1136 | if (field === '_ftsRelevance') { |
| 1137 | result = this.applyFtsRelevanceOrderBy(result, model, modelAlias, value, negated, buildFieldRef); |
| 1138 | continue; |
| 1139 | } |
| 1140 | |
| 1141 | // aggregations |
| 1142 | if (['_count', '_avg', '_sum', '_min', '_max'].includes(field)) { |
| 1143 | result = this.applyAggregationOrderBy( |
| 1144 | result, |
| 1145 | model, |
| 1146 | modelAlias, |
| 1147 | field as AggregateOperators, |
| 1148 | value, |
| 1149 | negated, |
| 1150 | buildFieldRef, |
| 1151 | ); |
| 1152 | continue; |
| 1153 | } |
| 1154 | |
| 1155 | const fieldDef = requireField(this.schema, model, field); |
| 1156 | |
| 1157 | if (!fieldDef.relation) { |
| 1158 | result = this.applyScalarOrderBy(result, model, modelAlias, field, value, negated, buildFieldRef); |
| 1159 | } else { |
nothing calls this directly
no test coverage detected