@@ -18,6 +18,7 @@ import { ActionRowBuilder, ButtonBuilder, ButtonStyle, messageLink, PermissionsB
1818import { CHECKIN_APPROVE_BUTTON_ID } from '../handlers/approve-button'
1919import { CHECKIN_CUSTOM_BUTTON_ID } from '../handlers/custom-button'
2020import { CheckinCustomButtonModalError } from '../handlers/custom-button-modal'
21+ import { CHECKIN_DETAIL_BUTTON_ID } from '../handlers/detail-button'
2122import { CheckinModalError } from '../handlers/modal'
2223import { CHECKIN_REJECT_BUTTON_ID } from '../handlers/reject-button'
2324import { CheckinMessage } from '../messages'
@@ -100,6 +101,12 @@ export class Checkin extends CheckinMessage {
100101 }
101102
102103 static generateButtons ( guildId : string , checkinId : string ) : ActionRowBuilder < ButtonBuilder > {
104+ const detailButtonId = getCustomId ( [ CHECKIN_DETAIL_BUTTON_ID , encodeSnowflake ( guildId ) , encodeSnowflake ( checkinId ) ] )
105+ const detailButton = new ButtonBuilder ( )
106+ . setCustomId ( detailButtonId )
107+ . setLabel ( '🔍 Detail' )
108+ . setStyle ( ButtonStyle . Primary )
109+
103110 const approveButtonId = getCustomId ( [ CHECKIN_APPROVE_BUTTON_ID , encodeSnowflake ( guildId ) , encodeSnowflake ( checkinId ) ] )
104111 const approveButton = new ButtonBuilder ( )
105112 . setCustomId ( approveButtonId )
@@ -116,9 +123,9 @@ export class Checkin extends CheckinMessage {
116123 const customButton = new ButtonBuilder ( )
117124 . setCustomId ( customButtonId )
118125 . setLabel ( '⚙️ Review' )
119- . setStyle ( ButtonStyle . Primary )
126+ . setStyle ( ButtonStyle . Secondary )
120127
121- return new ActionRowBuilder < ButtonBuilder > ( ) . addComponents ( approveButton , rejectButton , customButton )
128+ return new ActionRowBuilder < ButtonBuilder > ( ) . addComponents ( detailButton , approveButton , rejectButton , customButton )
122129 }
123130
124131 static getNewGrindRole ( guild : Guild , streakCount : number ) {
@@ -323,6 +330,26 @@ export class Checkin extends CheckinMessage {
323330 } ) as CheckinType
324331 }
325332
333+ static async getCheckin (
334+ prisma : PrismaClient ,
335+ checkinId : number ,
336+ ) : Promise < CheckinType > {
337+ const checkin = await prisma . checkin . findUnique ( {
338+ where : { id : checkinId } ,
339+ include : {
340+ checkin_streak : true ,
341+ user : true ,
342+ } ,
343+ } ) as CheckinType
344+
345+ if ( ! checkin )
346+ throw new SubmittedCheckinError ( this . ERR . PlainMessage )
347+
348+ await this . setAttachments ( prisma , checkin )
349+
350+ return checkin
351+ }
352+
326353 static async createAttachments (
327354 prisma : PrismaClient ,
328355 checkin : CheckinType ,
@@ -368,13 +395,8 @@ export class Checkin extends CheckinMessage {
368395 return prisma . $transaction ( async ( tx ) => {
369396 const checkinStreak = await this . upsertStreak ( tx , userId , lastCheckinStreak , decision )
370397 const checkin = await this . createCheckin ( tx , userId , checkinStreak , description )
371- const prevCheckin = await this . getPrevCheckin ( tx , userId , checkinStreak , checkin )
372398
373- return {
374- checkinStreak,
375- checkin,
376- prevCheckin,
377- }
399+ return { checkinStreak, checkin }
378400 } )
379401 }
380402
@@ -392,7 +414,7 @@ export class Checkin extends CheckinMessage {
392414 const updatedCheckin = await this . updateCheckinStatus ( prisma , flamewarden , checkin , checkinStatus , comment ) as CheckinType
393415
394416 await this . validateCheckinHandleToUser ( guild , flamewarden , checkin . user ! . discord_id , updatedCheckin )
395- await this . validateCheckinHandleSubmittedMsg ( message , updatedCheckin , checkinStatus )
417+ await message . react ( this . REVERSED_EMOJI_STATUS [ checkinStatus ] )
396418 }
397419
398420 static async validateCheckinHandleToUser ( guild : Guild , flamewarden : GuildMember , userDiscordId : string , updatedCheckin : CheckinType ) {
@@ -403,11 +425,6 @@ export class Checkin extends CheckinMessage {
403425 await this . sendCheckinStatusToMember ( flamewarden , member , updatedCheckin )
404426 }
405427
406- static async validateCheckinHandleSubmittedMsg ( message : Message , updatedCheckin : CheckinType , checkinStatus : CheckinStatusType ) {
407- await this . updateSubmittedCheckin ( message , updatedCheckin . checkin_streak ! . streak )
408- await message . react ( this . REVERSED_EMOJI_STATUS [ checkinStatus ] )
409- }
410-
411428 static async updateCheckinMsgLink ( interaction : Interaction , prisma : PrismaClient , checkin : CheckinType , msg : Message ) : Promise < CheckinType > {
412429 const msgLink = messageLink ( interaction . channelId ! , msg . id , interaction . guildId ! )
413430
@@ -491,13 +508,4 @@ export class Checkin extends CheckinMessage {
491508
492509 await member . send ( { embeds : [ embed ] } )
493510 }
494-
495- static async updateSubmittedCheckin ( message : Message , newStreak : number ) {
496- await message . edit (
497- message . content . replace (
498- / 🔥 \s * \* \* C u r r e n t S t r e a k : \* \* \s * \d + \s * d a y \( s \) / i,
499- `🔥 **Current Streak:** ${ newStreak } day(s)` ,
500- ) ,
501- )
502- }
503511}
0 commit comments