monkeeShark/src/models/repositories/user-group-invite.ts

25 lines
686 B
TypeScript
Raw Normal View History

2019-05-19 11:41:23 +00:00
import { EntityRepository, Repository } from 'typeorm';
import { UserGroupInvite } from '../entities/user-group-invite';
import { UserGroups } from '..';
import { ensure } from '../../prelude/ensure';
@EntityRepository(UserGroupInvite)
export class UserGroupInviteRepository extends Repository<UserGroupInvite> {
public async pack(
src: UserGroupInvite['id'] | UserGroupInvite,
) {
const invite = typeof src === 'object' ? src : await this.findOne(src).then(ensure);
return {
id: invite.id,
group: await UserGroups.pack(invite.userGroup || invite.userGroupId),
};
}
public packMany(
invites: any[],
) {
return Promise.all(invites.map(x => this.pack(x)));
}
}