-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.ts
39 lines (32 loc) · 1022 Bytes
/
db.ts
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
37
38
39
import { Collection, MongoClient } from "mongo/mod.ts";
import env from "./env.ts";
export interface Notification {
prNumber: number;
messageId: number;
text: string;
}
export const client = new MongoClient();
let notifications: Collection<Notification>;
export async function connect() {
const database = await client.connect(env.MONGODB_URI);
notifications = database.collection("notifications");
}
export function createNotification(
prNumber: number,
messageId: number,
text: string,
) {
return notifications.updateOne({ prNumber, messageId }, { $set: { text } }, {
upsert: true,
});
}
export function getNotification(prNumber: number) {
return notifications.findOne({ prNumber });
}
export async function updateNotification(messageId: number, text: string) {
return (await notifications.updateOne({ messageId }, { $set: { text } }))
.modifiedCount > 0;
}
export async function deleteNotification(prNumber: number) {
return (await notifications.deleteOne({ prNumber })) > 0;
}