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.

41 lines
1.3 KiB

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