2022-09-18 03:27:08 +09:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2022-09-21 05:33:11 +09:00
|
|
|
import type { UserGroupInvitationsRepository } from '@/models/index.js';
|
2022-09-18 03:27:08 +09:00
|
|
|
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)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|