Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/1139 update character issues report #563

Merged
merged 4 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions JAC - Digital Platform.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,15 @@
],
"body": {
"mode": "raw",
"raw": "{\r\n \"data\": {\r\n \"exerciseId\": \"4Ufg5bAC2Gjx2YRve9WZ\"\r\n }\r\n}"
"raw": "{\r\n \"data\": {\r\n \"exerciseId\": \"wdpALbyICL7ZxxN5AQt8\"\r\n }\r\n}"
},
"url": {
"raw": "{{host}}exportApplicationCharacterIssues",
"raw": "{{host}}/exportApplicationCharacterIssues",
"host": [
"{{host}}exportApplicationCharacterIssues"
"{{host}}"
],
"path": [
"exportApplicationCharacterIssues"
]
}
},
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ See [functions/scheduledFunctions](functions/scheduledFunctions) for functions t



<!--
## Local development


### Node.js

You must be running **Node.js 10**.

You can use [`nvm`](https://github.com/nvm-sh/nvm) or
[Homebrew](http://www.ianoxley.com/blog/2018/02/02/managing-node-versions-with-homebrew) to manage installed Node.js versions.


### Firebase CLI

You'll need the [Firebase Command Line Interface (CLI)](https://firebase.google.com/docs/cli) installed to interact with the staging and production projects on
Expand Down Expand Up @@ -65,6 +66,11 @@ cd functions
npm install
```

### Deploy a single function to develop

```
npx firebase deploy --project=digital-platform-develop --only functions:exportApplicationCharacterIssues
```

### Deploy to staging

Expand All @@ -81,6 +87,7 @@ Just prefix your branch name with `staging-` and every new push will automatical
You can also perform [partial deployments](https://firebase.google.com/docs/cli#partial_deploys) to only update specific apps,
Cloud Functions or Firebase services.


### Deploy to production

We use [CircleCI](https://circleci.com/gh/jac-uk/digital-platform) to deploy to production.
Expand All @@ -90,15 +97,11 @@ Open a Pull Request to merge your code into the `master` branch.
Once approved, merge your Pull Request and it'll be deployed to production automatically.



### Running an emulated firebase database locally

firebase emulators:start --only functions



### Running a tests on an emulated firebase database locally

firebase emulators:exec "npm run test:functions"

-->
40 changes: 27 additions & 13 deletions functions/actions/exercises/exportApplicationCharacterIssues.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
const { getDocuments, formatDate } = require('../../shared/helpers');
const { getDocuments, getDocument, formatDate } = require('../../shared/helpers');
const _ = require('lodash');

module.exports = (firebase, db) => {
return {
exportApplicationCharacterIssues,
};

async function exportApplicationCharacterIssues(exerciseId) {
// get submitted applications that have character check declarations
const applications = await getDocuments(db.collection('applications')
.where('exerciseId', '==', exerciseId));

// get applicationRecords
const applicationRecords = await getDocuments(db.collection('applicationRecords')
.where('exercise.id', '==', exerciseId)
.where('flags.characterIssues', '==', true));

// add applications
for (let i = 0, len = applicationRecords.length; i < len; i++) {
const applicationRecord = applicationRecords[i];
applicationRecords[i].application = await getDocument(
db.collection('applications').doc(applicationRecord.application.id)
);
}

// return data for export
return {
total: applications.length,
total: applicationRecords.length,
createdAt: firebase.firestore.Timestamp.fromDate(new Date()),
headers: getHeaders(),
rows: getRows(applications),
rows: getRows(applicationRecords),
};

}

function getCharacterInformationString(application) {
Expand Down Expand Up @@ -171,14 +184,15 @@ module.exports = (firebase, db) => {
];
}

function getRows(applications) {
return applications.filter(a => (Boolean(a.referenceNumber))).map(application => {
function getRows(applicationRecords) {
return applicationRecords.map((applicationRecord) => {
const application = applicationRecord.application;
return {
ref: application.referenceNumber,
name: (application.personalDetails && application.personalDetails.fullName) ? application.personalDetails.fullName : '',
email: (application.personalDetails && application.personalDetails.email) ? application.personalDetails.email : '',
citizenship: (application.personalDetails && application.personalDetails.citizenship) ? application.personalDetails.citizenship : '',
dob: (application.personalDetails && application.personalDetails.dateOfBirth) ? formatDate(application.personalDetails.dateOfBirth) : '',
ref: _.get(applicationRecord, 'application.referenceNumber', ''),
name: _.get(applicationRecord,'candidate.fullName', ''),
email: _.get(applicationRecord, 'application.personalDetails.email', ''),
citizenship: _.get(applicationRecord, 'application.personalDetails.citizenship', ''),
dob: formatDate(_.get(applicationRecord, 'application.personalDetails.dateOfBirth', '')),
qualifications: getQualificationInformationString(application),
character: getCharacterInformationString(application),
};
Expand Down