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.4 KiB

  1. import { plainToInstance } from 'class-transformer'
  2. import ApiService from '@/services/api.service'
  3. import { ProjectRepository, SearchOption } from '@/domain/models/project/projectRepository'
  4. import { ProjectReadItem, ProjectWriteItem, ProjectItemList } from '~/domain/models/project/project'
  5. export class APIProjectRepository implements ProjectRepository {
  6. constructor(
  7. private readonly request = ApiService
  8. ) {}
  9. async list({ limit = '10', offset = '0', q = '' }: SearchOption): Promise<ProjectItemList> {
  10. const url = `/projects?limit=${limit}&offset=${offset}&q=${q}`
  11. const response = await this.request.get(url)
  12. return plainToInstance(ProjectItemList, response.data)
  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. }