2019-05-17 19:56:47 +09:00
|
|
|
import { EntityRepository, Repository } from 'typeorm';
|
2021-08-19 18:33:41 +09:00
|
|
|
import { PageLike } from '../entities/page-like.js';
|
|
|
|
import { Pages } from '../index.js';
|
|
|
|
import { User } from '../entities/user.js';
|
2019-05-17 19:56:47 +09:00
|
|
|
|
|
|
|
@EntityRepository(PageLike)
|
|
|
|
export class PageLikeRepository extends Repository<PageLike> {
|
|
|
|
public async pack(
|
|
|
|
src: PageLike['id'] | PageLike,
|
2021-03-24 11:05:37 +09:00
|
|
|
me?: { id: User['id'] } | null | undefined
|
2019-05-17 19:56:47 +09:00
|
|
|
) {
|
2021-02-13 15:33:38 +09:00
|
|
|
const like = typeof src === 'object' ? src : await this.findOneOrFail(src);
|
2019-05-17 19:56:47 +09:00
|
|
|
|
|
|
|
return {
|
|
|
|
id: like.id,
|
|
|
|
page: await Pages.pack(like.page || like.pageId, me),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public packMany(
|
|
|
|
likes: any[],
|
2021-03-24 11:05:37 +09:00
|
|
|
me: { id: User['id'] }
|
2019-05-17 19:56:47 +09:00
|
|
|
) {
|
|
|
|
return Promise.all(likes.map(x => this.pack(x, me)));
|
|
|
|
}
|
|
|
|
}
|