(application, retentionDays, now = Date.now())
| 1032 | } |
| 1033 | |
| 1034 | function isApplicationExpired(application, retentionDays, now = Date.now()) { |
| 1035 | if (!application || typeof application !== 'object') { |
| 1036 | return false; |
| 1037 | } |
| 1038 | |
| 1039 | const createdAt = Number(application.createdAt) || now; |
| 1040 | const updatedAt = Number(application.updatedAt) || createdAt; |
| 1041 | const reviewedAt = application.reviewedAt ? Number(new Date(application.reviewedAt)) : null; |
| 1042 | const status = typeof application.status === 'string' ? application.status.toLowerCase() : 'pending'; |
| 1043 | |
| 1044 | const ageMsFromCreated = now - createdAt; |
| 1045 | const ageMsFromReviewed = now - (reviewedAt || updatedAt || createdAt); |
| 1046 | const pendingRetentionMs = retentionDays.pendingDays * 24 * 60 * 60 * 1000; |
| 1047 | const reviewedRetentionMs = retentionDays.reviewedDays * 24 * 60 * 60 * 1000; |
| 1048 | |
| 1049 | if (status === 'pending') { |
| 1050 | return ageMsFromCreated > pendingRetentionMs; |
| 1051 | } |
| 1052 | |
| 1053 | if (status === 'approved' || status === 'denied') { |
| 1054 | return ageMsFromReviewed > reviewedRetentionMs; |
| 1055 | } |
| 1056 | |
| 1057 | return ageMsFromCreated > pendingRetentionMs; |
| 1058 | } |
| 1059 | |
| 1060 | export async function deleteApplication(client, guildId, applicationId, userIdHint = null) { |
| 1061 | const key = getApplicationKey(guildId, applicationId); |
no outgoing calls
no test coverage detected