refactor: update asset aggregation to include JSON formatting and ordering by creation date

pull/24033/head
timonrieger 2025-11-20 15:25:08 +07:00
parent 024ef94fb2
commit 8de5e2557e
No known key found for this signature in database
1 changed files with 3 additions and 2 deletions

@ -431,12 +431,13 @@ export class AssetRepository {
eb
.selectFrom('asset as stacked')
.selectAll('stack')
.select((eb) => eb.fn('array_agg', [eb.table('stacked')]).as('assets'))
.select(
sql<unknown[]>`array_agg(to_json(stacked) ORDER BY stacked."fileCreatedAt" ASC)`.as('assets'),
)
.whereRef('stacked.stackId', '=', 'stack.id')
.whereRef('stacked.id', '!=', 'stack.primaryAssetId')
.where('stacked.deletedAt', 'is', null)
.where('stacked.visibility', '=', AssetVisibility.Timeline)
.orderBy('stacked.fileCreatedAt', 'asc')
.groupBy('stack.id')
.as('stacked_assets'),
(join) => join.on('stack.id', 'is not', null),