2019-05-18 20:36:33 +09:00
|
|
|
import { EntityRepository, Repository } from 'typeorm';
|
2021-08-19 22:04:15 +09:00
|
|
|
import { UserGroup } from '@/models/entities/user-group';
|
2021-08-19 21:55:45 +09:00
|
|
|
import { UserGroupJoinings } from '../index';
|
2021-09-22 22:35:55 +09:00
|
|
|
import { Packed } from '@/misc/schema';
|
2019-05-18 20:36:33 +09:00
|
|
|
|
|
|
|
@EntityRepository(UserGroup)
|
|
|
|
export class UserGroupRepository extends Repository<UserGroup> {
|
|
|
|
public async pack(
|
|
|
|
src: UserGroup['id'] | UserGroup,
|
2021-09-22 22:35:55 +09:00
|
|
|
): Promise<Packed<'UserGroup'>> {
|
2021-02-13 15:33:38 +09:00
|
|
|
const userGroup = typeof src === 'object' ? src : await this.findOneOrFail(src);
|
2019-05-18 20:36:33 +09:00
|
|
|
|
|
|
|
const users = await UserGroupJoinings.find({
|
2021-12-09 23:58:30 +09:00
|
|
|
userGroupId: userGroup.id,
|
2019-05-18 20:36:33 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
id: userGroup.id,
|
|
|
|
createdAt: userGroup.createdAt.toISOString(),
|
|
|
|
name: userGroup.name,
|
2019-05-22 12:58:44 +09:00
|
|
|
ownerId: userGroup.userId,
|
2021-12-09 23:58:30 +09:00
|
|
|
userIds: users.map(x => x.userId),
|
2019-05-18 20:36:33 +09:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|