(client, application)
| 1194 | } |
| 1195 | |
| 1196 | export async function createApplication(client, application) { |
| 1197 | const { guildId, userId } = application; |
| 1198 | const applicationId = `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`; |
| 1199 | const key = getApplicationKey(guildId, applicationId); |
| 1200 | |
| 1201 | const newApplication = { |
| 1202 | ...application, |
| 1203 | id: applicationId, |
| 1204 | status: 'pending', |
| 1205 | createdAt: Date.now(), |
| 1206 | updatedAt: Date.now(), |
| 1207 | reviewedBy: null, |
| 1208 | reviewedAt: null, |
| 1209 | notes: [] |
| 1210 | }; |
| 1211 | |
| 1212 | try { |
| 1213 | if (!client.db || typeof client.db.set !== "function") { |
| 1214 | logger.error("Database client is not available for createApplication."); |
| 1215 | throw new Error("Database not available"); |
| 1216 | } |
| 1217 | |
| 1218 | await client.db.set(key, newApplication); |
| 1219 | |
| 1220 | const userKey = getUserApplicationsKey(guildId, userId); |
| 1221 | const userApplications = await client.db.get(userKey, []); |
| 1222 | const unwrappedApplications = unwrapReplitData(userApplications); |
| 1223 | |
| 1224 | const applicationsArray = Array.isArray(unwrappedApplications) ? unwrappedApplications : []; |
| 1225 | applicationsArray.push(applicationId); |
| 1226 | |
| 1227 | await client.db.set(userKey, applicationsArray); |
| 1228 | if (process.env.NODE_ENV !== 'production') { |
| 1229 | logger.debug(`Successfully created application ${applicationId} for user ${userId}`); |
| 1230 | } |
| 1231 | |
| 1232 | return newApplication; |
| 1233 | } catch (error) { |
| 1234 | logger.error(`Error creating application for user ${userId} in guild ${guildId}:`, error); |
| 1235 | throw error; |
| 1236 | } |
| 1237 | } |
| 1238 | |
| 1239 | export async function getApplication(client, guildId, applicationId) { |
| 1240 | const key = getApplicationKey(guildId, applicationId); |
no test coverage detected