2021-04-24 16:38:24 +03:00
|
|
|
import { EntityRepository, Repository } from 'typeorm';
|
2021-08-19 15:55:45 +03:00
|
|
|
import { GalleryLike } from '../entities/gallery-like';
|
|
|
|
import { GalleryPosts } from '../index';
|
2021-04-24 16:38:24 +03:00
|
|
|
|
|
|
|
@EntityRepository(GalleryLike)
|
|
|
|
export class GalleryLikeRepository extends Repository<GalleryLike> {
|
|
|
|
public async pack(
|
|
|
|
src: GalleryLike['id'] | GalleryLike,
|
|
|
|
me?: any
|
|
|
|
) {
|
|
|
|
const like = typeof src === 'object' ? src : await this.findOneOrFail(src);
|
|
|
|
|
|
|
|
return {
|
|
|
|
id: like.id,
|
|
|
|
post: await GalleryPosts.pack(like.post || like.postId, me),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public packMany(
|
|
|
|
likes: any[],
|
|
|
|
me: any
|
|
|
|
) {
|
|
|
|
return Promise.all(likes.map(x => this.pack(x, me)));
|
|
|
|
}
|
|
|
|
}
|