Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build/communes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const MORTES_POUR_LA_FRANCE = ['55189', '55039', '55050', '55239', '55307', '551
async function buildCommunes() {
const communesFeatures = await readGeoJSONFeatures(COMMUNES_FEATURES_PATH)
const communesFeaturesIndex = keyBy(communesFeatures, f => f.properties.code)
const keyCom = 'collectiviteOutremer'

const communesData = communes
.filter(commune => {
Expand All @@ -30,6 +31,9 @@ async function buildCommunes() {
codesPostaux: commune.codesPostaux || [],
population: commune.population
}
if (keyCom in commune) {
communeData[keyCom] = commune[keyCom]
}

if (commune.code in communesFeaturesIndex) {
const contour = communesFeaturesIndex[commune.code].geometry
Expand Down
2 changes: 1 addition & 1 deletion lib/communeHelpers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {initFields, initFormat} = require('./helpers')

const initCommuneFields = initFields({
default: ['nom', 'code', 'codeDepartement', 'codeRegion', 'codesPostaux', 'population'],
default: ['nom', 'code', 'codeDepartement', 'codeRegion', 'codesPostaux', 'population', 'collectiviteOutremer'],
base: ['nom', 'code']
})

Expand Down
5 changes: 5 additions & 0 deletions lib/communes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const schema = {
code: {type: 'token', queryWith: 'code'},
codesPostaux: {type: 'tokenList', queryWith: 'codePostal'},
codeDepartement: {type: 'token', queryWith: 'codeDepartement'},
collectiviteOutremer: {
type: 'tokenNested',
queryWith: 'collectiviteOutremer',
nestedKey: 'code'
},
codeRegion: {type: 'token', queryWith: 'codeRegion'},
contour: {type: 'geo', queryWith: 'pointInContour'}
}
Expand Down
1 change: 1 addition & 0 deletions lib/searchableCollection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const TextIndex = require('./indexes/text')
const createIndexByType = {
token: (key, params) => new TokenIndex(key, params),
tokenList: (key, params) => new TokenIndex(key, {...params, array: true}),
tokenNested: (key, params) => new TokenIndex(key, params),
text: (key, params) => new TextIndex(key, params),
geo: key => new GeoIndex(key)
}
Expand Down
3 changes: 3 additions & 0 deletions lib/searchableCollection/indexes/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class TokenIndex {

this._key = key
this._array = options.array || false
this._nestedKey = options.nestedKey || false
this._multiple = options.multiple
this._index = new Map()
}
Expand All @@ -24,6 +25,8 @@ class TokenIndex {
if (this._key in item) {
if (this._array) {
item[this._key].forEach(token => this.indexForToken(token, item))
} else if (this._nestedKey) {
this.indexForToken(item[this._key][this._nestedKey], item)
} else {
this.indexForToken(item[this._key], item)
}
Expand Down
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ app.use((req, res, next) => {

/* Communes */
app.get('/communes', initLimit(), initCommuneFields, initCommuneFormat, (req, res) => {
const query = pick(req.query, 'type', 'code', 'codePostal', 'nom', 'codeDepartement', 'codeRegion', 'boost')
const query = pick(req.query, 'type', 'code', 'codePostal', 'nom', 'collectiviteOutremer', 'codeDepartement', 'codeRegion', 'boost')
if (req.query.lat && req.query.lon) {
const lat = parseFloat(req.query.lat)
const lon = parseFloat(req.query.lon)
Expand Down
2 changes: 1 addition & 1 deletion test/communeHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('communeHelpers', () => {
it('empty request should return default fields', done => {
runTestCase(
{},
['nom', 'code', 'codesPostaux', 'codeDepartement', 'codeRegion', 'population'],
['nom', 'code', 'codeDepartement', 'codeRegion', 'codesPostaux', 'population', 'collectiviteOutremer'],
done
)
})
Expand Down