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.ts20
1 files changed, 17 insertions, 3 deletions
diff --git a/server/models/utils.ts b/server/models/utils.ts
index 30de91e1d..24890f961 100644
--- a/server/models/utils.ts
+++ b/server/models/utils.ts
@@ -1,7 +1,7 @@
1import { Model, Sequelize } from 'sequelize-typescript' 1import { Model, Sequelize } from 'sequelize-typescript'
2import * as validator from 'validator' 2import * as validator from 'validator'
3import { Col } from 'sequelize/types/lib/utils' 3import { Col } from 'sequelize/types/lib/utils'
4import { OrderItem } from 'sequelize/types' 4import { OrderItem, literal } from 'sequelize'
5 5
6type SortType = { sortModel: any, sortValue: string } 6type SortType = { sortModel: any, sortValue: string }
7 7
@@ -129,16 +129,30 @@ function parseAggregateResult (result: any) {
129 return total 129 return total
130} 130}
131 131
132const createSafeIn = (model: typeof Model, stringArr: string[]) => { 132const createSafeIn = (model: typeof Model, stringArr: (string | number)[]) => {
133 return stringArr.map(t => model.sequelize.escape(t)) 133 return stringArr.map(t => model.sequelize.escape('' + t))
134 .join(', ') 134 .join(', ')
135} 135}
136 136
137function buildLocalAccountIdsIn () {
138 return literal(
139 '(SELECT "account"."id" FROM "account" INNER JOIN "actor" ON "actor"."id" = "account"."actorId" AND "actor"."serverId" IS NULL)'
140 )
141}
142
143function buildLocalActorIdsIn () {
144 return literal(
145 '(SELECT "actor"."id" FROM "actor" WHERE "actor"."serverId" IS NULL)'
146 )
147}
148
137// --------------------------------------------------------------------------- 149// ---------------------------------------------------------------------------
138 150
139export { 151export {
140 buildBlockedAccountSQL, 152 buildBlockedAccountSQL,
153 buildLocalActorIdsIn,
141 SortType, 154 SortType,
155 buildLocalAccountIdsIn,
142 getSort, 156 getSort,
143 getVideoSort, 157 getVideoSort,
144 getSortOnModel, 158 getSortOnModel,