egirlskey/src/models/repositories/page-like.ts
syuilo ce340aba7a
Refactor (#7394)
* wip

* wip

* wip

* wip

* wip

* Update define.ts

* Update update.ts

* Update user.ts

* wip

* wip

* Update request.ts

* URL

* wip

* wip

* wip

* wip

* Update invite.ts

* Update create.ts
2021-03-24 11:05:37 +09:00

26 lines
668 B
TypeScript

import { EntityRepository, Repository } from 'typeorm';
import { PageLike } from '../entities/page-like';
import { Pages } from '..';
import { User } from '../entities/user';
@EntityRepository(PageLike)
export class PageLikeRepository extends Repository<PageLike> {
public async pack(
src: PageLike['id'] | PageLike,
me?: { id: User['id'] } | null | undefined
) {
const like = typeof src === 'object' ? src : await this.findOneOrFail(src);
return {
id: like.id,
page: await Pages.pack(like.page || like.pageId, me),
};
}
public packMany(
likes: any[],
me: { id: User['id'] }
) {
return Promise.all(likes.map(x => this.pack(x, me)));
}
}