
* chore: 著作権とライセンスについての情報を各ファイルに追加する * chore: Add the SPDX information to each file Add copyright and licensing information as defined in version 3.0 of the REUSE Specification. * tweak format --------- Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * chore: Add SPDX-License-Identifier [skip ci] * add missing SPDX-License-Identifier * remove unused file --------- Co-authored-by: Shun Sakai <sorairolake@protonmail.ch> Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> Co-authored-by: Chocolate Pie <106949016+chocolate-pie@users.noreply.github.com>
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
import { DI } from '@/di-symbols.js';
|
|
import type { GalleryLikesRepository } from '@/models/index.js';
|
|
import type { GalleryLike } from '@/models/entities/GalleryLike.js';
|
|
import { bindThis } from '@/decorators.js';
|
|
import { Packed } from '@/misc/json-schema.js';
|
|
import type { User } from '@/models/entities/User.js';
|
|
import { GalleryPostEntityService } from './GalleryPostEntityService.js';
|
|
|
|
@Injectable()
|
|
export class GalleryLikeEntityService {
|
|
constructor(
|
|
@Inject(DI.galleryLikesRepository)
|
|
private galleryLikesRepository: GalleryLikesRepository,
|
|
|
|
private galleryPostEntityService: GalleryPostEntityService,
|
|
) {
|
|
}
|
|
|
|
@bindThis
|
|
public async pack(
|
|
src: GalleryLike['id'] | GalleryLike,
|
|
me: { id: User['id'] } | null | undefined,
|
|
) : Promise<Packed<'GalleryLike'>> {
|
|
const like = typeof src === 'object' ? src : await this.galleryLikesRepository.findOneByOrFail({ id: src });
|
|
|
|
return {
|
|
id: like.id,
|
|
post: await this.galleryPostEntityService.pack(like.post ?? like.postId, me),
|
|
};
|
|
}
|
|
|
|
@bindThis
|
|
public async packMany(
|
|
likes: (GalleryLike['id'] | GalleryLike)[],
|
|
me: { id: User['id'] } | null | undefined,
|
|
) : Promise<Packed<'GalleryLike'>[]> {
|
|
return (await Promise.allSettled(likes.map(x => this.pack(x, me))))
|
|
.filter(result => result.status === 'fulfilled')
|
|
.map(result => (result as PromiseFulfilledResult<Packed<'GalleryLike'>>).value);
|
|
}
|
|
}
|
|
|