Skip to content

Commit 8302818

Browse files
authored
Small code changes related to entities and datasets (getodk#769)
1 parent 35a6f0f commit 8302818

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

lib/data/entity.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const formatRow = (entity, props) => {
9999
return out;
100100
};
101101

102-
const streamEntityCsvs = (inStream, properties) => {
102+
const streamEntityCsv = (inStream, properties) => {
103103
const header = [ 'name', 'label' ];
104104
const props = [];
105105

@@ -110,25 +110,25 @@ const streamEntityCsvs = (inStream, properties) => {
110110
props.push(prop);
111111
}
112112

113-
let rootHeaderSent = false;
114-
const rootStream = new Transform({
113+
let headerSent = false;
114+
const entityStream = new Transform({
115115
objectMode: true,
116116
transform(entity, _, done) {
117117
try {
118-
if (rootHeaderSent === false) {
118+
if (headerSent === false) {
119119
this.push(header);
120-
rootHeaderSent = true;
120+
headerSent = true;
121121
}
122122
this.push(formatRow(entity, props));
123123
done();
124124
} catch (ex) { done(ex); }
125125
}, flush(done) {
126-
if (rootHeaderSent === false) this.push(header);
126+
if (headerSent === false) this.push(header);
127127
done();
128128
}
129129
});
130130

131-
return PartialPipe.of(inStream, rootStream, csv());
131+
return PartialPipe.of(inStream, entityStream, csv());
132132
};
133133

134134
const selectFields = (entity, properties, selectedProperties) => {
@@ -239,7 +239,7 @@ const streamEntityOdata = (inStream, properties, domain, originalUrl, query, tab
239239

240240
module.exports = {
241241
parseSubmissionXml, validateEntity,
242-
streamEntityCsvs, streamEntityOdata,
242+
streamEntityCsv, streamEntityOdata,
243243
odataToColumnMap,
244244
extractSelectedProperties, selectFields
245245
};

lib/model/query/form-attachments.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ const getAllByFormDefIdForOpenRosa = (formDefId) => ({ all }) => all(sql`
136136
select ${_unjoinMd5.fields} from form_attachments
137137
left outer join (select id, md5 from blobs) as blobs on form_attachments."blobId"=blobs.id
138138
left outer join (
139-
select d.id, max(e."updatedAt") "dsUpdatedAt" from datasets d left outer join entities e on d.id = e."datasetId" group by d.id
139+
select d.id, max(coalesce(e."updatedAt", e."createdAt")) "dsUpdatedAt" from datasets d left outer join entities e on d.id = e."datasetId" group by d.id
140140
) as ds on form_attachments."datasetId"=ds.id
141141
where "formDefId"=${formDefId}`)
142142
.then(map(_unjoinMd5));

lib/model/query/submissions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ where submissions."instanceId"=${instanceId}
180180
and submissions."deletedAt" is null
181181
and draft=${draft}
182182
and submission_defs.current=true`)
183-
.then(map((row) => new Submission.Partial(row, { def: new Submission.Def({ id: row.defId }) })));
183+
.then(map((row) => new Submission(row, { def: new Submission.Def({ id: row.defId }) })));
184184

185185
const getCurrentDefByIds = (projectId, xmlFormId, instanceId, draft) => ({ maybeOne }) => maybeOne(sql`
186186
select submission_defs.* from submission_defs

lib/resources/datasets.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
const sanitize = require('sanitize-filename');
1111
const { getOrNotFound } = require('../util/promise');
12-
const { streamEntityCsvs } = require('../data/entity');
12+
const { streamEntityCsv } = require('../data/entity');
1313
const { contentDisposition } = require('../util/http');
1414

1515
module.exports = (service, endpoint) => {
@@ -38,6 +38,6 @@ module.exports = (service, endpoint) => {
3838
const extension = 'csv';
3939
response.append('Content-Disposition', contentDisposition(`${filename}.${extension}`));
4040
response.append('Content-Type', 'text/csv');
41-
return streamEntityCsvs(entities, dataset.properties);
41+
return streamEntityCsv(entities, dataset.properties);
4242
})))));
4343
};

lib/resources/forms.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const { getOrNotFound, reject, resolve, rejectIf } = require('../util/promise');
1919
const { success } = require('../util/http');
2020
const { formList, formManifest } = require('../formats/openrosa');
2121
const { noargs, isPresent, isBlank } = require('../util/util');
22-
const { streamEntityCsvs } = require('../data/entity');
22+
const { streamEntityCsv } = require('../data/entity');
2323

2424
// excel-related util funcs/data used below:
2525
const isExcel = (contentType) => (contentType === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') || (contentType === 'application/vnd.ms-excel');
@@ -288,7 +288,7 @@ module.exports = (service, endpoint) => {
288288
.then((entities) => {
289289
response.append('Content-Disposition', contentDisposition(`${attachment.name}`));
290290
response.append('Content-Type', 'text/csv');
291-
return streamEntityCsvs(entities, dataset.properties);
291+
return streamEntityCsv(entities, dataset.properties);
292292
}))))))));
293293
};
294294

0 commit comments

Comments
 (0)