2022-03-26 06:34:00 +00:00
|
|
|
import { db } from '@/db/postgre.js';
|
2022-02-27 02:07:39 +00:00
|
|
|
import { PageLike } from '@/models/entities/page-like.js';
|
|
|
|
import { Pages } from '../index.js';
|
|
|
|
import { User } from '@/models/entities/user.js';
|
2019-05-17 10:56:47 +00:00
|
|
|
|
2022-03-26 06:34:00 +00:00
|
|
|
export const PageLikeRepository = db.getRepository(PageLike).extend({
|
|
|
|
async pack(
|
2019-05-17 10:56:47 +00:00
|
|
|
src: PageLike['id'] | PageLike,
|
2021-03-24 02:05:37 +00:00
|
|
|
me?: { id: User['id'] } | null | undefined
|
2019-05-17 10:56:47 +00:00
|
|
|
) {
|
2022-03-26 06:34:00 +00:00
|
|
|
const like = typeof src === 'object' ? src : await this.findOneByOrFail({ id: src });
|
2019-05-17 10:56:47 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
id: like.id,
|
|
|
|
page: await Pages.pack(like.page || like.pageId, me),
|
|
|
|
};
|
2022-03-26 06:34:00 +00:00
|
|
|
},
|
2019-05-17 10:56:47 +00:00
|
|
|
|
2022-03-26 06:34:00 +00:00
|
|
|
packMany(
|
2019-05-17 10:56:47 +00:00
|
|
|
likes: any[],
|
2021-03-24 02:05:37 +00:00
|
|
|
me: { id: User['id'] }
|
2019-05-17 10:56:47 +00:00
|
|
|
) {
|
|
|
|
return Promise.all(likes.map(x => this.pack(x, me)));
|
2022-03-26 06:34:00 +00:00
|
|
|
},
|
|
|
|
});
|