-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathusersDb.ts
More file actions
29 lines (24 loc) · 778 Bytes
/
usersDb.ts
File metadata and controls
29 lines (24 loc) · 778 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
import { db } from "./connect.ts";
import { UserSchema } from "../core/interfaces.ts";
export const users = db.collection<UserSchema>("BOTUSERS");
export async function addUser(userId: number) {
const user = await users.findOne({ userID: userId });
if (user) return;
await users.insertOne({ userID: userId });
}
export async function removeUser(userId: number) {
const user = await users.findOne({ userID: userId });
if (!user) return;
await users.deleteOne({ userID: userId });
}
export async function countUsers() {
const count = await users.countDocuments({ userID: { $ne: 0 } });
return count;
}
export async function addAll(usrs: number[]) {
const a = [];
for (const user of usrs) {
a.push({ userID: user });
}
await users.insertMany(a);
}