90 lines
3.8 KiB
JavaScript
90 lines
3.8 KiB
JavaScript
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
};
|
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
};
|
|
var GeocodingService_1;
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.GeocodingService = void 0;
|
|
const common_1 = require("@nestjs/common");
|
|
const typeorm_1 = require("@nestjs/typeorm");
|
|
const typeorm_2 = require("typeorm");
|
|
const place_syria_entity_1 = require("./entities/place-syria.entity");
|
|
const osm_area_entity_1 = require("./entities/osm-area.entity");
|
|
const osm_point_with_area_entity_1 = require("./entities/osm-point-with-area.entity");
|
|
let GeocodingService = GeocodingService_1 = class GeocodingService {
|
|
placesRepository;
|
|
osmAreasRepository;
|
|
osmPointsRepository;
|
|
logger = new common_1.Logger(GeocodingService_1.name);
|
|
constructor(placesRepository, osmAreasRepository, osmPointsRepository) {
|
|
this.placesRepository = placesRepository;
|
|
this.osmAreasRepository = osmAreasRepository;
|
|
this.osmPointsRepository = osmPointsRepository;
|
|
}
|
|
async searchPlaces(query) {
|
|
if (!query || query.length < 3)
|
|
return { userPlaces: [], osmAreas: [] };
|
|
const userPlaces = await this.placesRepository.find({
|
|
where: [
|
|
{ name: (0, typeorm_2.Like)(`%${query}%`) },
|
|
{ name_ar: (0, typeorm_2.Like)(`%${query}%`) },
|
|
],
|
|
take: 10,
|
|
});
|
|
const osmAreas = await this.osmAreasRepository.find({
|
|
where: [
|
|
{ name: (0, typeorm_2.Like)(`%${query}%`) },
|
|
{ name_ar: (0, typeorm_2.Like)(`%${query}%`) },
|
|
],
|
|
take: 10,
|
|
});
|
|
return {
|
|
userPlaces,
|
|
osmAreas,
|
|
};
|
|
}
|
|
async reverseGeocode(lat, lng) {
|
|
try {
|
|
const query = `
|
|
SELECT *, ST_Distance_Sphere(location, POINT(?, ?)) as distance
|
|
FROM places_syria
|
|
WHERE location IS NOT NULL
|
|
ORDER BY distance ASC
|
|
LIMIT 5
|
|
`;
|
|
const results = await this.placesRepository.query(query, [lng, lat]);
|
|
return results;
|
|
}
|
|
catch (error) {
|
|
this.logger.error('Reverse geocoding error:', error);
|
|
return [];
|
|
}
|
|
}
|
|
async addPlace(data) {
|
|
const newPlace = this.placesRepository.create({
|
|
...data,
|
|
created_at: new Date(),
|
|
});
|
|
return this.placesRepository.save(newPlace);
|
|
}
|
|
};
|
|
exports.GeocodingService = GeocodingService;
|
|
exports.GeocodingService = GeocodingService = GeocodingService_1 = __decorate([
|
|
(0, common_1.Injectable)(),
|
|
__param(0, (0, typeorm_1.InjectRepository)(place_syria_entity_1.PlaceSyria, 'mysqlConnection')),
|
|
__param(1, (0, typeorm_1.InjectRepository)(osm_area_entity_1.OsmArea, 'mysqlConnection')),
|
|
__param(2, (0, typeorm_1.InjectRepository)(osm_point_with_area_entity_1.OsmPointWithArea, 'mysqlConnection')),
|
|
__metadata("design:paramtypes", [typeorm_2.Repository,
|
|
typeorm_2.Repository,
|
|
typeorm_2.Repository])
|
|
], GeocodingService);
|
|
//# sourceMappingURL=geocoding.service.js.map
|