2022-03-26 07:34:00 +01:00
|
|
|
import { db } from '@/db/postgre.js';
|
2022-02-27 03:07:39 +01:00
|
|
|
import { UserGroupInvitation } from '@/models/entities/user-group-invitation.js';
|
|
|
|
import { UserGroups } from '../index.js';
|
2020-02-12 18:17:54 +01:00
|
|
|
|
2022-03-26 07:34:00 +01:00
|
|
|
export const UserGroupInvitationRepository = db.getRepository(UserGroupInvitation).extend({
|
|
|
|
async pack(
|
2020-02-12 18:17:54 +01:00
|
|
|
src: UserGroupInvitation['id'] | UserGroupInvitation,
|
|
|
|
) {
|
2022-03-26 07:34:00 +01:00
|
|
|
const invitation = typeof src === 'object' ? src : await this.findOneByOrFail({ id: src });
|
2020-02-12 18:17:54 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
id: invitation.id,
|
|
|
|
group: await UserGroups.pack(invitation.userGroup || invitation.userGroupId),
|
|
|
|
};
|
2022-03-26 07:34:00 +01:00
|
|
|
},
|
2020-02-12 18:17:54 +01:00
|
|
|
|
2022-03-26 07:34:00 +01:00
|
|
|
packMany(
|
2020-02-12 18:17:54 +01:00
|
|
|
invitations: any[],
|
|
|
|
) {
|
|
|
|
return Promise.all(invitations.map(x => this.pack(x)));
|
2022-03-26 07:34:00 +01:00
|
|
|
},
|
|
|
|
});
|