Files
Server/services/transportService.js
azures04 e5eccb77db Add transport DDL, repos and transport service
Add database DDL and server-side data access/service layers for transport domain. New SQL DDL files create transport_types, lines, stations, platforms and platform_lines tables (with FKs, indexes, spatial POINT column, CHECK constraints, and triggers to populate location). New repositories implement queries and CRUD for lines, stations, platforms and platform_lines (including distance/nearest-platform and accessibility queries). A transportService aggregates repo functions and exposes high-level operations (CRUD, station/line lookups, platform-line management and nearest-platform validation).
2026-09-22 10:27:12 +02:00

220 lines
4.7 KiB
JavaScript

const lineRepo = require("../repositories/lineRepo")
const stationRepo = require("../repositories/stationRepo")
const platformRepo = require("../repositories/platformRepo")
const platformLineRepo = require("../repositories/platformLineRepo")
/* ---------- LINES ---------- */
async function getAllLines() {
return await lineRepo.findAllLines()
}
async function getLineById({ lineId }) {
return await lineRepo.findLineById(lineId)
}
async function getLinesByTransportType({ transportTypeId }) {
return await lineRepo.findLinesByTransportType(transportTypeId)
}
async function createLine({
code,
name,
textColorHex,
backColorHex,
transportTypeId
}) {
return await lineRepo.createLine(
code,
name,
textColorHex,
backColorHex,
transportTypeId
)
}
async function updateLine({ lineId, updateData }) {
return await lineRepo.updateLine(lineId, updateData)
}
async function deleteLine({ lineId }) {
return await lineRepo.deleteLine(lineId)
}
/* ---------- STATIONS ---------- */
async function getAllStations() {
return await stationRepo.findAllStations()
}
async function getStationById({ stationId }) {
return await stationRepo.findStationById(stationId)
}
async function getStationsByDistance({ latitude, longitude, radiusKm }) {
return await stationRepo.findStationsByDistance(
latitude,
longitude,
radiusKm
)
}
async function getAccessibleStations({ latitude, longitude, radiusKm }) {
return await stationRepo.findAccessibleStations(
latitude,
longitude,
radiusKm
)
}
async function createStation({ name, description }) {
return await stationRepo.createStation(name, description)
}
async function updateStation({ stationId, updateData }) {
return await stationRepo.updateStation(stationId, updateData)
}
async function deleteStation({ stationId }) {
return await stationRepo.deleteStation(stationId)
}
/* ---------- PLATFORMS ---------- */
async function getPlatformsByStation({ stationId }) {
return await platformRepo.findPlatformsByStation(stationId)
}
async function getPlatformById({ platformId }) {
return await platformRepo.findPlatformById(platformId)
}
async function createPlatform({
stationId,
name,
direction,
latitude,
longitude,
isPRM = false,
hasElevator = false
}) {
return await platformRepo.createPlatform(
stationId,
name,
direction,
latitude,
longitude,
isPRM,
hasElevator
)
}
async function updatePlatformAccessibility({
platformId,
isPRM,
hasElevator
}) {
return await platformRepo.updatePlatformAccessibility(
platformId,
isPRM,
hasElevator
)
}
async function deletePlatform({ platformId }) {
return await platformRepo.deletePlatform(platformId)
}
/* ---------- PLATFORM <-> LINES ---------- */
async function getStationLines({ stationId }) {
return await platformLineRepo.findLinesByStation(stationId)
}
async function getPlatformLines({ platformId }) {
return await platformLineRepo.findLinesByPlatform(platformId)
}
async function getLineStations({ lineId, directionId = 0 }) {
return await platformLineRepo.findStationsByLine(lineId, directionId)
}
async function addLineToPlatform({
platformId,
lineId,
directionId = 0,
orderInLine
}) {
return await platformLineRepo.addLineToPlatform(
platformId,
lineId,
directionId,
orderInLine
)
}
async function removeLineFromPlatform({
platformId,
lineId,
directionId = 0
}) {
return await platformLineRepo.removeLineFromPlatform(
platformId,
lineId,
directionId
)
}
async function updatePlatformLineOrder({ platformLineId, orderInLine }) {
return await platformLineRepo.updateOrder(platformLineId, orderInLine)
}
/* ---------- VALIDATION ---------- */
const DEFAULT_RADIUS_M = 100
async function findNearestPlatformForLine({
lineId,
latitude,
longitude,
radiusM = DEFAULT_RADIUS_M
}) {
return await platformRepo.findNearestPlatformForLine(
lineId,
latitude,
longitude,
radiusM
)
}
module.exports = {
getAllLines,
getLineById,
getLinesByTransportType,
createLine,
updateLine,
deleteLine,
getAllStations,
getStationById,
getStationsByDistance,
getAccessibleStations,
createStation,
updateStation,
deleteStation,
getPlatformsByStation,
getPlatformById,
createPlatform,
updatePlatformAccessibility,
deletePlatform,
getStationLines,
getPlatformLines,
getLineStations,
addLineToPlatform,
removeLineFromPlatform,
updatePlatformLineOrder,
findNearestPlatformForLine
}