feat: implement multi-city support with city management features
- Added a new cities table to the database to manage multiple cities independently. - Created a middleware to resolve city context based on X-City-Id header. - Updated routes and services to handle city-specific data for routes, stops, and alerts. - Implemented a CityContext in the frontend to manage active city state and provide city data across the application. - Added a CitySelector component for users to switch between cities. - Created a CitiesPage for admins to manage cities, including adding new cities with validation. - Updated various components and pages to reflect the active city context, ensuring data is displayed correctly based on the selected city. - Enhanced the schedule import functionality to restrict imports based on the active city.
This commit is contained in:
@@ -277,9 +277,23 @@ function buildQualityReport(rowsByCheck, checkedAt = new Date().toISOString()) {
|
||||
return { checked_at: checkedAt, summary, issues };
|
||||
}
|
||||
|
||||
async function runQualityChecks(pool) {
|
||||
const results = await Promise.all(qualityChecks.map(async ({ name, query }) => [name, (await pool.query(query)).rows]));
|
||||
function withCityScope(query, cityId) {
|
||||
if (!cityId) return { query, params: [] };
|
||||
return {
|
||||
query: query
|
||||
.replaceAll('r.is_active = true', 'r.is_active = true AND r.city_id = $1')
|
||||
.replace('WHERE s.is_active = true', 'WHERE s.is_active = true AND s.city_id = $1')
|
||||
.replace('WHERE a.is_active = true', 'WHERE a.is_active = true AND a.city_id = $1'),
|
||||
params: [cityId]
|
||||
};
|
||||
}
|
||||
|
||||
async function runQualityChecks(pool, cityId = null) {
|
||||
const results = await Promise.all(qualityChecks.map(async ({ name, query }) => {
|
||||
const scoped = withCityScope(query, cityId);
|
||||
return [name, (await pool.query(scoped.query, scoped.params)).rows];
|
||||
}));
|
||||
return buildQualityReport(Object.fromEntries(results));
|
||||
}
|
||||
|
||||
module.exports = { buildQualityReport, qualityChecks, runQualityChecks };
|
||||
module.exports = { buildQualityReport, qualityChecks, runQualityChecks, withCityScope };
|
||||
|
||||
Reference in New Issue
Block a user