aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/utils.ts')
-rw-r--r--server/models/utils.ts38
1 files changed, 21 insertions, 17 deletions
diff --git a/server/models/utils.ts b/server/models/utils.ts
index f7afb8d4b..674ddcbe4 100644
--- a/server/models/utils.ts
+++ b/server/models/utils.ts
@@ -156,8 +156,11 @@ function parseAggregateResult (result: any) {
156} 156}
157 157
158const createSafeIn = (model: typeof Model, stringArr: (string | number)[]) => { 158const createSafeIn = (model: typeof Model, stringArr: (string | number)[]) => {
159 return stringArr.map(t => model.sequelize.escape('' + t)) 159 return stringArr.map(t => {
160 .join(', ') 160 return t === null
161 ? null
162 : model.sequelize.escape('' + t)
163 }).join(', ')
161} 164}
162 165
163function buildLocalAccountIdsIn () { 166function buildLocalAccountIdsIn () {
@@ -172,6 +175,21 @@ function buildLocalActorIdsIn () {
172 ) 175 )
173} 176}
174 177
178function buildDirectionAndField (value: string) {
179 let field: string
180 let direction: 'ASC' | 'DESC'
181
182 if (value.substring(0, 1) === '-') {
183 direction = 'DESC'
184 field = value.substring(1)
185 } else {
186 direction = 'ASC'
187 field = value
188 }
189
190 return { direction, field }
191}
192
175// --------------------------------------------------------------------------- 193// ---------------------------------------------------------------------------
176 194
177export { 195export {
@@ -191,6 +209,7 @@ export {
191 isOutdated, 209 isOutdated,
192 parseAggregateResult, 210 parseAggregateResult,
193 getFollowsSort, 211 getFollowsSort,
212 buildDirectionAndField,
194 createSafeIn 213 createSafeIn
195} 214}
196 215
@@ -203,18 +222,3 @@ function searchTrigramNormalizeValue (value: string) {
203function searchTrigramNormalizeCol (col: string) { 222function searchTrigramNormalizeCol (col: string) {
204 return Sequelize.fn('lower', Sequelize.fn('immutable_unaccent', Sequelize.col(col))) 223 return Sequelize.fn('lower', Sequelize.fn('immutable_unaccent', Sequelize.col(col)))
205} 224}
206
207function buildDirectionAndField (value: string) {
208 let field: string
209 let direction: 'ASC' | 'DESC'
210
211 if (value.substring(0, 1) === '-') {
212 direction = 'DESC'
213 field = value.substring(1)
214 } else {
215 direction = 'ASC'
216 field = value
217 }
218
219 return { direction, field }
220}