Skip to content

Commit

Permalink
Merge pull request #152 from opendatakit/cxlt/odata-fixes
Browse files Browse the repository at this point in the history
minor odata bugs
  • Loading branch information
issa-tseng authored Nov 2, 2018
2 parents 8d186c6 + 628728c commit f9c0c06
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/model/query/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module.exports = {
.where(options.condition)
.where({ deletedAt: null })
.orderBy('createdAt', 'desc')
.orderBy('id', 'desc')
.modify(applyPagingOptions(options))
: db.select(fieldsForJoin({
submission: { table: 'submissions', fields: Submission.fields() },
Expand All @@ -69,6 +70,7 @@ module.exports = {
'submissions.submitter', 'actors.id'
)
.orderBy('submissions.createdAt', 'desc')
.orderBy('submissions.id', 'desc')
.modify(applyPagingOptions(options))),

deserializer: (extended = false) => ({ Submission, Actor }) => ((extended === false)
Expand Down
5 changes: 4 additions & 1 deletion lib/outbound/odata.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,10 @@ const rowStreamToOData = (form, table, domain, originalUrl, query, inStream, tab
// rows.
const totalCount = ((table === 'Submissions') && (tableCount != null)) ? tableCount : counted;
const nextUrl = nextUrlFor(limit, offset, totalCount, originalUrl);
this.push(jsonDataFooter({ form, table, domain, serviceRoot, nextUrl, count: (shouldCount ? totalCount : null) }));

// we do toStrring on the totalCount because mustache won't bother rendering
// the block if it sees integer zero.
this.push(jsonDataFooter({ form, table, domain, serviceRoot, nextUrl, count: (shouldCount ? totalCount.toString() : null) }));
done();
}
});
Expand Down
9 changes: 9 additions & 0 deletions test/integration/api/odata.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ describe('api: /forms/:id.svc', () => {
});
}))));

it('should return a count even if there are no rows', testService((service) =>
service.login('alice', (asAlice) =>
asAlice.get('/v1/forms/withrepeat.svc/Submissions?$count=true')
.expect(200)
.then(({ body }) => {
console.log(body);
body['@odata.count'].should.equal(0);
}))));

it('should return subtable results', testService((service) =>
withSubmissions(service, (asAlice) =>
asAlice.get('/v1/forms/withrepeat.svc/Submissions.children.child')
Expand Down

0 comments on commit f9c0c06

Please sign in to comment.