mirror of
https://github.com/immich-app/immich.git
synced 2026-03-01 18:19:10 +03:00
feat(web): display number of likes in asset viewer (#18911)
* feat: display number of likes * fix: properly decrement like count on unlike Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com> * chore: pr feedback * chore: updated related test * chore: formatter run * chore: force numberOfLikes to null in album context to pass lint * chore: open-api updated * fix: use undefined, not null * styling tweaks * chore: updated sql --------- Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com> Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
@@ -67,19 +67,27 @@ export class ActivityRepository {
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [{ albumId: DummyValue.UUID, assetId: DummyValue.UUID }] })
|
||||
async getStatistics({ albumId, assetId }: { albumId: string; assetId?: string }): Promise<number> {
|
||||
const { count } = await this.db
|
||||
async getStatistics({
|
||||
albumId,
|
||||
assetId,
|
||||
}: {
|
||||
albumId: string;
|
||||
assetId?: string;
|
||||
}): Promise<{ comments: number; likes: number }> {
|
||||
const result = await this.db
|
||||
.selectFrom('activity')
|
||||
.select((eb) => eb.fn.countAll<number>().as('count'))
|
||||
.select((eb) => [
|
||||
eb.fn.countAll<number>().filterWhere('activity.isLiked', '=', false).as('comments'),
|
||||
eb.fn.countAll<number>().filterWhere('activity.isLiked', '=', true).as('likes'),
|
||||
])
|
||||
.innerJoin('users', (join) => join.onRef('users.id', '=', 'activity.userId').on('users.deletedAt', 'is', null))
|
||||
.leftJoin('assets', 'assets.id', 'activity.assetId')
|
||||
.$if(!!assetId, (qb) => qb.where('activity.assetId', '=', assetId!))
|
||||
.where('activity.albumId', '=', albumId)
|
||||
.where('activity.isLiked', '=', false)
|
||||
.where('assets.deletedAt', 'is', null)
|
||||
.where('assets.visibility', '!=', sql.lit(AssetVisibility.LOCKED))
|
||||
.executeTakeFirstOrThrow();
|
||||
|
||||
return count;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user