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.

33 lines
1.3 KiB

  1. import { plainToInstance } from 'class-transformer'
  2. import ApiService from '@/services/api.service'
  3. import { MemberRepository } from '@/domain/models/member/memberRepository'
  4. import { MemberItem } from '~/domain/models/member/member'
  5. export class APIMemberRepository implements MemberRepository {
  6. constructor(
  7. private readonly request = ApiService
  8. ) {}
  9. async list(projectId: string): Promise<MemberItem[]> {
  10. const url = `/projects/${projectId}/members`
  11. const response = await this.request.get(url)
  12. return response.data.map((item: any) => plainToInstance(MemberItem, item))
  13. }
  14. async create(projectId: string, item: MemberItem): Promise<MemberItem> {
  15. const url = `/projects/${projectId}/members`
  16. const response = await this.request.post(url, item.toObject())
  17. return plainToInstance(MemberItem, response.data)
  18. }
  19. async update(projectId: string, item: MemberItem): Promise<MemberItem> {
  20. const url = `/projects/${projectId}/members/${item.id}`
  21. const response = await this.request.patch(url, item.toObject())
  22. return plainToInstance(MemberItem, response.data)
  23. }
  24. async bulkDelete(projectId: string, memberIds: number[]): Promise<void> {
  25. const url = `/projects/${projectId}/members`
  26. await this.request.delete(url, { ids: memberIds })
  27. }
  28. }