📦 EqualifyEverything / equalify

📄 audits.ts · 19 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19import { db, event, sleep } from "#src/utils";

export const audits = async () => {
    const { op, data: { new: { id, created_at, user_id } } } = event?.body?.event;

    if (['INSERT'].includes(op)) {
        await db.connect();
        await sleep(10000);
        const audit = (await db.query(`SELECT "name" FROM "audits" WHERE "id"=$1`, [id])).rows[0];
        const message = `${audit.name} added`
        await db.query({
            text: `INSERT INTO "logs" ("user_id","audit_id","message") VALUES ($1, $2, $3)`,
            values: [user_id, id, message],
        });
        await db.clean();
    }

    return;
}