Created
September 15, 2024 01:28
-
-
Save jschwalbe/d2a36e5ed2ed955b42c5aa87cc05948d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server/src/interfaces/search.interface.ts | |
------------------- | |
export interface SearchOrderOptions { | |
orderDirection?: 'ASC' | 'DESC'; | |
} | |
to | |
export interface SearchOrderOptions { | |
orderDirection?: 'ASC' | 'DESC' | 'RAND'; | |
} | |
search.repository.ts | |
-------------------- | |
async searchMetadata(pagination: SearchPaginationOptions, options: AssetSearchOptions): Paginated<AssetEntity> { | |
let builder = this.assetRepository.createQueryBuilder('asset'); | |
builder = searchAssetBuilder(builder, options); | |
builder.orderBy('asset.fileCreatedAt', options.orderDirection ?? 'DESC'); | |
return paginatedBuilder<AssetEntity>(builder, { | |
mode: PaginationMode.SKIP_TAKE, | |
skip: (pagination.page - 1) * pagination.size, | |
take: pagination.size, | |
}); | |
} | |
to | |
async searchMetadata(pagination: SearchPaginationOptions, options: AssetSearchOptions): Paginated<AssetEntity> { | |
let builder = this.assetRepository.createQueryBuilder('asset'); | |
builder = searchAssetBuilder(builder, options); | |
if (options.orderDirection === 'RAND') { | |
// Sort by random | |
builder.orderBy('RANDOM()'); | |
} else { | |
// Default sorting by fileCreatedAt with ASC/DESC | |
builder.orderBy('asset.fileCreatedAt', options.orderDirection ?? 'DESC'); | |
} | |
return paginatedBuilder<AssetEntity>(builder, { | |
mode: PaginationMode.SKIP_TAKE, | |
skip: (pagination.page - 1) * pagination.size, | |
take: pagination.size, | |
}); | |
} | |
server/src/enum.ts | |
------------------ | |
export enum AssetOrder { | |
ASC = 'asc', | |
DESC = 'desc', | |
} | |
to | |
export enum AssetOrder { | |
ASC = 'asc', | |
DESC = 'desc', | |
RAND = 'rand', | |
} | |
open-api/immich-openapi-specs.json | |
---------------------------------- | |
"AssetOrder": { | |
"enum": [ | |
"asc", | |
"desc" | |
], | |
"type": "string" | |
}, | |
to | |
"AssetOrder": { | |
"enum": [ | |
"asc", | |
"desc", | |
"rand" | |
], | |
"type": "string" | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment