-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2606/Multiple Exercise Custom Report (#1283)
* wip * wip * Amend callable function interface --------- Co-authored-by: warrensearle <warren@precise-minds.co.uk>
- Loading branch information
1 parent
6fdf016
commit 54b52a9
Showing
6 changed files
with
402 additions
and
3,364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.