Skip to content

Commit

Permalink
Merge pull request #200 from OpenFn/199-bns-price-db-zero-results
Browse files Browse the repository at this point in the history
Add `PNMD` in `landscapeMap`
  • Loading branch information
daissatou2 authored Jan 26, 2024
2 parents 9482138 + 2b80cab commit 21b00ba
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions bns/price.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// NOTE: This data cleaning operation returns state, modified as needed.
alterState(state => {
fn(state => {
//try {
const { body, formName, instance, formOwner } = state.data;
const { _submission_time, _id, _xform_id_string } = body;
Expand Down Expand Up @@ -36,6 +36,7 @@ alterState(state => {
'Nosy Be': 'tandavandriva',
Makira: 'makira',
'BNS Ndoki Prix 2020': 'ndoki',
PNMD: 'pnmd',

//formName: landscapeValue,
//other values
Expand Down Expand Up @@ -66,11 +67,12 @@ sql({
`DELETE FROM WCSPROGRAMS_KoboBnsPrice where AnswerId = '${state.data._id}'`,
});

alterState(state => {
fn(state => {
const { good } = state.data;
if (!good || good.length === 0) {
return state;
}

const data = good.map((g, i) => ({
// Id: state.data._id,
Id: i + 1,
Expand All @@ -82,18 +84,18 @@ alterState(state => {
Price: g[`good/price`],
LastUpdate: new Date().toISOString(),
//Landscape: state.landscapeMap[state.data.formName], //see L24 for mappings. We want to use formName to look-up a new value
Landscape: state => {
Landscape: () => {
for (let val in state.landscapeMap)
if (state.formName.includes(val)) return state.landscapeMap[val];
return '';
},
SurveyDate: state.data.today,
}));
// console.log('data', data);
return insertMany('WCSPROGRAMS_KoboBnsPrice', state => data)(state);
return insertMany('WCSPROGRAMS_KoboBnsPrice', data)(state);
});

alterState(state => {
fn(state => {
console.log('DatasetName ::', state.formName);
console.log('DatasetOwner ::', state.formOwner);
console.log('form submission id ::', state.data['_id']);
Expand All @@ -117,7 +119,7 @@ upsert('WCSPROGRAMS_KoboData', 'DatasetUuidId', {
Citation: dataValue('instance'),
});

alterState(state => {
fn(state => {
console.log('data uploaded ::', state.data);
return state;
});

0 comments on commit 21b00ba

Please sign in to comment.