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.

73 lines
2.1 KiB

3 years ago
3 years ago
3 years ago
  1. import { ConfigRepository, ConfigTestResponse } from '~/domain/models/autoLabeling/configRepository'
  2. import { ConfigItemList, ConfigItem } from '~/domain/models/autoLabeling/config'
  3. export class ConfigApplicationService {
  4. constructor(
  5. private readonly configRepository: ConfigRepository
  6. ) {}
  7. public list(id: string): Promise<ConfigItemList> {
  8. return this.configRepository.list(id)
  9. }
  10. public save(projectId: string, item: ConfigItem): Promise<ConfigItem> {
  11. return this.configRepository.create(projectId, item)
  12. }
  13. public delete(projectId: string, itemId: number) {
  14. return this.configRepository.delete(projectId, itemId)
  15. }
  16. public testConfig(projectId: string, item: ConfigItem, text: string): Promise<ConfigTestResponse> {
  17. return this.configRepository.testConfig(projectId, item, text)
  18. .then((value) => {
  19. return value
  20. })
  21. .catch((error) => {
  22. const data = error.response.data
  23. if ('non_field_errors' in data) {
  24. throw new Error(data.non_field_errors)
  25. } else if ('template' in data) {
  26. throw new Error('The template need to be filled.')
  27. } else if ('detail' in data) {
  28. throw new Error(data.detail)
  29. } else {
  30. throw new Error(data)
  31. }
  32. })
  33. }
  34. public testParameters(projectId: string, item: ConfigItem, text: string) {
  35. return this.configRepository.testParameters(projectId, item, text)
  36. .then((value) => {
  37. return value
  38. })
  39. .catch((error) => {
  40. const data = error.response.data
  41. throw new Error(data)
  42. })
  43. }
  44. public testTemplate(projectId: string, response: any, item: ConfigItem) {
  45. return this.configRepository.testTemplate(projectId, response, item)
  46. .then((value) => {
  47. return value
  48. })
  49. .catch((error) => {
  50. const data = error.response.data
  51. throw new Error(data)
  52. })
  53. }
  54. public testMapping(projectId: string, item: ConfigItem, response: any) {
  55. return this.configRepository.testMapping(projectId, item, response)
  56. .then((value) => {
  57. return value
  58. })
  59. .catch((error) => {
  60. const data = error.response.data
  61. throw new Error(data)
  62. })
  63. }
  64. }