mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-14 21:43:09 +02:00
26 lines
613 B
TypeScript
26 lines
613 B
TypeScript
|
import { EntityRepository, Repository } from 'typeorm';
|
||
|
import { GalleryLike } from '../entities/gallery-like';
|
||
|
import { GalleryPosts } from '..';
|
||
|
|
||
|
@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)));
|
||
|
}
|
||
|
}
|