@crombolo/data 0.36.2 → 0.38.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/audit.ts +163 -133
- package/src/change-report.ts +66 -43
- package/src/cluster.ts +119 -59
- package/src/content-query.ts +205 -200
- package/src/{bundle-tables → custom-tables}/builder.ts +104 -12
- package/src/custom-tables/chain.ts +150 -0
- package/src/custom-tables/ddl.ts +159 -0
- package/src/custom-tables/handle.ts +141 -0
- package/src/{bundle-tables → custom-tables}/index.ts +3 -2
- package/src/custom-tables/names.ts +94 -0
- package/src/custom-tables/owners.ts +299 -0
- package/src/{bundle-tables → custom-tables}/schema.ts +263 -90
- package/src/custom-tables/values.ts +181 -0
- package/src/database.ts +40 -5
- package/src/dialect.ts +43 -16
- package/src/index.ts +8 -1
- package/src/migrations.ts +130 -88
- package/src/query.ts +158 -0
- package/src/relations.ts +49 -28
- package/src/repositories/approvals.ts +130 -89
- package/src/repositories/bundle-grants.ts +74 -0
- package/src/repositories/bundles.ts +85 -76
- package/src/repositories/content-applied.ts +47 -28
- package/src/repositories/content-events.ts +114 -67
- package/src/repositories/content-notifications.ts +102 -74
- package/src/repositories/content-types.ts +449 -320
- package/src/repositories/data-types.ts +105 -56
- package/src/repositories/delivery-member-tokens.ts +37 -28
- package/src/repositories/dictionary.ts +77 -58
- package/src/repositories/documents.ts +956 -580
- package/src/repositories/domains.ts +28 -16
- package/src/repositories/dynamic-roots.ts +32 -17
- package/src/repositories/external-logins.ts +38 -24
- package/src/repositories/folders.ts +7 -4
- package/src/repositories/form-entries.ts +120 -103
- package/src/repositories/form-workflows.ts +87 -62
- package/src/repositories/jobs.ts +296 -0
- package/src/repositories/languages.ts +51 -38
- package/src/repositories/log-searches.ts +7 -5
- package/src/repositories/media-access.ts +173 -123
- package/src/repositories/media-listing.ts +155 -92
- package/src/repositories/members.ts +189 -162
- package/src/repositories/nodes.ts +227 -181
- package/src/repositories/notifications.ts +22 -17
- package/src/repositories/public-access.ts +77 -61
- package/src/repositories/redirects.ts +113 -70
- package/src/repositories/references.ts +55 -44
- package/src/repositories/remote-jobs.ts +45 -35
- package/src/repositories/tags.ts +11 -10
- package/src/repositories/templates.ts +24 -14
- package/src/repositories/transfer-answers.ts +58 -50
- package/src/repositories/transfer-runs.ts +93 -75
- package/src/repositories/two-factor.ts +74 -55
- package/src/repositories/user-data.ts +54 -36
- package/src/repositories/users.ts +345 -300
- package/src/repositories/webhooks.ts +196 -137
- package/src/schema/bundle-grants.ts +32 -0
- package/src/schema/jobs.ts +56 -0
- package/src/schema/plan.ts +4 -0
- package/src/schema-ops.ts +15 -12
- package/src/schema-state.ts +53 -38
- package/src/search.ts +175 -129
- package/src/setup.ts +17 -13
- package/src/site-search.ts +134 -83
- package/src/table-types.ts +152 -0
- package/src/tables.gen.ts +859 -0
- package/src/tree-invariants.ts +21 -12
- package/src/url-options.ts +17 -13
- package/src/workflow-store.ts +17 -13
- package/src/bundle-tables/capability.ts +0 -377
- package/src/bundle-tables/chain.ts +0 -105
- package/src/bundle-tables/ddl.ts +0 -124
- package/src/bundle-tables/guard.ts +0 -116
- package/src/bundle-tables/names.ts +0 -58
|
@@ -12,8 +12,10 @@
|
|
|
12
12
|
* `data` depends on nothing but types.
|
|
13
13
|
*/
|
|
14
14
|
import { normaliseUuid, ObjectTypes } from '@crombolo/core'
|
|
15
|
+
import type { SqlBool } from 'kysely'
|
|
15
16
|
import type { Db } from '../database.ts'
|
|
16
17
|
import { DbDate, fromDbBool } from '../dialect.ts'
|
|
18
|
+
import { type Expression, sql } from '../query.ts'
|
|
17
19
|
import { queueForSearch } from '../search.ts'
|
|
18
20
|
import { searchTerms } from '../search-text.ts'
|
|
19
21
|
import {
|
|
@@ -79,14 +81,16 @@ export interface MemberFilter {
|
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
/** Umbraco's `MemberFilterRepository` order columns; anything else is username. */
|
|
82
|
-
const ORDER_COLUMNS
|
|
84
|
+
const ORDER_COLUMNS = {
|
|
83
85
|
email: 'm.email',
|
|
84
86
|
name: 'n.text',
|
|
85
87
|
username: 'm.login_name',
|
|
86
88
|
isapproved: 'm.is_approved',
|
|
87
89
|
islockedout: 'm.is_locked_out',
|
|
88
90
|
lastlogindate: 'm.last_login_date',
|
|
89
|
-
}
|
|
91
|
+
} as const
|
|
92
|
+
|
|
93
|
+
type OrderColumn = (typeof ORDER_COLUMNS)[keyof typeof ORDER_COLUMNS]
|
|
90
94
|
|
|
91
95
|
interface MemberRow {
|
|
92
96
|
unique_id: string
|
|
@@ -108,13 +112,19 @@ interface MemberRow {
|
|
|
108
112
|
type_icon: string | null
|
|
109
113
|
}
|
|
110
114
|
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
const joined = (db: Db) =>
|
|
116
|
+
db.q
|
|
117
|
+
.selectFrom('member as m')
|
|
118
|
+
.innerJoin('node as n', 'n.id', 'm.node_id')
|
|
119
|
+
.innerJoin('content as c', 'c.node_id', 'm.node_id')
|
|
120
|
+
.innerJoin('content_type as ct', 'ct.node_id', 'c.content_type_id')
|
|
121
|
+
.innerJoin('node as tn', 'tn.id', 'ct.node_id')
|
|
122
|
+
|
|
123
|
+
const memberColumns = (query: ReturnType<typeof joined>) =>
|
|
124
|
+
query
|
|
125
|
+
.select(['n.unique_id', 'n.text'])
|
|
126
|
+
.selectAll('m')
|
|
127
|
+
.select(['tn.unique_id as type_key', 'ct.alias as type_alias', 'ct.icon as type_icon'])
|
|
118
128
|
|
|
119
129
|
export class MemberRepository {
|
|
120
130
|
#db: Db
|
|
@@ -128,20 +138,24 @@ export class MemberRepository {
|
|
|
128
138
|
}
|
|
129
139
|
|
|
130
140
|
async #rolesOf(nodeId: number): Promise<string[]> {
|
|
131
|
-
const rows = await this.#db.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
141
|
+
const rows = await this.#db.q
|
|
142
|
+
.selectFrom('member_group_member as mg')
|
|
143
|
+
.innerJoin('node as g', 'g.id', 'mg.member_group_id')
|
|
144
|
+
.select('g.text')
|
|
145
|
+
.where('mg.member_id', '=', nodeId)
|
|
146
|
+
.orderBy('g.text')
|
|
147
|
+
.execute()
|
|
136
148
|
return rows.map((row) => String(row.text ?? '')).filter(Boolean)
|
|
137
149
|
}
|
|
138
150
|
|
|
139
151
|
async #groupKeysOf(nodeId: number): Promise<string[]> {
|
|
140
|
-
const rows = await this.#db.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
152
|
+
const rows = await this.#db.q
|
|
153
|
+
.selectFrom('member_group_member as mg')
|
|
154
|
+
.innerJoin('node as g', 'g.id', 'mg.member_group_id')
|
|
155
|
+
.select('g.unique_id')
|
|
156
|
+
.where('mg.member_id', '=', nodeId)
|
|
157
|
+
.orderBy('g.text')
|
|
158
|
+
.execute()
|
|
145
159
|
return rows.map((row) => normaliseUuid(String(row.unique_id)))
|
|
146
160
|
}
|
|
147
161
|
|
|
@@ -169,21 +183,24 @@ export class MemberRepository {
|
|
|
169
183
|
}
|
|
170
184
|
}
|
|
171
185
|
|
|
172
|
-
async #one(
|
|
173
|
-
|
|
186
|
+
async #one(
|
|
187
|
+
column: 'n.unique_id' | 'm.login_name' | 'm.email',
|
|
188
|
+
value: string,
|
|
189
|
+
): Promise<MemberCredentials | undefined> {
|
|
190
|
+
const rows = await memberColumns(joined(this.#db)).where(column, '=', value).execute()
|
|
174
191
|
return rows[0] ? this.#hydrate(rows[0]) : undefined
|
|
175
192
|
}
|
|
176
193
|
|
|
177
194
|
byKey(key: string): Promise<MemberCredentials | undefined> {
|
|
178
|
-
return this.#one('n.unique_id
|
|
195
|
+
return this.#one('n.unique_id', normaliseUuid(key))
|
|
179
196
|
}
|
|
180
197
|
|
|
181
198
|
byUsername(username: string): Promise<MemberCredentials | undefined> {
|
|
182
|
-
return this.#one('m.login_name
|
|
199
|
+
return this.#one('m.login_name', username)
|
|
183
200
|
}
|
|
184
201
|
|
|
185
202
|
byEmail(email: string): Promise<MemberCredentials | undefined> {
|
|
186
|
-
return this.#one('m.email
|
|
203
|
+
return this.#one('m.email', email)
|
|
187
204
|
}
|
|
188
205
|
|
|
189
206
|
/** The group keys a member belongs to, for the editor's Groups picker. */
|
|
@@ -195,10 +212,12 @@ export class MemberRepository {
|
|
|
195
212
|
/** Whether a username or an e-mail is taken by anyone other than `exceptKey`. */
|
|
196
213
|
async taken(field: 'username' | 'email', value: string, exceptKey?: string): Promise<boolean> {
|
|
197
214
|
const column = field === 'username' ? 'm.login_name' : 'm.email'
|
|
198
|
-
const rows = await this.#db.
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
215
|
+
const rows = await this.#db.q
|
|
216
|
+
.selectFrom('member as m')
|
|
217
|
+
.innerJoin('node as n', 'n.id', 'm.node_id')
|
|
218
|
+
.select('n.unique_id')
|
|
219
|
+
.where(column, '=', value)
|
|
220
|
+
.execute()
|
|
202
221
|
return rows.some(
|
|
203
222
|
(row) => !exceptKey || normaliseUuid(String(row.unique_id)) !== normaliseUuid(exceptKey),
|
|
204
223
|
)
|
|
@@ -212,14 +231,14 @@ export class MemberRepository {
|
|
|
212
231
|
}
|
|
213
232
|
|
|
214
233
|
async #writeGroups(nodeId: number, groupKeys: readonly string[]): Promise<void> {
|
|
215
|
-
await this.#db.
|
|
234
|
+
await this.#db.q.deleteFrom('member_group_member').where('member_id', '=', nodeId).execute()
|
|
216
235
|
for (const key of groupKeys) {
|
|
217
236
|
const group = await this.#nodes.byKey(key)
|
|
218
237
|
if (!group || group.objectType !== ObjectTypes.MemberGroup) continue
|
|
219
|
-
await this.#db.
|
|
220
|
-
'
|
|
221
|
-
|
|
222
|
-
|
|
238
|
+
await this.#db.q
|
|
239
|
+
.insertInto('member_group_member')
|
|
240
|
+
.values({ member_id: nodeId, member_group_id: group.id })
|
|
241
|
+
.execute()
|
|
223
242
|
}
|
|
224
243
|
}
|
|
225
244
|
|
|
@@ -232,24 +251,21 @@ export class MemberRepository {
|
|
|
232
251
|
const node = await this.#nodes.byKey(created.key)
|
|
233
252
|
if (!node) throw new Error(`the member node ${created.key} vanished while being created`)
|
|
234
253
|
const now = new Date()
|
|
235
|
-
await this.#db.
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
identity.
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
identity.
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
identity.passwordHash ? DbDate.toDb(now) : null,
|
|
251
|
-
],
|
|
252
|
-
)
|
|
254
|
+
await this.#db.q
|
|
255
|
+
.insertInto('member')
|
|
256
|
+
.values({
|
|
257
|
+
node_id: node.id,
|
|
258
|
+
email: identity.email,
|
|
259
|
+
login_name: identity.username,
|
|
260
|
+
password: identity.passwordHash ?? null,
|
|
261
|
+
password_config: identity.passwordConfig ?? null,
|
|
262
|
+
security_stamp_token: crypto.randomUUID(),
|
|
263
|
+
failed_password_attempts: 0,
|
|
264
|
+
is_locked_out: this.#db.dialect.boolValue(identity.isLockedOut) as boolean | number,
|
|
265
|
+
is_approved: this.#db.dialect.boolValue(identity.isApproved) as boolean | number,
|
|
266
|
+
last_password_change_date: identity.passwordHash ? DbDate.toDb(now) : null,
|
|
267
|
+
})
|
|
268
|
+
.execute()
|
|
253
269
|
await this.#writeGroups(node.id, identity.groupKeys ?? [])
|
|
254
270
|
// Again, now the e-mail and username it is found by are written.
|
|
255
271
|
await queueForSearch(this.#db, [node.id])
|
|
@@ -272,35 +288,25 @@ export class MemberRepository {
|
|
|
272
288
|
const updated = await this.content.update({ ...content, key, componentKey: null })
|
|
273
289
|
if (!updated) return undefined
|
|
274
290
|
const now = new Date()
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
)
|
|
293
|
-
|
|
294
|
-
identity.passwordHash,
|
|
295
|
-
identity.passwordConfig ?? null,
|
|
296
|
-
DbDate.toDb(now),
|
|
297
|
-
crypto.randomUUID(),
|
|
298
|
-
)
|
|
299
|
-
}
|
|
300
|
-
await this.#db.exec(`UPDATE member SET ${sets.join(', ')} WHERE node_id = ?`, [
|
|
301
|
-
...values,
|
|
302
|
-
node.id,
|
|
303
|
-
])
|
|
291
|
+
await this.#db.q
|
|
292
|
+
.updateTable('member')
|
|
293
|
+
.set({
|
|
294
|
+
email: identity.email,
|
|
295
|
+
login_name: identity.username,
|
|
296
|
+
is_approved: this.#db.dialect.boolValue(identity.isApproved) as boolean | number,
|
|
297
|
+
is_locked_out: this.#db.dialect.boolValue(identity.isLockedOut) as boolean | number,
|
|
298
|
+
...(identity.isLockedOut ? {} : { failed_password_attempts: 0 }),
|
|
299
|
+
...(identity.passwordHash
|
|
300
|
+
? {
|
|
301
|
+
password: identity.passwordHash,
|
|
302
|
+
password_config: identity.passwordConfig ?? null,
|
|
303
|
+
last_password_change_date: DbDate.toDb(now),
|
|
304
|
+
security_stamp_token: crypto.randomUUID(),
|
|
305
|
+
}
|
|
306
|
+
: {}),
|
|
307
|
+
})
|
|
308
|
+
.where('node_id', '=', node.id)
|
|
309
|
+
.execute()
|
|
304
310
|
await queueForSearch(this.#db, [node.id])
|
|
305
311
|
if (identity.groupKeys) await this.#writeGroups(node.id, identity.groupKeys)
|
|
306
312
|
return this.byKey(key)
|
|
@@ -312,19 +318,23 @@ export class MemberRepository {
|
|
|
312
318
|
* password is the same, so the security stamp and change date stand.
|
|
313
319
|
*/
|
|
314
320
|
async rehashPassword(key: string, passwordHash: string, passwordConfig: string): Promise<void> {
|
|
315
|
-
await this.#db.
|
|
316
|
-
'
|
|
317
|
-
|
|
318
|
-
|
|
321
|
+
await this.#db.q
|
|
322
|
+
.updateTable('member')
|
|
323
|
+
.set({ password: passwordHash, password_config: passwordConfig })
|
|
324
|
+
.where('node_id', '=', (eb) =>
|
|
325
|
+
eb.selectFrom('node').select('id').where('unique_id', '=', normaliseUuid(key)),
|
|
326
|
+
)
|
|
327
|
+
.execute()
|
|
319
328
|
}
|
|
320
329
|
|
|
321
330
|
async recordLogin(key: string): Promise<void> {
|
|
322
331
|
const node = await this.#nodes.byKey(key)
|
|
323
332
|
if (!node) return
|
|
324
|
-
await this.#db.
|
|
325
|
-
'
|
|
326
|
-
|
|
327
|
-
|
|
333
|
+
await this.#db.q
|
|
334
|
+
.updateTable('member')
|
|
335
|
+
.set({ last_login_date: DbDate.toDb(new Date()), failed_password_attempts: 0 })
|
|
336
|
+
.where('node_id', '=', node.id)
|
|
337
|
+
.execute()
|
|
328
338
|
}
|
|
329
339
|
|
|
330
340
|
/**
|
|
@@ -334,95 +344,112 @@ export class MemberRepository {
|
|
|
334
344
|
async recordFailedLogin(key: string, maxAttempts: number): Promise<{ lockedOut: boolean }> {
|
|
335
345
|
const node = await this.#nodes.byKey(key)
|
|
336
346
|
if (!node) return { lockedOut: false }
|
|
337
|
-
const
|
|
338
|
-
'
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
347
|
+
const row = await this.#db.q
|
|
348
|
+
.selectFrom('member')
|
|
349
|
+
.select('failed_password_attempts')
|
|
350
|
+
.where('node_id', '=', node.id)
|
|
351
|
+
.executeTakeFirst()
|
|
352
|
+
const attempts = Number(row?.failed_password_attempts ?? 0) + 1
|
|
342
353
|
const lockedOut = maxAttempts > 0 && attempts >= maxAttempts
|
|
343
|
-
await this.#db.
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
:
|
|
349
|
-
|
|
354
|
+
await this.#db.q
|
|
355
|
+
.updateTable('member')
|
|
356
|
+
.set({
|
|
357
|
+
failed_password_attempts: attempts,
|
|
358
|
+
is_locked_out: this.#db.dialect.boolValue(lockedOut) as boolean | number,
|
|
359
|
+
...(lockedOut ? { last_lockout_date: DbDate.toDb(new Date()) } : {}),
|
|
360
|
+
})
|
|
361
|
+
.where('node_id', '=', node.id)
|
|
362
|
+
.execute()
|
|
350
363
|
return { lockedOut }
|
|
351
364
|
}
|
|
352
365
|
|
|
353
366
|
async delete(key: string): Promise<boolean> {
|
|
354
367
|
const node = await this.#nodes.byKey(key)
|
|
355
368
|
if (!node || node.objectType !== ObjectTypes.Member) return false
|
|
356
|
-
|
|
357
|
-
await
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
await
|
|
369
|
+
const q = this.#db.q
|
|
370
|
+
await q.deleteFrom('member_group_member').where('member_id', '=', node.id).execute()
|
|
371
|
+
await q
|
|
372
|
+
.deleteFrom('external_login_token')
|
|
373
|
+
.where('external_login_id', 'in', (eb) =>
|
|
374
|
+
eb.selectFrom('external_login').select('id').where('user_or_member_key', '=', node.key),
|
|
375
|
+
)
|
|
376
|
+
.execute()
|
|
377
|
+
await q.deleteFrom('external_login').where('user_or_member_key', '=', node.key).execute()
|
|
378
|
+
await q.deleteFrom('two_factor_login').where('owner_key', '=', node.key).execute()
|
|
379
|
+
await q.deleteFrom('two_factor_recovery_code').where('owner_key', '=', node.key).execute()
|
|
380
|
+
await q.deleteFrom('member').where('node_id', '=', node.id).execute()
|
|
365
381
|
return this.content.delete(key)
|
|
366
382
|
}
|
|
367
383
|
|
|
368
384
|
/** The Members collection: Umbraco's member filter, with the same columns and defaults. */
|
|
369
385
|
async filter(criteria: MemberFilter): Promise<{ total: number; items: MemberCredentials[] }> {
|
|
370
|
-
const
|
|
371
|
-
const values: unknown[] = []
|
|
372
|
-
if (criteria.memberTypeKey) {
|
|
373
|
-
wheres.push('tn.unique_id = ?')
|
|
374
|
-
values.push(normaliseUuid(criteria.memberTypeKey))
|
|
375
|
-
}
|
|
376
|
-
if (criteria.isApproved !== undefined) {
|
|
377
|
-
wheres.push('m.is_approved = ?')
|
|
378
|
-
values.push(this.#db.dialect.boolValue(criteria.isApproved))
|
|
379
|
-
}
|
|
380
|
-
if (criteria.isLockedOut !== undefined) {
|
|
381
|
-
wheres.push('m.is_locked_out = ?')
|
|
382
|
-
values.push(this.#db.dialect.boolValue(criteria.isLockedOut))
|
|
383
|
-
}
|
|
384
|
-
if (criteria.memberGroupName) {
|
|
385
|
-
wheres.push(
|
|
386
|
-
`EXISTS (SELECT 1 FROM member_group_member mg JOIN node g ON g.id = mg.member_group_id
|
|
387
|
-
WHERE mg.member_id = m.node_id AND g.text = ?)`,
|
|
388
|
-
)
|
|
389
|
-
values.push(criteria.memberGroupName)
|
|
390
|
-
}
|
|
386
|
+
const db = this.#db
|
|
391
387
|
const text = criteria.filter?.trim()
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
const
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
388
|
+
const terms = text ? searchTerms(text) : []
|
|
389
|
+
const base = joined(db).where((eb) => {
|
|
390
|
+
const all: Expression<SqlBool>[] = []
|
|
391
|
+
if (criteria.memberTypeKey)
|
|
392
|
+
all.push(eb('tn.unique_id', '=', normaliseUuid(criteria.memberTypeKey)))
|
|
393
|
+
if (criteria.isApproved !== undefined)
|
|
394
|
+
all.push(
|
|
395
|
+
eb('m.is_approved', '=', db.dialect.boolValue(criteria.isApproved) as boolean | number),
|
|
396
|
+
)
|
|
397
|
+
if (criteria.isLockedOut !== undefined)
|
|
398
|
+
all.push(
|
|
399
|
+
eb(
|
|
400
|
+
'm.is_locked_out',
|
|
401
|
+
'=',
|
|
402
|
+
db.dialect.boolValue(criteria.isLockedOut) as boolean | number,
|
|
403
|
+
),
|
|
404
|
+
)
|
|
405
|
+
if (criteria.memberGroupName)
|
|
406
|
+
all.push(
|
|
407
|
+
eb.exists(
|
|
408
|
+
eb
|
|
409
|
+
.selectFrom('member_group_member as mg')
|
|
410
|
+
.innerJoin('node as g', 'g.id', 'mg.member_group_id')
|
|
411
|
+
.select(sql<number>`1`.as('one'))
|
|
412
|
+
.whereRef('mg.member_id', '=', 'm.node_id')
|
|
413
|
+
.where('g.text', '=', criteria.memberGroupName),
|
|
414
|
+
),
|
|
415
|
+
)
|
|
416
|
+
if (text) {
|
|
417
|
+
const like = `%${text.toLowerCase()}%`
|
|
418
|
+
const any: Expression<SqlBool>[] = [
|
|
419
|
+
eb(eb.fn('lower', ['m.email']), 'like', like),
|
|
420
|
+
eb(eb.fn('lower', ['m.login_name']), 'like', like),
|
|
421
|
+
eb(eb.fn('lower', ['n.text']), 'like', like),
|
|
422
|
+
]
|
|
423
|
+
// The index adds what a member's properties say to the name, username and e-mail.
|
|
424
|
+
if (terms.length > 0)
|
|
425
|
+
any.push(
|
|
426
|
+
eb(
|
|
427
|
+
'm.node_id',
|
|
428
|
+
'in',
|
|
429
|
+
eb
|
|
430
|
+
.selectFrom(db.dialect.fullTextMatches(db.dialect.fullTextQuery(terms)).as('h'))
|
|
431
|
+
.select(sql<number>`node_id`.as('node_id')),
|
|
432
|
+
),
|
|
433
|
+
)
|
|
434
|
+
all.push(eb.or(any))
|
|
435
|
+
}
|
|
436
|
+
return eb.and(all)
|
|
437
|
+
})
|
|
438
|
+
const order: OrderColumn =
|
|
439
|
+
ORDER_COLUMNS[(criteria.orderBy ?? '').toLowerCase() as keyof typeof ORDER_COLUMNS] ??
|
|
440
|
+
ORDER_COLUMNS.username
|
|
441
|
+
const direction = criteria.orderDirection === 'Descending' ? 'desc' : 'asc'
|
|
442
|
+
|
|
443
|
+
const counted = await base.select(sql<number>`count(*)`.as('total')).executeTakeFirst()
|
|
444
|
+
const rows = await memberColumns(base)
|
|
445
|
+
.orderBy(order, direction)
|
|
446
|
+
.orderBy('n.id')
|
|
447
|
+
.limit(criteria.take)
|
|
448
|
+
.offset(criteria.skip)
|
|
449
|
+
.execute()
|
|
423
450
|
const items = []
|
|
424
451
|
for (const row of rows) items.push(await this.#hydrate(row))
|
|
425
|
-
return { total: Number(counted
|
|
452
|
+
return { total: Number(counted?.total ?? 0), items }
|
|
426
453
|
}
|
|
427
454
|
|
|
428
455
|
/** The member picker's search: name, username or e-mail, within the types allowed. */
|