Skip to content

Commit

Permalink
2606/Multiple Exercise Custom Report (#1283)
Browse files Browse the repository at this point in the history
* wip

* wip

* Amend callable function interface

---------

Co-authored-by: warrensearle <warren@precise-minds.co.uk>
  • Loading branch information
tomlovesgithub and warrensearle authored Dec 19, 2024
1 parent 6fdf016 commit 54b52a9
Show file tree
Hide file tree
Showing 6 changed files with 402 additions and 3,364 deletions.
27 changes: 27 additions & 0 deletions functions/actions/exercises/getMultipleApplicationData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import initGetApplicationData from './getApplicationData.js';

export default (config, firebase, db, auth) => {

const getApplicationData = initGetApplicationData(config, firebase, db, auth);

return getMultipleApplicationData;

async function getMultipleApplicationData(exerciseIds, columns) {
const allData = [];

for (const exerciseId of exerciseIds) {
const whereClauses = [];
const exerciseParams = { whereClauses, columns, exerciseId };
const exerciseData = await getApplicationData(exerciseParams);

if (Array.isArray(exerciseData)) {
allData.push(...exerciseData);
} else {
console.warn(`Non-iterable data returned for exerciseId: ${exerciseId}`, exerciseData);
}
}

return allData;
}

};
36 changes: 36 additions & 0 deletions functions/callableFunctions/getMultipleApplicationData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import functions from 'firebase-functions';
import { auth } from '../shared/admin.js';
import config from '../shared/config.js';
import { firebase, db } from '../shared/admin.js';
import { checkArguments } from '../shared/helpers.js';
import initGetMultipleApplicationData from '../actions/exercises/getMultipleApplicationData.js';
import initServiceSettings from '../shared/serviceSettings.js';
import { PERMISSIONS, hasPermissions } from '../shared/permissions.js';

const getMultipleApplicationData = initGetMultipleApplicationData(config, firebase, db, auth);
const { checkFunctionEnabled } = initServiceSettings(db);

const runtimeOptions = {
memory: '512MB',
};

export default functions.runWith(runtimeOptions).region('europe-west2').https.onCall(async (data, context) => {
await checkFunctionEnabled();
if (!context.auth) {
throw new functions.https.HttpsError('failed-precondition', 'The function must be called while authenticated.');
}

hasPermissions(context.auth.token.rp, [
PERMISSIONS.applications.permissions.canReadApplications.value,
]);

if (!checkArguments({
exerciseIds: { required: true },
columns: { required: true },
}, data)) {
throw new functions.https.HttpsError('invalid-argument', 'Please provide valid arguments');
}
return getMultipleApplicationData(data.exerciseIds, data.columns);

});

2 changes: 2 additions & 0 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import getLatestReleases from './callableFunctions/getLatestReleases.js';
import verifyFileChecksum from './callableFunctions/verifyFileChecksum.js';
import sendSmsVerificationCode from './callableFunctions/sendSmsVerificationCode.js';
import verifySmsVerificationCode from './callableFunctions/verifySmsVerificationCode.js';
import getMultipleApplicationData from './callableFunctions/getMultipleApplicationData.js';

// Callable - QTs v2
import listQualifyingTests from './callableFunctions/qualifyingTests/v2/listQualifyingTests.js';
Expand Down Expand Up @@ -206,6 +207,7 @@ export {
verifyFileChecksum,
sendSmsVerificationCode,
verifySmsVerificationCode,
getMultipleApplicationData,

// Callable - QTs v2
listQualifyingTests,
Expand Down
Loading

0 comments on commit 54b52a9

Please sign in to comment.