You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.4 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. import { plainToInstance } from 'class-transformer'
  2. import { MemberDTO } from './memberData'
  3. import { MemberRepository } from '~/domain/models/member/memberRepository'
  4. import { MemberItem } from '~/domain/models/member/member'
  5. export class MemberApplicationService {
  6. constructor(private readonly repository: MemberRepository) {}
  7. public async list(id: string): Promise<MemberDTO[]> {
  8. try {
  9. const items = await this.repository.list(id)
  10. return items.map((item) => new MemberDTO(item))
  11. } catch (e: any) {
  12. throw new Error(e.response.data.detail)
  13. }
  14. }
  15. public async create(projectId: string, item: MemberDTO): Promise<void> {
  16. try {
  17. const member = plainToInstance(MemberItem, item)
  18. await this.repository.create(projectId, member)
  19. } catch (e: any) {
  20. throw new Error(e.response.data.detail)
  21. }
  22. }
  23. public async update(projectId: string, item: MemberDTO): Promise<void> {
  24. try {
  25. const member = plainToInstance(MemberItem, item)
  26. await this.repository.update(projectId, member)
  27. } catch (e: any) {
  28. throw new Error(e.response.data.detail)
  29. }
  30. }
  31. public bulkDelete(projectId: string, items: MemberDTO[]): Promise<void> {
  32. const ids = items.map((item) => item.id)
  33. return this.repository.bulkDelete(projectId, ids)
  34. }
  35. public async isProjectAdmin(projectId: string): Promise<boolean> {
  36. const item = await this.repository.fetchMyRole(projectId)
  37. return item.isProjectAdmin
  38. }
  39. }