MCPcopy Index your code
hub / github.com/codebymitch/TitanBot / getApplications

Function getApplications

src/utils/database.js:1300–1351  ·  view source on GitHub ↗
(client, guildId, filters = {})

Source from the content-addressed store, hash-verified

1298}
1299
1300export async function getApplications(client, guildId, filters = {}) {
1301 const {
1302 status,
1303 userId,
1304 limit = 50,
1305 offset = 0
1306 } = filters;
1307
1308 try {
1309 if (!client.db || typeof client.db.list !== "function") {
1310 logger.error("Database client is not available for getApplications.");
1311 return [];
1312 }
1313
1314 await cleanupExpiredApplications(client, guildId);
1315
1316 const prefix = `guild:${guildId}:applications:`;
1317 let keys = await client.db.list(prefix);
1318
1319 if (!Array.isArray(keys)) {
1320 if (typeof keys === 'object' && keys !== null) {
1321 const keyArray = Object.keys(keys).filter(key => key.startsWith(prefix));
1322 keys = keyArray;
1323 } else {
1324 return [];
1325 }
1326 }
1327
1328 const applicationKeyPattern = new RegExp(`^guild:${guildId}:applications:[^:]+$`);
1329 const applicationKeys = keys.filter(key => applicationKeyPattern.test(key));
1330
1331 const applicationPromises = applicationKeys.map(key => client.db.get(key));
1332 let applications = (await Promise.all(applicationPromises))
1333 .map(unwrapReplitData)
1334 .filter(Boolean);
1335
1336 if (status) {
1337 applications = applications.filter(app => app.status === status);
1338 }
1339
1340 if (userId) {
1341 applications = applications.filter(app => app.userId === userId);
1342 }
1343
1344 applications.sort((a, b) => b.createdAt - a.createdAt);
1345
1346 return applications.slice(offset, offset + limit);
1347 } catch (error) {
1348 logger.error(`Error getting applications for guild ${guildId}:`, error);
1349 return [];
1350 }
1351}
1352
1353export function getJoinToCreateConfigKey(guildId) {
1354 return `guild:${guildId}:jointocreate`;

Callers 3

handleListFunction · 0.90
handleDeleteApplicationFunction · 0.90
getApplicationsListMethod · 0.90

Calls 3

listMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected