forked from hplush/slowreader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers.ts
More file actions
36 lines (33 loc) · 921 Bytes
/
users.ts
File metadata and controls
36 lines (33 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import type { BaseServer } from '@logux/server'
import { deleteUser } from '@slowreader/api'
import { eq } from 'drizzle-orm'
import { actions, db, sessions, users } from '../db/index.ts'
async function deleteUserData(
server: BaseServer,
userId: string
): Promise<void> {
await db.transaction(async tx => {
await Promise.all([
tx.delete(sessions).where(eq(sessions.userId, userId)),
tx.delete(actions).where(eq(actions.userId, userId))
])
await tx.delete(users).where(eq(users.id, userId))
})
let clients = server.userIds.get(userId)
if (clients) {
for (let client of clients) client.destroy()
}
}
export default (server: BaseServer): void => {
server.type(deleteUser, {
access() {
return true
},
process(ctx) {
/* node:coverage ignore next 3 */
deleteUserData(server, ctx.userId).catch((e: unknown) => {
throw e
})
}
})
}