mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
feat(web+server): map date filters + small changes (#2565)
This commit is contained in:
parent
bcc2c34eef
commit
062e2eca6f
18 changed files with 429 additions and 178 deletions
|
|
@ -15,6 +15,8 @@ export interface LivePhotoSearchOptions {
|
|||
|
||||
export interface MapMarkerSearchOptions {
|
||||
isFavorite?: boolean;
|
||||
fileCreatedBefore?: string;
|
||||
fileCreatedAfter?: string;
|
||||
}
|
||||
|
||||
export interface MapMarker {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,22 @@
|
|||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { toBoolean } from 'apps/immich/src/utils/transform.util';
|
||||
import { Transform } from 'class-transformer';
|
||||
import { IsBoolean, IsOptional } from 'class-validator';
|
||||
import { IsBoolean, IsISO8601, IsOptional } from 'class-validator';
|
||||
|
||||
export class MapMarkerDto {
|
||||
@ApiProperty()
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@Transform(toBoolean)
|
||||
isFavorite?: boolean;
|
||||
|
||||
@ApiProperty({ format: 'date-time' })
|
||||
@IsOptional()
|
||||
@IsISO8601({ strict: true, strictSeparator: true })
|
||||
fileCreatedAfter?: string;
|
||||
|
||||
@ApiProperty({ format: 'date-time' })
|
||||
@IsOptional()
|
||||
@IsISO8601({ strict: true, strictSeparator: true })
|
||||
fileCreatedBefore?: string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import { InjectRepository } from '@nestjs/typeorm';
|
|||
import { FindOptionsRelations, FindOptionsWhere, In, IsNull, Not, Repository } from 'typeorm';
|
||||
import { AssetEntity, AssetType } from '../entities';
|
||||
import { paginate } from '../utils/pagination.util';
|
||||
import OptionalBetween from '../utils/optional-between.util';
|
||||
|
||||
@Injectable()
|
||||
export class AssetRepository implements IAssetRepository {
|
||||
|
|
@ -212,7 +213,7 @@ export class AssetRepository implements IAssetRepository {
|
|||
}
|
||||
|
||||
async getMapMarkers(ownerId: string, options: MapMarkerSearchOptions = {}): Promise<MapMarker[]> {
|
||||
const { isFavorite } = options;
|
||||
const { isFavorite, fileCreatedAfter, fileCreatedBefore } = options;
|
||||
|
||||
const assets = await this.repository.find({
|
||||
select: {
|
||||
|
|
@ -231,6 +232,7 @@ export class AssetRepository implements IAssetRepository {
|
|||
longitude: Not(IsNull()),
|
||||
},
|
||||
isFavorite,
|
||||
fileCreatedAt: OptionalBetween(fileCreatedAfter, fileCreatedBefore),
|
||||
},
|
||||
relations: {
|
||||
exifInfo: true,
|
||||
|
|
|
|||
15
server/libs/infra/src/utils/optional-between.util.ts
Normal file
15
server/libs/infra/src/utils/optional-between.util.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { Between, LessThanOrEqual, MoreThanOrEqual } from 'typeorm';
|
||||
|
||||
/**
|
||||
* Allows optional values unlike the regular Between and uses MoreThanOrEqual
|
||||
* or LessThanOrEqual when only one parameter is specified.
|
||||
*/
|
||||
export default function OptionalBetween<T>(from?: T, to?: T) {
|
||||
if (from && to) {
|
||||
return Between(from, to);
|
||||
} else if (from) {
|
||||
return MoreThanOrEqual(from);
|
||||
} else if (to) {
|
||||
return LessThanOrEqual(to);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue