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