misskey/packages/backend/src/core/entities/UserGroupInvitationEntityService.ts

40 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-09-18 03:27:08 +09:00
import { Inject, Injectable } from '@nestjs/common';
import { DI } from '@/di-symbols.js';
import { UserGroupInvitationsRepository } from '@/models/index.js';
import { awaitAll } from '@/misc/prelude/await-all.js';
import type { Packed } from '@/misc/schema.js';
import type { } from '@/models/entities/Blocking.js';
import type { User } from '@/models/entities/User.js';
import type { UserGroupInvitation } from '@/models/entities/UserGroupInvitation.js';
import { UserEntityService } from './UserEntityService.js';
import { UserGroupEntityService } from './UserGroupEntityService.js';
@Injectable()
export class UserGroupInvitationEntityService {
constructor(
@Inject(DI.userGroupInvitationsRepository)
private userGroupInvitationsRepository: UserGroupInvitationsRepository,
private userGroupEntityService: UserGroupEntityService,
) {
}
public async pack(
src: UserGroupInvitation['id'] | UserGroupInvitation,
) {
const invitation = typeof src === 'object' ? src : await this.userGroupInvitationsRepository.findOneByOrFail({ id: src });
return {
id: invitation.id,
group: await this.userGroupEntityService.pack(invitation.userGroup ?? invitation.userGroupId),
};
}
public packMany(
invitations: any[],
) {
return Promise.all(invitations.map(x => this.pack(x)));
}
}