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.

60 lines
1.8 KiB

  1. import ApiService from '@/services/api.service'
  2. class DocumentService {
  3. constructor() {
  4. this.request = ApiService
  5. }
  6. getDocumentList({ projectId, limit = 10, offset = 0, q = '', isChecked = '', filterName = '' }) {
  7. return this.request.get(`/projects/${projectId}/docs?limit=${limit}&offset=${offset}&q=${q}&${filterName}=${isChecked}`)
  8. }
  9. addDocument(projectId, payload) {
  10. return this.request.post(`/projects/${projectId}/docs`, payload)
  11. }
  12. deleteAllDocuments(projectId) {
  13. return this.request.delete(`/projects/${projectId}/docs`)
  14. }
  15. deleteDocument(projectId, docId) {
  16. return this.request.delete(`/projects/${projectId}/docs/${docId}`)
  17. }
  18. updateDocument(projectId, docId, payload) {
  19. return this.request.patch(`/projects/${projectId}/docs/${docId}`, payload)
  20. }
  21. uploadFile(projectId, payload, config = {}) {
  22. return this.request.post(`/projects/${projectId}/docs/upload`, payload, config)
  23. }
  24. exportFile(projectId, format, onlyApproved) {
  25. const headers = {}
  26. if (format === 'csv') {
  27. headers.Accept = 'text/csv; charset=utf-8'
  28. headers['Content-Type'] = 'text/csv; charset=utf-8'
  29. } else if (format === 'txt') {
  30. headers.Accept = 'text/plain; charset=utf-8'
  31. headers['Content-Type'] = 'text/plain; charset=utf-8'
  32. } else {
  33. headers.Accept = 'application/json'
  34. headers['Content-Type'] = 'application/json'
  35. }
  36. const config = {
  37. responseType: 'blob',
  38. params: {
  39. q: format,
  40. onlyApproved
  41. },
  42. headers
  43. }
  44. return this.request.get(`/projects/${projectId}/docs/download`, config)
  45. }
  46. approveDocument(projectId, docId, payload) {
  47. return this.request.post(`/projects/${projectId}/docs/${docId}/approve-labels`, payload)
  48. }
  49. }
  50. export default new DocumentService()