Skip to content

Commit 243f77d

Browse files
committed
fix: upload would fail most of the time for tagbox / checkbox questions
1 parent c247ee6 commit 243f77d

File tree

5 files changed

+16
-21
lines changed

5 files changed

+16
-21
lines changed

src/routes/gis/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ const getFeatures = async (
189189
if (mapping.adminField) {
190190
adminPolygons = await getPolygons(mapping.adminField);
191191
}
192-
console.log('Items length is : ', items.length);
193192
items.forEach((item) => {
194193
try {
195194
if (mapping.adminField) {

src/routes/upload/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ async function insertRecords(
9292
String(form.resource ? form.resource : form.id)
9393
),
9494
form: form.id,
95-
createdAt: new Date(),
96-
modifiedAt: new Date(),
95+
// createdAt: new Date(),
96+
// modifiedAt: new Date(),
9797
data: dataSet.data,
9898
resource: form.resource ? form.resource : null,
9999
createdBy: {

src/utils/files/getUploadColumns.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export const getUploadColumns = (fields: any[], headers: any[]): any[] => {
1111
switch (field.type) {
1212
case 'checkbox':
1313
case 'tagbox': {
14-
if (field.choices) {
14+
// One column per option, if question has choices & we don't find it in the list of the excel columns.
15+
if (field.choices && !headers.find(field.name)) {
1516
for (const item of field.choices) {
1617
const name = `${field.name}.${item.value}`;
1718
const index = headers.indexOf(name);

src/utils/files/loadRow.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isArray } from 'lodash';
1+
import { isArray, isNil } from 'lodash';
22
import set from 'lodash/set';
33
import { PositionAttribute } from '@models';
44

@@ -36,19 +36,18 @@ export const loadRow = (
3636
data[column.field] = false;
3737
}
3838
}
39-
case 'checkbox': {
40-
if (value === 1) {
41-
data[column.field] = (
42-
isArray(data[column.field]) ? data[column.field] : []
43-
).concat(column.value);
44-
}
45-
break;
46-
}
39+
case 'checkbox':
4740
case 'tagbox': {
48-
if (value === 1) {
49-
data[column.field] = (
50-
isArray(data[column.field]) ? data[column.field] : []
51-
).concat(column.value);
41+
// Column is linked to a specific value
42+
if (!isNil(column.value)) {
43+
if (value === 1) {
44+
data[column.field] = (
45+
isArray(data[column.field]) ? data[column.field] : []
46+
).concat(column.value);
47+
}
48+
} else {
49+
// General column for the field, so we can directly save the values in the record
50+
set(data, column.field, value);
5251
}
5352
break;
5453
}

src/utils/gis/getCountryPolygons.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ export const getAdmin0Polygons = async (
6161
password: config.get('redis.password'),
6262
});
6363
client.on('error', (error) => {
64-
console.log('error is here');
6564
logger.error(`REDIS: ${error}`);
6665
});
6766
await client.connect();
@@ -94,7 +93,6 @@ export const getAdmin0Polygons = async (
9493
})
9594
.then(({ data }) => {
9695
if (client) {
97-
console.log('setting cache');
9896
client.set(cacheKey, JSON.stringify(data.data.countrys), {
9997
EX: 60 * 60 * 1, // set a cache of one hour
10098
});
@@ -106,9 +104,7 @@ export const getAdmin0Polygons = async (
106104
return [];
107105
});
108106
} else {
109-
console.log('there is cache');
110107
admin0s = JSON.parse(cacheData);
111-
console.log('And length is : ', admin0s.length);
112108
}
113109
for (const country of admin0s) {
114110
if (country.polygons && country[identifier]) {

0 commit comments

Comments
 (0)