Skip to content

Commit 5e70c8e

Browse files
committed
feat: one collection, updating course after button press
1 parent f9a00d2 commit 5e70c8e

4 files changed

Lines changed: 87 additions & 17 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the `VerifyData` table. If the table is not empty, all the data it contains will be lost.
5+
6+
*/
7+
-- DropTable
8+
DROP TABLE "VerifyData";
9+
10+
-- CreateTable
11+
CREATE TABLE "verifyData" (
12+
"discordId" VARCHAR(18) NOT NULL,
13+
"ID" SERIAL NOT NULL,
14+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
15+
"realName" TEXT NOT NULL,
16+
17+
CONSTRAINT "verifyData_pkey" PRIMARY KEY ("ID")
18+
);
19+
20+
-- CreateTable
21+
CREATE TABLE "studentData" (
22+
"discordId" VARCHAR(18) NOT NULL,
23+
"realName" TEXT NOT NULL,
24+
"course" TEXT NOT NULL,
25+
"ID" SERIAL NOT NULL,
26+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
27+
28+
CONSTRAINT "studentData_pkey" PRIMARY KEY ("ID")
29+
);
30+
31+
-- CreateIndex
32+
CREATE UNIQUE INDEX "verifyData_discordId_key" ON "verifyData"("discordId");
33+
34+
-- CreateIndex
35+
CREATE UNIQUE INDEX "studentData_discordId_key" ON "studentData"("discordId");
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the `verifyData` table. If the table is not empty, all the data it contains will be lost.
5+
6+
*/
7+
-- AlterTable
8+
ALTER TABLE "studentData" ALTER COLUMN "course" DROP NOT NULL;
9+
10+
-- DropTable
11+
DROP TABLE "verifyData";

prisma/schema.prisma

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ datasource db {
1010
url = env("DATABASE_URL")
1111
}
1212

13-
model VerifyData {
13+
model studentData {
1414
discordId String @unique @db.VarChar(18)
15+
realName String
16+
course String?
1517
ID Int @id @default(autoincrement())
1618
createdAt DateTime @default(now())
17-
realName String
1819
}

src/commands/verify.ts

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ const prisma = new PrismaClient();
2222

2323
@Discord()
2424
export class Command {
25-
name: string;
26-
27-
constructor(name: string) {
28-
this.name = name;
29-
}
30-
3125
@Slash({
3226
name: "verify",
3327
description: "Verify yourself and join Leagues of Code!",
@@ -42,8 +36,6 @@ export class Command {
4236
name: string | undefined,
4337
interaction: CommandInteraction
4438
): Promise<void> {
45-
this.name = name!;
46-
4739
await interaction.deferReply({ ephemeral: true });
4840

4941
// Class Buttons
@@ -67,7 +59,7 @@ export class Command {
6759
);
6860

6961
// Save / Updatename to DB
70-
const upsertVerify = await prisma.verifyData.upsert({
62+
const upsertVerify = await prisma.studentData.upsert({
7163
where: {
7264
discordId: interaction.user.id,
7365
},
@@ -90,19 +82,50 @@ export class Command {
9082
}
9183

9284
// Events after button press
85+
// Clear this repeating junk
9386
@ButtonComponent({ id: "python" })
94-
PythonButton(interaction: ButtonInteraction): void {
95-
interaction.reply({
87+
async PythonButton(interaction: ButtonInteraction): Promise<void> {
88+
const getData = await prisma.studentData.findUnique({
89+
where: {
90+
discordId: interaction.user.id,
91+
},
92+
});
93+
94+
await interaction.reply({
9695
ephemeral: true,
97-
content: `***${this.name}***, you've sent a verification request of **Python**<:python:1025584887337590834>! ${interaction.member}\nWait for an admin to approve your request.`,
96+
content: `***${getData?.realName}***, you've sent a verification request of **Python**<:python:1025584887337590834>! ${interaction.member}\nWait for an admin to approve your request.`,
97+
});
98+
99+
await prisma.studentData.update({
100+
where: {
101+
discordId: interaction.user.id,
102+
},
103+
data: {
104+
course: "Python",
105+
},
98106
});
99107
}
100108

101109
@ButtonComponent({ id: "cplus" })
102-
CplusButton(interaction: ButtonInteraction): void {
103-
interaction.reply({
110+
async CplusButton(interaction: ButtonInteraction): Promise<void> {
111+
const getData = await prisma.studentData.findUnique({
112+
where: {
113+
discordId: interaction.user.id,
114+
},
115+
});
116+
117+
await interaction.reply({
104118
ephemeral: true,
105-
content: `***${this.name}***, you've sent a verification request of **C++**<:cplus:1025584885034913802>! ${interaction.member}\nWait for an admin to approve your request.`,
119+
content: `***${getData?.realName}***, you've sent a verification request of **C++**<:cplus:1025584885034913802>! ${interaction.member}\nWait for an admin to approve your request.`,
120+
});
121+
122+
await prisma.studentData.update({
123+
where: {
124+
discordId: interaction.user.id,
125+
},
126+
data: {
127+
course: "C++",
128+
},
106129
});
107130
}
108131
}

0 commit comments

Comments
 (0)