feat(arabot): add stat role to separate table

This commit is contained in:
smyalygames 2023-02-28 20:11:58 +00:00
parent 3baa0e2081
commit da8088e157
3 changed files with 68 additions and 21 deletions

View File

@ -104,18 +104,25 @@ model EventType {
}
model Stat {
id Int @id @default(autoincrement())
event Event @relation(fields: [eventId], references: [id])
eventId Int
leader User @relation("statLeader", fields: [leaderId], references: [id]) // Not sure if this will stay
leaderId String
vegan Int @default(0)
considered Int @default(0)
antivegan Int @default(0)
thanked Int @default(0)
documentary Int @default(0)
educated Int @default(0)
participationStats ParticipantStat[]
id Int @id @default(autoincrement())
event Event @relation(fields: [eventId], references: [id])
eventId Int
leader User @relation("statLeader", fields: [leaderId], references: [id]) // Not sure if this will stay
leaderId String
vegan Int @default(0)
considered Int @default(0)
antivegan Int @default(0)
thanked Int @default(0)
documentary Int @default(0)
educated Int @default(0)
participants ParticipantStat[]
role StatRole[]
}
model StatRole {
stat Stat @relation(fields: [statId], references: [id])
statId Int @id
roleId String
}
model ParticipantStat {

View File

@ -24,7 +24,7 @@ import {
checkActiveEvent,
createEvent,
createStat,
getCurrentEvent,
getCurrentEvent, getStatGroups,
} from '#utils/database/outreach';
export class OutreachCommand extends Subcommand {
@ -144,18 +144,33 @@ export class OutreachCommand extends Subcommand {
public async groupCreate(interaction: Subcommand.ChatInputCommandInteraction) {
const leader = interaction.options.getUser('leader', true);
const { guild } = interaction;
const event = await getCurrentEvent();
if (event === null) {
if (guild === null) {
await interaction.reply({
content: 'There is no current event!',
content: 'Guild not found!',
ephemeral: true,
});
return;
}
await createStat(event.id, leader.id);
await interaction.deferReply({ ephemeral: true });
const event = await getCurrentEvent();
if (event === null) {
await interaction.editReply({
content: 'There is no current event!',
});
return;
}
const statGroups = await getStatGroups(event.id);
const groupNo = statGroups.length + 1;
const role = await guild.roles.create({ name: `Outreach Group ${groupNo}` });
await createStat(event.id, leader.id, role.id);
await interaction.reply({
content: `Created a group with the leader being ${leader}`,

View File

@ -62,8 +62,8 @@ export async function addStatUser(statId: number, userId: Snowflake) {
});
}
export async function createStat(eventId: number, leaderId: Snowflake) {
const stat = await container.database.stat.create({
export async function createStat(eventId: number, leaderId: Snowflake, roleId: Snowflake) {
await container.database.stat.create({
data: {
event: {
connect: {
@ -75,10 +75,35 @@ export async function createStat(eventId: number, leaderId: Snowflake) {
id: leaderId,
},
},
participants: {
create: {
user: {
connect: {
id: leaderId,
},
},
},
},
role: {
create: {
roleId,
},
},
},
});
}
export async function getStatGroups(eventId: number) {
const stats = await container.database.stat.findMany({
where: {
eventId,
},
orderBy: {
id: 'asc',
},
});
await addStatUser(stat.id, leaderId);
return stats;
}
// Misc