Browse Source

update filter city for province_id

pearlgw 3 weeks ago
parent
commit
dfc16899aa
2 changed files with 5 additions and 3 deletions
  1. 2 2
      src/controllers/admin/CityController.ts
  2. 3 1
      src/services/admin/CityService.ts

+ 2 - 2
src/controllers/admin/CityController.ts

@@ -9,8 +9,8 @@ import { CustomRequest } from '../../types/token/CustomRequest';
9 9
 
10 10
 export const getAllCity = async (req: Request, res: Response): Promise<Response> => {
11 11
     try {
12
-        const { page, limit, search, sortBy, orderBy } = PaginationParam(req);
13
-        const { cities, total } = await CityService.getAllCityService({ page, limit, search, sortBy, orderBy });
12
+        const { page, limit, search, sortBy, orderBy, province_id, } = PaginationParam(req, ['province_id']);
13
+        const { cities, total } = await CityService.getAllCityService({ page, limit, search, sortBy, orderBy, province_id });
14 14
 
15 15
         return CityCollection(req, res, cities, total, page, limit, 'City data successfully retrieved');
16 16
     } catch (err) {

+ 3 - 1
src/services/admin/CityService.ts

@@ -15,13 +15,15 @@ interface GetAllCityParams {
15 15
     search?: string;
16 16
     sortBy: string;
17 17
     orderBy: 'asc' | 'desc';
18
+    province_id?: string;
18 19
 }
19 20
 
20
-export const getAllCityService = async ({ page, limit, search = '', sortBy, orderBy, }: GetAllCityParams) => {
21
+export const getAllCityService = async ({ page, limit, search = '', sortBy, orderBy, province_id }: GetAllCityParams) => {
21 22
     const skip = (page - 1) * limit;
22 23
 
23 24
     const where: Prisma.CityWhereInput = {
24 25
         ...SearchFilter(search, ['id', 'name', 'province.id']),
26
+        ...(province_id ? { province_id: province_id } : {}),
25 27
         deletedAt: null,
26 28
     };
27 29