Skip to content

Commit

Permalink
fix typo in api.doc and add attachmentToDatasename util
Browse files Browse the repository at this point in the history
  • Loading branch information
sadiqkhoja committed Feb 19, 2025
1 parent ee4b6f2 commit fa07c2e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9804,7 +9804,7 @@ paths:

[Offline Entities support](https://forum.getodk.org/t/openrosa-spec-proposal-support-offline-entities/48052):

* If an attachemnt is linked to a Dataset, then `type="entityList"` attribute is added to the `mediaFile` element.
* If an attachment is linked to a Dataset, then `type="entityList"` attribute is added to the `mediaFile` element.

* `integrityUrl` is also returned for the attachments that are linked to a Dataset.
operationId: OpenRosa Form Manifest API
Expand Down
3 changes: 2 additions & 1 deletion lib/formats/openrosa.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

const { mergeRight } = require('ramda');
const { parse, render } = require('mustache');
const { attachmentToDatasetName } = require('../util/util');

////////////////////////////////////////////////////////////////////////////////
// SETUP
Expand Down Expand Up @@ -82,7 +83,7 @@ const formManifest = (data) => formManifestTemplate(mergeRight(data, {
urlName: encodeURIComponent(attachment.name),
isDataset: attachment.datasetId != null,
integrityUrl: attachment.datasetId ?
`${data.domain}${data.projectPath}/datasets/${encodeURIComponent(attachment.name.replace(/\.[^/.]+$/, ''))}/integrity`
`${data.domain}${data.projectPath}/datasets/${encodeURIComponent(attachmentToDatasetName(attachment.name))}/integrity`
: null
}))
}));
Expand Down
4 changes: 2 additions & 2 deletions lib/resources/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const { sanitizeFieldsForOdata, setVersion } = require('../data/schema');
const { getOrNotFound, reject, resolve, rejectIf } = require('../util/promise');
const { success } = require('../util/http');
const { formList, formManifest } = require('../formats/openrosa');
const { noargs, isPresent, isBlank } = require('../util/util');
const { noargs, isPresent, isBlank, attachmentToDatasetName } = require('../util/util');
const { streamEntityCsvAttachment } = require('../data/entity');
const { md5sum } = require('../util/crypto');

Expand Down Expand Up @@ -226,7 +226,7 @@ module.exports = (service, endpoint) => {
.then(getOrNotFound)
.then((form) => auth.canOrReject('form.update', form))
.then((form) => Promise.all([
Datasets.get(params.projectId, params.name.replace(/\.csv$/i, ''), true)
Datasets.get(params.projectId, attachmentToDatasetName(params.name), true)
.then(getOrNotFound)
.then((dataset) => auth.canOrReject('entity.list', dataset)),
FormAttachments.getByFormDefIdAndName(form.draftDefId, params.name).then(getOrNotFound)
Expand Down
3 changes: 2 additions & 1 deletion lib/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ function utf8ToBase64(string) {
// so let's just make our own.
const construct = (Type) => (x, y) => new Type(x, y);

const attachmentToDatasetName = (attachmentName) => attachmentName.replace(/\.csv$/i, '');

module.exports = {
noop, noargs,
isBlank, isPresent, blankStringToNull, sanitizeOdataIdentifier,
printPairs, without, pickAll,
base64ToUtf8, utf8ToBase64,
construct
construct, attachmentToDatasetName
};

0 comments on commit fa07c2e

Please sign in to comment.