hippofish/packages/backend/src/models/repositories/user-group-invitation.ts

24 lines
673 B
TypeScript
Raw Normal View History

2023-01-13 05:40:33 +01:00
import { db } from "@/db/postgre.js";
import { UserGroupInvitation } from "@/models/entities/user-group-invitation.js";
import { UserGroups } from "../index.js";
2023-01-13 05:40:33 +01:00
export const UserGroupInvitationRepository = db
.getRepository(UserGroupInvitation)
.extend({
async pack(src: UserGroupInvitation["id"] | UserGroupInvitation) {
const invitation =
typeof src === "object" ? src : await this.findOneByOrFail({ id: src });
2023-01-13 05:40:33 +01:00
return {
id: invitation.id,
group: await UserGroups.pack(
invitation.userGroup || invitation.userGroupId,
),
};
},
2023-01-13 05:40:33 +01:00
packMany(invitations: any[]) {
return Promise.all(invitations.map((x) => this.pack(x)));
},
});