mirror of
https://github.com/immich-app/immich.git
synced 2026-04-12 22:08:29 -04:00
* refactor(server): config service * fix: function renaming --------- Co-authored-by: Daniel Dietzler <mail@ddietzler.dev>
43 lines
1.7 KiB
TypeScript
43 lines
1.7 KiB
TypeScript
import { Inject } from '@nestjs/common';
|
|
import { AuthDto } from 'src/dtos/auth.dto';
|
|
import { MapMarkerDto, MapMarkerResponseDto, MapReverseGeocodeDto } from 'src/dtos/map.dto';
|
|
import { IAlbumRepository } from 'src/interfaces/album.interface';
|
|
import { IMapRepository } from 'src/interfaces/map.interface';
|
|
import { IPartnerRepository } from 'src/interfaces/partner.interface';
|
|
import { getMyPartnerIds } from 'src/utils/asset.util';
|
|
|
|
export class MapService {
|
|
constructor(
|
|
@Inject(IAlbumRepository) private albumRepository: IAlbumRepository,
|
|
@Inject(IPartnerRepository) private partnerRepository: IPartnerRepository,
|
|
@Inject(IMapRepository) private mapRepository: IMapRepository,
|
|
) {}
|
|
|
|
async getMapMarkers(auth: AuthDto, options: MapMarkerDto): Promise<MapMarkerResponseDto[]> {
|
|
const userIds = [auth.user.id];
|
|
if (options.withPartners) {
|
|
const partnerIds = await getMyPartnerIds({ userId: auth.user.id, repository: this.partnerRepository });
|
|
userIds.push(...partnerIds);
|
|
}
|
|
|
|
// TODO convert to SQL join
|
|
const albumIds: string[] = [];
|
|
if (options.withSharedAlbums) {
|
|
const [ownedAlbums, sharedAlbums] = await Promise.all([
|
|
this.albumRepository.getOwned(auth.user.id),
|
|
this.albumRepository.getShared(auth.user.id),
|
|
]);
|
|
albumIds.push(...ownedAlbums.map((album) => album.id), ...sharedAlbums.map((album) => album.id));
|
|
}
|
|
|
|
return this.mapRepository.getMapMarkers(userIds, albumIds, options);
|
|
}
|
|
|
|
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] : [];
|
|
}
|
|
}
|