Skip to content

Conversation

@zuramai
Copy link
Member

@zuramai zuramai commented Aug 9, 2025

No description provided.

@zuramai zuramai requested review from alfianchii and papannnn August 9, 2025 10:15
async execute(interaction: ChatInputCommandInteraction) {
const discord_id = interaction.user.id

let user = await interaction.client.prisma.user.findUnique({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let user = getUniqueUserByDiscordId(discordId)

Copy link
Member Author

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?

Copy link
Collaborator

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({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user = createUser(discord_id)

Copy link
Member Author

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

}
let streak_count = user.streak_count

const yesterday = new Date();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: getYesterdayDate()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const description = interaction.options.getString("description")

// do the checkin
const result = await interaction.client.prisma.checkin.create({
Copy link
Collaborator

@papannnn papannnn Aug 9, 2025

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)

Copy link
Member Author

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

})

// update streak count
await interaction.client.prisma.user.update({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

increaseUserStreakCount(userId)

Copy link
Member Author

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"
Copy link
Collaborator

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?

Copy link
Collaborator

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?

Copy link
Member

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!

Copy link
Member Author

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.

})

// update streak count
await interaction.client.prisma.user.update({
Copy link
Collaborator

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

Copy link
Member Author

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])
Copy link
Collaborator

@papannnn papannnn Aug 9, 2025

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

Copy link
Member Author

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({
Copy link
Collaborator

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 ?

Copy link
Member

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".

Copy link
Member Author

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'
Copy link
Collaborator

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

Copy link
Member Author

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?

@alfianchii alfianchii added the enhancement New feature or request label Aug 9, 2025
streak_count = 0
}

const description = interaction.options.getString("description")
Copy link
Member

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")!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don

id: user.id
}
},
description: description || "",
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@alfianchii alfianchii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@zuramai zuramai merged commit b284db4 into main Aug 10, 2025
@alfianchii alfianchii deleted the feat/checkin branch September 20, 2025 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants