|
|
@@ -8,8 +8,11 @@ import {
|
|
|
listLocationsSchema,
|
|
|
deleteLocationSchema,
|
|
|
toggleLocationStatusSchema,
|
|
|
- searchLocationsSchema
|
|
|
+ searchLocationsSchema,
|
|
|
+ locationListResponseSchema
|
|
|
} from '@/server/modules/locations/location.schema';
|
|
|
+import { LocationService } from '@/server/modules/locations/location.service';
|
|
|
+import { AppDataSource } from '@/server/data-source';
|
|
|
|
|
|
// 使用通用CRUD路由创建地点管理API
|
|
|
export default createCrudRoutes({
|
|
|
@@ -17,14 +20,10 @@ export default createCrudRoutes({
|
|
|
createSchema: createLocationSchema,
|
|
|
updateSchema: updateLocationSchema,
|
|
|
getSchema: getLocationSchema,
|
|
|
- listSchema: listLocationsSchema,
|
|
|
- deleteSchema: deleteLocationSchema,
|
|
|
- toggleStatusSchema: toggleLocationStatusSchema,
|
|
|
+ listSchema: locationListResponseSchema,
|
|
|
searchFields: ['name', 'address'],
|
|
|
- filterFields: ['provinceId', 'cityId', 'districtId', 'isDisabled'],
|
|
|
- sortFields: ['name', 'provinceId', 'cityId', 'districtId', 'createdAt'],
|
|
|
relations: ['province', 'city', 'district'],
|
|
|
- middlewares: [authMiddleware]
|
|
|
+ middleware: [authMiddleware]
|
|
|
})
|
|
|
// 搜索地点
|
|
|
.get('/search', authMiddleware, async (c) => {
|
|
|
@@ -39,7 +38,7 @@ export default createCrudRoutes({
|
|
|
}, 400);
|
|
|
}
|
|
|
|
|
|
- const locationService = c.get('locationService');
|
|
|
+ const locationService = new LocationService(AppDataSource);
|
|
|
const locations = await locationService.searchLocations(validation.data);
|
|
|
return c.json({
|
|
|
success: true,
|