2022-09-17 20:27:08 +02:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2022-09-20 22:33:11 +02:00
|
|
|
import type { UserGroupInvitationsRepository } from '@/models/index.js';
|
2022-09-17 20:27:08 +02: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';
|
2022-12-04 07:03:09 +01:00
|
|
|
import { bindThis } from '@/decorators.js';
|
2022-09-17 20:27:08 +02:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class UserGroupInvitationEntityService {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.userGroupInvitationsRepository)
|
|
|
|
private userGroupInvitationsRepository: UserGroupInvitationsRepository,
|
|
|
|
|
|
|
|
private userGroupEntityService: UserGroupEntityService,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2022-12-04 07:03:09 +01:00
|
|
|
@bindThis
|
2022-09-17 20:27:08 +02:00
|
|
|
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),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-04 07:03:09 +01:00
|
|
|
@bindThis
|
2022-09-17 20:27:08 +02:00
|
|
|
public packMany(
|
|
|
|
invitations: any[],
|
|
|
|
) {
|
|
|
|
return Promise.all(invitations.map(x => this.pack(x)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|