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.

39 lines
1.3 KiB

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