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