Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed Jan 2, 2024
2 parents 725b6c5 + ef4fbe9 commit 53c8537
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/api/geographicalcategories/root/root.middlewares.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ export async function getGeographicalCategoryById(req, res, next) {
if (!geographicalCategory) {
return res.status(404).json({ error: 'Geographical category not found' });
}

req.geographicalCategory = geographicalCategory;

return next();
} catch (error) {
return res.status(500).json({ error: 'An error occurred while fetching data' });
}
}

export async function getStructureFromGeoCategory(req, res, next) {
try {
const { geographicalCategory } = req;

const { limit, skip } = req.query;

const filters = {
'localisations.geometry': {
$geoWithin: {
Expand All @@ -38,7 +41,7 @@ export async function getStructureFromGeoCategory(req, res, next) {

filters['localisations.active'] = { $ne: false };

const { data } = await structuresRepository.find({ filters, useQuery: readQuery });
const { data } = await structuresRepository.find({ filters, useQuery: readQuery, limit, skip });
res.status(200).json({ data, totalCount: data.length });
next();
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions src/api/search/search.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ router.route('/autocomplete')
bool: {
should: [{
query_string: {
query: `*"${query.replace(/-/g, ' ')}"*`,
query: `*"${query.replace(/[-_]/g, ' ')}"*`,
default_operator: 'AND',
fields: searchedFields,
},
}, {
query_string: {
query: `*${query.replace(/-/g, ' ')}*`,
query: `*${query.replace(/[-_]/g, ' ')}*`,
default_operator: 'AND',
fields: searchedFields,
},
Expand Down
2 changes: 2 additions & 0 deletions src/openapi/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ paths:
$ref: './paths/geographicalcategories/geographicalcategories.yml#/collectionMethods'
'/geographical-categories/{geographicalCategoryId}':
$ref: './paths/geographicalcategories/geographicalcategories.yml#/documentMethods'
'/geographical-categories/{geographicalCategoryId}/structures':
$ref: './paths/geographicalcategories/structures-from-categories.yml#/collectionMethods'

### GEOGRAPHICAL CATEGORIES ###
'/geographical-exception':
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

collectionMethods:
get:
tags:
- Geographical categories - Structures
summary: List structures from a geographical categories
parameters:
- $ref: '../../api.yml#/components/parameters/filters'
- $ref: '../../api.yml#/components/parameters/skip'
- $ref: '../../api.yml#/components/parameters/limit'
- $ref: '../../api.yml#/components/parameters/sort'
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: '../../api.yml#/components/schemas/GeographicalCategory'
totalCount:
type: integer
'400':
$ref: '../../api.yml#/components/responses/BadRequest'
'401':
$ref: '../../api.yml#/components/responses/Unauthorized'
'403':
$ref: '../../api.yml#/components/responses/Forbidden'
'404':
$ref: '../../api.yml#/components/responses/NotFound'
'500':
$ref: '../../api.yml#/components/responses/ServerError'

0 comments on commit 53c8537

Please sign in to comment.