mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-10-18 23:17:39 +02:00
feat(db): add role log table to database
This commit is contained in:
parent
873afcd4d6
commit
232cbc4b67
29
prisma/migrations/20230303182446_role_logs/migration.sql
Normal file
29
prisma/migrations/20230303182446_role_logs/migration.sql
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "RoleLog" (
|
||||||
|
"id" SERIAL NOT NULL,
|
||||||
|
"userId" TEXT NOT NULL,
|
||||||
|
"modId" TEXT NOT NULL,
|
||||||
|
"roleId" TEXT NOT NULL,
|
||||||
|
"add" BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
"time" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
|
||||||
|
CONSTRAINT "RoleLog_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "Role" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"name" TEXT NOT NULL,
|
||||||
|
"staff" BOOLEAN NOT NULL,
|
||||||
|
|
||||||
|
CONSTRAINT "Role_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "RoleLog" ADD CONSTRAINT "RoleLog_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "RoleLog" ADD CONSTRAINT "RoleLog_modId_fkey" FOREIGN KEY ("modId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "RoleLog" ADD CONSTRAINT "RoleLog_roleId_fkey" FOREIGN KEY ("roleId") REFERENCES "Role"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
@ -42,6 +42,8 @@ model User {
|
|||||||
SendPayment Payment[] @relation("sendPayment")
|
SendPayment Payment[] @relation("sendPayment")
|
||||||
RecievePayment Payment[] @relation("recievePayment")
|
RecievePayment Payment[] @relation("recievePayment")
|
||||||
LeaveLog LeaveLog[]
|
LeaveLog LeaveLog[]
|
||||||
|
UserRoleLog RoleLog[] @relation("userRoleLog")
|
||||||
|
ModRoleLog RoleLog[] @relation("modRoleLog")
|
||||||
EventLeader Event[] @relation("eventLeader")
|
EventLeader Event[] @relation("eventLeader")
|
||||||
StatLeader Stat[] @relation("statLeader")
|
StatLeader Stat[] @relation("statLeader")
|
||||||
OutreachParticipation ParticipantStat[] @relation("participantUser")
|
OutreachParticipation ParticipantStat[] @relation("participantUser")
|
||||||
@ -129,6 +131,25 @@ model LeaveLog {
|
|||||||
roles String[]
|
roles String[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model RoleLog {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
user User @relation("userRoleLog", fields: [userId], references: [id])
|
||||||
|
userId String
|
||||||
|
mod User @relation("modRoleLog", fields: [modId], references: [id])
|
||||||
|
modId String
|
||||||
|
role Role @relation(fields: [roleId], references: [id])
|
||||||
|
roleId String
|
||||||
|
add Boolean @default(false)
|
||||||
|
time DateTime @default(now())
|
||||||
|
}
|
||||||
|
|
||||||
|
model Role {
|
||||||
|
id String @id
|
||||||
|
name String
|
||||||
|
staff Boolean
|
||||||
|
RoleLog RoleLog[]
|
||||||
|
}
|
||||||
|
|
||||||
// Outreach
|
// Outreach
|
||||||
|
|
||||||
model Event {
|
model Event {
|
||||||
|
66
src/utils/logging/role.ts
Normal file
66
src/utils/logging/role.ts
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import { container } from '@sapphire/framework';
|
||||||
|
import type { Snowflake, Role } from 'discord.js';
|
||||||
|
|
||||||
|
export async function roleLog(
|
||||||
|
userId: Snowflake,
|
||||||
|
modId: Snowflake,
|
||||||
|
role: Role,
|
||||||
|
staffRole : boolean,
|
||||||
|
add: boolean,
|
||||||
|
) {
|
||||||
|
await container.database.roleLog.create({
|
||||||
|
data: {
|
||||||
|
user: {
|
||||||
|
connectOrCreate: {
|
||||||
|
where: {
|
||||||
|
id: userId,
|
||||||
|
},
|
||||||
|
create: {
|
||||||
|
id: userId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
mod: {
|
||||||
|
connectOrCreate: {
|
||||||
|
where: {
|
||||||
|
id: modId,
|
||||||
|
},
|
||||||
|
create: {
|
||||||
|
id: modId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
role: {
|
||||||
|
connectOrCreate: {
|
||||||
|
where: {
|
||||||
|
id: role.id,
|
||||||
|
},
|
||||||
|
create: {
|
||||||
|
id: role.id,
|
||||||
|
name: role.name,
|
||||||
|
staff: staffRole,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
add,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function roleAddLog(
|
||||||
|
userId: Snowflake,
|
||||||
|
modId: Snowflake,
|
||||||
|
role: Role,
|
||||||
|
staffRole = false,
|
||||||
|
) {
|
||||||
|
await roleLog(userId, modId, role, staffRole, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function roleRemoveLog(
|
||||||
|
userId: Snowflake,
|
||||||
|
modId: Snowflake,
|
||||||
|
role: Role,
|
||||||
|
staffRole = false,
|
||||||
|
) {
|
||||||
|
await roleLog(userId, modId, role, staffRole, false);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user