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