d071d18dd7
* wip * wip * fix * clean up * Update tsconfig.json * Update activitypub.ts * wip
25 lines
747 B
TypeScript
25 lines
747 B
TypeScript
import { EntityRepository, Repository } from 'typeorm';
|
|
import { UserGroup } from '@/models/entities/user-group.js';
|
|
import { UserGroupJoinings } from '../index.js';
|
|
import { Packed } from '@/misc/schema.js';
|
|
|
|
@EntityRepository(UserGroup)
|
|
export class UserGroupRepository extends Repository<UserGroup> {
|
|
public async pack(
|
|
src: UserGroup['id'] | UserGroup,
|
|
): Promise<Packed<'UserGroup'>> {
|
|
const userGroup = typeof src === 'object' ? src : await this.findOneOrFail(src);
|
|
|
|
const users = await UserGroupJoinings.find({
|
|
userGroupId: userGroup.id,
|
|
});
|
|
|
|
return {
|
|
id: userGroup.id,
|
|
createdAt: userGroup.createdAt.toISOString(),
|
|
name: userGroup.name,
|
|
ownerId: userGroup.userId,
|
|
userIds: users.map(x => x.userId),
|
|
};
|
|
}
|
|
}
|