Skip to content

Commit

Permalink
don't search for null dates
Browse files Browse the repository at this point in the history
  • Loading branch information
etnoy committed Feb 2, 2025
1 parent b632b84 commit 0700b45
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
17 changes: 8 additions & 9 deletions server/src/dtos/asset-response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,16 @@ const hexOrBufferToBase64 = (encoded: string | Buffer) => {
return encoded.toString('base64');
};

export function mapAsset(entity: AssetEntity, options: AssetMapOptions = {}): AssetResponseDto {
export function mapAsset(
entity: AssetEntity & { localDateTime: NonNullable<AssetEntity['localDateTime']> } & {
fileCreatedAt: NonNullable<AssetEntity['fileCreatedAt']>;
} & {
fileModifiedAt: NonNullable<AssetEntity['fileModifiedAt']>;
},
options: AssetMapOptions = {},
): AssetResponseDto {
const { stripMetadata = false, withStack = false } = options;

if (!entity.localDateTime) {
throw new Error('Asset localDateTime is missing');
} else if (!entity.fileCreatedAt) {
throw new Error('Asset fileCreatedAt is missing');
} else if (!entity.fileModifiedAt) {
throw new Error('Asset fileModifiedAt is missing');
}

if (stripMetadata) {
const sanitizedAssetResponse: SanitizedAssetResponseDto = {
id: entity.id,
Expand Down
6 changes: 3 additions & 3 deletions server/src/entities/asset.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export function searchAssetBuilder(kysely: Kysely<DB>, options: AssetSearchBuild
.$if(!!options.withExif, withExifInner)
.$if(!!(options.withFaces || options.withPeople || options.personIds), (qb) => qb.select(withFacesAndPeople))
.$if(!options.withDeleted, (qb) => qb.where('assets.deletedAt', 'is', null))
.$if(!options.withNullFileModifiedAt, (qb) => qb.where('assets.fileModifiedAt', 'is not', null))
.$if(!options.withNullFileCreatedAt, (qb) => qb.where('assets.fileCreatedAt', 'is not', null))
.$if(!options.withNullLocalDateTime, (qb) => qb.where('assets.localDateTime', 'is not', null));
.where('assets.fileCreatedAt', 'is not', null)
.where('assets.fileModifiedAt', 'is not', null)
.where('assets.localDateTime', 'is not', null);
}
3 changes: 0 additions & 3 deletions server/src/interfaces/search.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ export interface SearchStatusOptions {
status?: AssetStatus;
withArchived?: boolean;
withDeleted?: boolean;
withNullLocalDateTime?: boolean;
withNullFileCreatedAt?: boolean;
withNullFileModifiedAt?: boolean;
}

export interface SearchOneToOneRelationOptions {
Expand Down

0 comments on commit 0700b45

Please sign in to comment.