-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.ts
More file actions
35 lines (28 loc) · 854 Bytes
/
database.ts
File metadata and controls
35 lines (28 loc) · 854 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
import { MongoClient } from "mongo";
import config from "$env";
console.log("Connecting to MongoDB...");
const client = new MongoClient();
const MONGO_URL = new URL(config.MONGO_URI);
if (!MONGO_URL.searchParams.has("authMechanism")) {
MONGO_URL.searchParams.set("authMechanism", "SCRAM-SHA-1");
}
try {
await client.connect(MONGO_URL.href);
} catch (err) {
console.error("Error connecting to MongoDB", err);
throw err;
}
const db = client.database("INCEPTRA-ATTENDANCE");
interface AttendanceSchema {
agentID: string;
}
const attendance = db.collection<AttendanceSchema>("attendance");
async function addAgent(agentID: string) {
console.log(await attendance.find({}).toArray());
if (!(await attendance.findOne({ agentID }))) {
await attendance.insertOne({ agentID });
return true;
}
return false;
}
export { addAgent };