Skip to content

Commit 2c2242a

Browse files
authored
Merge pull request #86 from StreetSupport/staging
Merge staging into main
2 parents 5e0214e + 6dd3126 commit 2c2242a

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/controllers/cityController.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,26 @@ import mongoose from 'mongoose';
1010
* @access Private
1111
*/
1212
export const getCities = asyncHandler(async (req: Request, res: Response) => {
13-
const { locations } = req.query; // Optional: comma-separated list of location slugs for filtering
14-
13+
const { locations, isPublic } = req.query; // Optional: comma-separated list of location slugs for filtering
14+
1515
// Build query based on location filter
1616
const query: any = {};
17-
17+
1818
if (locations && typeof locations === 'string') {
1919
// Filter by specific locations (used for CityAdmin users)
2020
const locationArray = locations.split(',').map(loc => loc.trim()).filter(Boolean);
2121
if (locationArray.length > 0) {
2222
query.Key = { $in: locationArray };
2323
}
2424
}
25-
25+
26+
// Filter by IsPublic status
27+
if (isPublic === 'true') {
28+
query.IsPublic = true;
29+
} else if (isPublic === 'false') {
30+
query.IsPublic = false;
31+
}
32+
2633
const cities = await Cities.find(query).lean();
2734
return sendSuccess(res, cities);
2835
});

src/controllers/swepBannerController.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { asyncHandler } from '../utils/asyncHandler.js';
33
import { sendSuccess, sendBadRequest, sendNotFound, sendPaginatedSuccess } from '../utils/apiResponses.js';
44
import { validateSwepBanner } from '../schemas/swepBannerSchema.js';
55
import SwepBanner from '../models/swepModel.js';
6+
import Cities from '../models/cityModel.js';
67
import { deleteFile } from '../middleware/uploadMiddleware.js';
78

89
// @desc Get all SWEP banners with optional filtering
@@ -23,6 +24,11 @@ export const getSwepBanners = asyncHandler(async (req: Request, res: Response) =
2324
const query: any = {};
2425
const conditions: any[] = [];
2526

27+
// Get public city keys to filter SWEP banners
28+
const publicCities = await Cities.find({ IsPublic: true }).select('Key').lean();
29+
const publicCityKeys = publicCities.map(city => city.Key);
30+
conditions.push({ LocationSlug: { $in: publicCityKeys } });
31+
2632
// Apply search filter
2733
if (search && typeof search === 'string') {
2834
conditions.push({
@@ -38,7 +44,9 @@ export const getSwepBanners = asyncHandler(async (req: Request, res: Response) =
3844
if (locations && typeof locations === 'string') {
3945
const locationArray = locations.split(',').map(loc => loc.trim()).filter(Boolean);
4046
if (locationArray.length > 0) {
41-
conditions.push({ LocationSlug: { $in: locationArray } });
47+
// Intersect with public cities
48+
const filteredLocations = locationArray.filter(loc => publicCityKeys.includes(loc));
49+
conditions.push({ LocationSlug: { $in: filteredLocations } });
4250
}
4351
} else if (location && typeof location === 'string') {
4452
conditions.push({ LocationSlug: location });

0 commit comments

Comments
 (0)