// @ts-check
/**
* @import {ExpressRequestAuthorized, ExpressResponse} from '../types.js'
*/
/**
* Location Router
*
* Handles location management including creating, updating, deleting, and retrieving locations.
* Locations are geographical points associated with groups and users.
*
* @swagger
* components:
* schemas:
* Location:
* type: object
* properties:
* UID:
* type: string
* format: uuid
* UIDBelongsTo:
* type: string
* format: uuid
* Title:
* type: string
* Display:
* type: string
* Data:
* type: object
* properties:
* type:
* type: string
* public:
* type: boolean
* criteria:
* type: object
* geo:
* type: object
* properties:
* lat:
* type: number
* lng:
* type: number
* UIDgroup:
* type: string
* format: uuid
* GroupTitle:
* type: string
* GroupDisplay:
* type: string
* UIDowner:
* type: string
* format: uuid
* OwnerTitle:
* type: string
* OwnerDisplay:
* type: string
*
* tags:
* - name: Location
* description: Location management operations
*/
import express from 'express';
import { checkObjectAdmin, checkVisible } from '../utils/authChecks.js';
import { requestUpdateLogger, readLogger } from '../utils/requestLogger.js';
import { validateSingleUID, validateUUID } from '../utils/uuidValidation.js';
import * as locationController from './location/controller.js';
/** @type {express.Express} */
const api = express();
// Export helper functions for use by other modules
export { addVisibility } from './location/service.js';
/**
* @swagger
* /api/location/{group}:
* put:
* summary: Create or update a location
* description: Creates a new location or updates an existing one. Handles location copies, visibility filters, and group/owner assignments.
* tags:
* - Location
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: group
* required: true
* schema:
* type: string
* format: uuid
* description: Group UID to associate the location with
* - in: query
* name: owner
* schema:
* type: string
* format: uuid
* description: Owner UID (defaults to current user)
* - in: query
* name: copy
* schema:
* type: string
* format: uuid
* description: Copy location UID
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - geo
* - type
* properties:
* geo:
* type: object
* required:
* - lat
* - lng
* properties:
* lat:
* type: number
* lng:
* type: number
* type:
* type: string
* public:
* type: boolean
* visibility:
* type: object
* description: Custom visibility filter rules
* responses:
* 200:
* description: Location created or updated successfully
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* result:
* $ref: '#/components/schemas/Location'
* 300:
* description: Invalid owner or group UID
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* message:
* type: string
*/
// @ts-ignore
api.put('/:group', validateUUID(['group']), requestUpdateLogger, checkObjectAdmin, locationController.createOrUpdateLocationController);
// @ts-ignore
api.put('/:group', validateUUID(['group']), requestUpdateLogger, checkObjectAdmin, locationController.createOrUpdateLocationController);
/**
* @swagger
* /api/location/{UID}:
* delete:
* summary: Delete a location
* description: Deletes a location and all its associated links
* tags:
* - Location
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: UID
* required: true
* schema:
* type: string
* format: uuid
* description: Location UID to delete
* responses:
* 200:
* description: Location deleted successfully
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
*/
// @ts-ignore
api.delete('/:UID', validateSingleUID, requestUpdateLogger, locationController.deleteLocationController);
// @ts-ignore
api.delete('/:UID', validateSingleUID, requestUpdateLogger, locationController.deleteLocationController);
/**
* @swagger
* /api/location/{UID}:
* get:
* summary: Get a single location
* description: Retrieves detailed information about a specific location including group and owner details
* tags:
* - Location
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: UID
* required: true
* schema:
* type: string
* format: uuid
* description: Location UID to retrieve
* responses:
* 200:
* description: Location retrieved successfully
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* result:
* $ref: '#/components/schemas/Location'
* message:
* type: string
*/
// @ts-ignore
api.get('/:UID', validateSingleUID, readLogger, checkVisible, locationController.getLocationController);
// @ts-ignore
api.get('/:UID', validateSingleUID, readLogger, checkVisible, locationController.getLocationController);
/**
* @swagger
* /api/location:
* get:
* summary: Get location listing
* description: Retrieves a list of locations with optional filtering, pagination, and data field selection
* tags:
* - Location
* security:
* - bearerAuth: []
* parameters:
* - in: query
* name: __page
* schema:
* type: integer
* description: Page number for pagination (optional)
* - in: query
* name: types
* schema:
* type: string
* description: JSON array or single type to filter locations
* - in: query
* name: Data
* schema:
* type: string
* description: Specify 'all' for full data or JSON array of field specifications
* - in: query
* name: filter
* schema:
* type: string
* description: JSON filter criteria for location data
* responses:
* 200:
* description: Location listing retrieved successfully
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* result:
* type: array
* items:
* $ref: '#/components/schemas/Location'
*/
// @ts-ignore
api.get('/', readLogger, locationController.getLocationListingController);
export default api;