2025-02-11 17:15:56 -05:00
|
|
|
import { Injectable } from '@nestjs/common';
|
2024-05-29 17:51:01 +02:00
|
|
|
import { AuthDto } from 'src/dtos/auth.dto';
|
2024-07-29 18:17:26 -04:00
|
|
|
import { MapMarkerDto, MapMarkerResponseDto, MapReverseGeocodeDto } from 'src/dtos/map.dto';
|
2024-10-02 10:54:35 -04:00
|
|
|
import { BaseService } from 'src/services/base.service';
|
2024-06-14 18:29:32 -04:00
|
|
|
import { getMyPartnerIds } from 'src/utils/asset.util';
|
2024-05-29 17:51:01 +02:00
|
|
|
|
2025-02-11 17:15:56 -05:00
|
|
|
@Injectable()
|
2024-10-02 10:54:35 -04:00
|
|
|
export class MapService extends BaseService {
|
2024-05-29 17:51:01 +02:00
|
|
|
async getMapMarkers(auth: AuthDto, options: MapMarkerDto): Promise<MapMarkerResponseDto[]> {
|
2024-06-14 18:29:32 -04:00
|
|
|
const userIds = [auth.user.id];
|
2024-05-29 17:51:01 +02:00
|
|
|
if (options.withPartners) {
|
2024-06-14 18:29:32 -04:00
|
|
|
const partnerIds = await getMyPartnerIds({ userId: auth.user.id, repository: this.partnerRepository });
|
|
|
|
|
userIds.push(...partnerIds);
|
2024-05-29 17:51:01 +02:00
|
|
|
}
|
|
|
|
|
|
2026-05-07 18:13:07 +02:00
|
|
|
const albumIds = options.withSharedAlbums ? await this.albumRepository.getAllIds(auth.user.id) : [];
|
2024-05-29 17:51:01 +02:00
|
|
|
|
|
|
|
|
return this.mapRepository.getMapMarkers(userIds, albumIds, options);
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-29 18:17:26 -04:00
|
|
|
async reverseGeocode(dto: MapReverseGeocodeDto) {
|
|
|
|
|
const { lat: latitude, lon: longitude } = dto;
|
|
|
|
|
// eventually this should probably return an array of results
|
|
|
|
|
const result = await this.mapRepository.reverseGeocode({ latitude, longitude });
|
|
|
|
|
return result ? [result] : [];
|
|
|
|
|
}
|
2024-05-29 17:51:01 +02:00
|
|
|
}
|