feat(db): add role log table to database

This commit is contained in:
smyalygames
2023-03-03 17:59:02 +00:00
parent 873afcd4d6
commit 232cbc4b67
3 changed files with 116 additions and 0 deletions

66
src/utils/logging/role.ts Normal file
View 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);
}