-
Notifications
You must be signed in to change notification settings - Fork 0
check in command functionality #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
db/migrations/20250809080731_add_description_column_to_checkin_table/migration.sql
Outdated
Show resolved
Hide resolved
| async execute(interaction: ChatInputCommandInteraction) { | ||
| const discord_id = interaction.user.id | ||
|
|
||
| let user = await interaction.client.prisma.user.findUnique({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let user = getUniqueUserByDiscordId(discordId)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bikin repository pattern gitu maksudnya?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sesimple2nya bikin function aja di file ini / file buat fetch db, entah dari repository, entah cuma dari function, terserah. Ini kayaknya function ini bakalan dipake lagi di future soalnya
| }) | ||
|
|
||
| if (!user) { | ||
| user = await interaction.client.prisma.user.create({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
user = createUser(discord_id)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ini gw skip dulu ya
src/bot/commands/checkin/checkin.ts
Outdated
| } | ||
| let streak_count = user.streak_count | ||
|
|
||
| const yesterday = new Date(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: getYesterdayDate()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/bot/commands/checkin/checkin.ts
Outdated
| const description = interaction.options.getString("description") | ||
|
|
||
| // do the checkin | ||
| const result = await interaction.client.prisma.checkin.create({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createCheckin(discordId, data1, data2, dst atau bikin object)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ini gw skip dulu juga
src/bot/commands/checkin/checkin.ts
Outdated
| }) | ||
|
|
||
| // update streak count | ||
| await interaction.client.prisma.user.update({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
increaseUserStreakCount(userId)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don
| "test": "echo \"Error: no test specified\" && exit 1" | ||
| "test": "echo \"Error: no test specified\" && exit 1", | ||
| "start": "bun src/index.ts", | ||
| "commands": "bun src/deploy-commands.ts" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commands dan event listener bakalan jadi 2 "instance" yang berbeda ya?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Abis baca komen ini
#6 (comment)
Berarti ini cuma di run 1x doang per change ya?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Abis baca komen ini #6 (comment)
Berarti ini cuma di run 1x doang per change ya?
Iyes, exactly!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iya dirun 1x doang bun commands ini. Buat update command confignya di discord.
src/bot/commands/checkin/checkin.ts
Outdated
| }) | ||
|
|
||
| // update streak count | ||
| await interaction.client.prisma.user.update({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ini update streak sama create checkinnya bisa dibikin di 1 db transaction ga? Ini takutnya kalo createnya sukses tapi updatenya gagal malah jadi double insert ntar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| description String | ||
| created_at DateTime @default(now()) | ||
| updated_at DateTime @updatedAt | ||
| user User @relation(fields: [user_id], references: [id]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ini under the hoodnya bakalan bikin foreign key ya? Kalo nggak, consider taruh db indexing buat user_idnya
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iya udah under the hood udah indexing kok
| }) | ||
|
|
||
| if (!user) { | ||
| user = await interaction.client.prisma.user.create({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setelah dipikir2, kenapa kita create usernya ketika checkin ya? Bukannya flownya user awal masuk discord ada flow "ambil role" ya? Consider kita bikin usernya pas disitu aja? Kalo misalnya ada user discord yg blum register trus nyoba login, kita bisa throw error. Wdyt @alfianchii ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ini seharusnya untuk sementara dan testing az. Karena fitur "ambil role" belum ada. Ketika nanti sudah jadi, let user = await interaction.client.prisma.user.findUnique dan user = await interaction.client.prisma.user.create bisa kita pindahkan ke fitur "ambil role".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ini seharusnya untuk sementara dan testing az.
this.
dan juga ini checkinnya blm ada fitur approval, maybe in the next PR aja
| checkins: { | ||
| take: 1, | ||
| orderBy: { | ||
| created_at: 'desc' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
baru ngeh ini ada orderBy created_at. Consider pake compound indexing ya btw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compound indexing buat apa bang? sortnya kan cuma dari 1 field? atau maksudnya sort by indexed key aja kayak id?
src/bot/commands/checkin/checkin.ts
Outdated
| streak_count = 0 | ||
| } | ||
|
|
||
| const description = interaction.options.getString("description") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bisa tambahin ! di belakang:
const description = interaction.options.getString("description")!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don
src/bot/commands/checkin/checkin.ts
Outdated
| id: user.id | ||
| } | ||
| }, | ||
| description: description || "", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Terus di sini jadi hanya:
description
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
alfianchii
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
No description provided.