(interaction)
| 326 | } |
| 327 | |
| 328 | async function handleStatus(interaction) { |
| 329 | const appId = interaction.options.getString("id"); |
| 330 | |
| 331 | if (appId) { |
| 332 | const application = await getApplication( |
| 333 | interaction.client, |
| 334 | interaction.guild.id, |
| 335 | appId, |
| 336 | ); |
| 337 | |
| 338 | if (!application || application.userId !== interaction.user.id) { |
| 339 | return await replyUserError(interaction, { type: ErrorTypes.PERMISSION, message: 'Application not found or you do not have permission to view it.' }); |
| 340 | } |
| 341 | |
| 342 | const submittedAt = application?.createdAt ? new Date(application.createdAt) : null; |
| 343 | const submittedAtDisplay = submittedAt && !Number.isNaN(submittedAt.getTime()) |
| 344 | ? submittedAt.toLocaleString() |
| 345 | : 'Unknown date'; |
| 346 | const statusView = getApplicationStatusPresentation(application.status); |
| 347 | const embed = createEmbed({ |
| 348 | title: `Application #${application.id} - ${application.roleName || 'Unknown Role'}`, |
| 349 | description: |
| 350 | `**Application ID:** \`${application.id}\`\n` + |
| 351 | `**Status:** ${statusView.statusEmoji} ${statusView.statusLabel}\n` + |
| 352 | `**Submitted:** ${submittedAtDisplay}` |
| 353 | }); |
| 354 | |
| 355 | return InteractionHelper.safeEditReply(interaction, { embeds: [embed], flags: ["Ephemeral"] }); |
| 356 | } else { |
| 357 | const applications = await getUserApplications( |
| 358 | interaction.client, |
| 359 | interaction.guild.id, |
| 360 | interaction.user.id, |
| 361 | ); |
| 362 | |
| 363 | if (applications.length === 0) { |
| 364 | return await replyUserError(interaction, { type: ErrorTypes.UNKNOWN, message: 'You have not submitted any applications yet.' }); |
| 365 | } |
| 366 | |
| 367 | const recentApplications = applications |
| 368 | .sort((a, b) => new Date(b.createdAt || 0) - new Date(a.createdAt || 0)) |
| 369 | .slice(0, 10); |
| 370 | |
| 371 | const embed = createEmbed({ |
| 372 | title: "Your Applications", |
| 373 | description: `Showing ${recentApplications.length} recent application(s).` |
| 374 | }); |
| 375 | |
| 376 | recentApplications.forEach((application) => { |
| 377 | const submittedAt = application?.createdAt ? new Date(application.createdAt) : null; |
| 378 | const submittedAtDisplay = submittedAt && !Number.isNaN(submittedAt.getTime()) |
| 379 | ? submittedAt.toLocaleDateString() |
| 380 | : 'Unknown date'; |
| 381 | const statusView = getApplicationStatusPresentation(application.status); |
| 382 | |
| 383 | embed.addFields({ |
| 384 | name: `${statusView.statusEmoji} ${application.roleName || 'Unknown Role'} (${statusView.statusLabel})`, |
| 385 | value: |
no test coverage detected