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.

49 lines
2.0 KiB

3 years ago
3 years ago
3 years ago
3 years ago
  1. import { plainToInstance } from 'class-transformer'
  2. import ApiService from '@/services/api.service'
  3. import { ExampleRepository, SearchOption } from '~/domain/models/example/exampleRepository'
  4. import { ExampleItem, ExampleItemList } from '~/domain/models/example/example'
  5. export class APIExampleRepository implements ExampleRepository {
  6. constructor(
  7. private readonly request = ApiService
  8. ) {}
  9. async list(projectId: string, { limit = '10', offset = '0', q = '', isChecked = '' }: SearchOption): Promise<ExampleItemList> {
  10. const url = `/projects/${projectId}/examples?limit=${limit}&offset=${offset}&q=${q}&confirmed=${isChecked}`
  11. const response = await this.request.get(url)
  12. return plainToInstance(ExampleItemList, response.data)
  13. }
  14. async create(projectId: string, item: ExampleItem): Promise<ExampleItem> {
  15. const url = `/projects/${projectId}/examples`
  16. const response = await this.request.post(url, item.toObject())
  17. return plainToInstance(ExampleItem, response.data)
  18. }
  19. async update(projectId: string, item: ExampleItem): Promise<ExampleItem> {
  20. const url = `/projects/${projectId}/examples/${item.id}`
  21. const response = await this.request.patch(url, item.toObject())
  22. return plainToInstance(ExampleItem, response.data)
  23. }
  24. async bulkDelete(projectId: string, ids: number[]): Promise<void> {
  25. const url = `/projects/${projectId}/examples`
  26. await this.request.delete(url, { ids })
  27. }
  28. async deleteAll(projectId: string): Promise<void> {
  29. const url = `/projects/${projectId}/examples`
  30. await this.request.delete(url)
  31. }
  32. async findById(projectId: string, exampleId: number): Promise<ExampleItem> {
  33. const url = `/projects/${projectId}/examples/${exampleId}`
  34. const response = await this.request.get(url)
  35. return plainToInstance(ExampleItem, response.data)
  36. }
  37. async confirm(projectId: string, exampleId: number): Promise<void> {
  38. const url = `/projects/${projectId}/examples/${exampleId}/states`
  39. await this.request.post(url, {})
  40. }
  41. }