2022-03-26 07:34:00 +01:00
|
|
|
import { db } from '@/db/postgre.js';
|
2022-02-27 03:07:39 +01:00
|
|
|
import { GalleryLike } from '@/models/entities/gallery-like.js';
|
|
|
|
import { GalleryPosts } from '../index.js';
|
2021-04-24 15:38:24 +02:00
|
|
|
|
2022-03-26 07:34:00 +01:00
|
|
|
export const GalleryLikeRepository = db.getRepository(GalleryLike).extend({
|
|
|
|
async pack(
|
2021-04-24 15:38:24 +02:00
|
|
|
src: GalleryLike['id'] | GalleryLike,
|
|
|
|
me?: any
|
|
|
|
) {
|
2022-03-26 07:34:00 +01:00
|
|
|
const like = typeof src === 'object' ? src : await this.findOneByOrFail({ id: src });
|
2021-04-24 15:38:24 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
id: like.id,
|
|
|
|
post: await GalleryPosts.pack(like.post || like.postId, me),
|
|
|
|
};
|
2022-03-26 07:34:00 +01:00
|
|
|
},
|
2021-04-24 15:38:24 +02:00
|
|
|
|
2022-03-26 07:34:00 +01:00
|
|
|
packMany(
|
2021-04-24 15:38:24 +02:00
|
|
|
likes: any[],
|
|
|
|
me: any
|
|
|
|
) {
|
|
|
|
return Promise.all(likes.map(x => this.pack(x, me)));
|
2022-03-26 07:34:00 +01:00
|
|
|
},
|
|
|
|
});
|