1010const { getOrNotFound } = require ( '../util/promise' ) ;
1111const { Form } = require ( '../model/frames' ) ;
1212const { Sanitize } = require ( '../util/param-sanitize' ) ;
13- const { isTrue, json } = require ( '../util/http' ) ;
13+ const { isTrue, json, withEtag } = require ( '../util/http' ) ;
1414
1515
1616module . exports = ( service , endpoint ) => {
1717
18- service . get ( '/projects/:projectId/forms/:xmlFormId/submissions.geojson' , endpoint . plain ( async ( { Forms, GeoExtracts } , { auth, query, params } ) => {
18+ service . get ( '/projects/:projectId/forms/:xmlFormId/submissions.geojson' , endpoint . plain ( async ( { Forms, GeoExtracts, Actees } , { auth, query, params } ) => {
1919
2020 const form = await Forms . getByProjectAndXmlFormId ( params . projectId , params . xmlFormId , Form . WithoutDef , Form . WithoutXml )
2121 . then ( getOrNotFound )
2222 . then ( ( foundForm ) => auth . canOrReject ( 'submission.list' , foundForm ) ) ;
2323
24- return GeoExtracts . getSubmissionFeatureCollectionGeoJson (
24+ const createResponse = ( ) => GeoExtracts . getSubmissionFeatureCollectionGeoJson (
2525 form . id ,
2626 Sanitize . queryParamToArray ( query . fieldpath ) ,
2727 Sanitize . queryParamToIntArray ( query . submitterId , 'submitterId' ) ,
@@ -30,22 +30,31 @@ module.exports = (service, endpoint) => {
3030 isTrue ( query . deleted ) ,
3131 Number . parseInt ( query . limit , 10 ) || null ,
3232 ) . then ( json ) ;
33+
34+ const acteeVersion = await Actees . getEventCount ( form . acteeId ) ;
35+ // Weak etag, as the order in the resultset is undefined.
36+ return withEtag ( acteeVersion , createResponse , true ) ;
3337 } ) ) ;
3438
35- service . get ( '/projects/:projectId/datasets/:datasetName/entities.geojson' , endpoint . plain ( async ( { Datasets, GeoExtracts } , { auth, query, params } ) => {
39+
40+ service . get ( '/projects/:projectId/datasets/:datasetName/entities.geojson' , endpoint . plain ( async ( { Datasets, GeoExtracts, Actees } , { auth, query, params } ) => {
3641
3742 const foundDataset = await Datasets . get ( params . projectId , params . datasetName , true )
3843 . then ( getOrNotFound )
3944 . then ( ( dataset ) => auth . canOrReject ( 'entity.list' , dataset ) ) ;
4045
41- return GeoExtracts . getEntityFeatureCollectionGeoJson (
46+ const createResponse = ( ) => GeoExtracts . getEntityFeatureCollectionGeoJson (
4247 foundDataset . id ,
4348 Sanitize . queryParamToIntArray ( query . creatorId , 'creatorId' ) ,
4449 Sanitize . getTSTZRangeFromQueryParams ( query ) ,
4550 Sanitize . getEntityConflictStates ( query . conflict , 'conflict' ) ,
4651 isTrue ( query . deleted ) ,
4752 Number . parseInt ( query . limit , 10 ) || null ,
4853 ) . then ( json ) ;
54+
55+ const acteeVersion = await Actees . getEventCount ( foundDataset . acteeId ) ;
56+ // Weak etag, as the order in the resultset is undefined.
57+ return withEtag ( acteeVersion , createResponse , true ) ;
4958 } ) ) ;
5059
5160} ;
0 commit comments