Before
unknown
typescript
4 years ago
6.9 kB
8
Indexable
import axios from 'axios' import { Storage } from '@capacitor/storage' const storageKey = 'auth' const apiUrl = process.env.VUE_APP_API_URL; /* eslint-disable @typescript-eslint/camelcase */ const tasks = { getAllTasksList (datefrom: any, dateto: any, category: number, statuses: any) { return new Promise((resolve, reject) => { Storage.get({ key: storageKey }).then((data) => { const auth = data.value !== null ? JSON.parse(data.value) : null if (auth && auth.token) { axios.get(apiUrl + '/api/support-app/tasks?token=' + auth.token + '&statusId=' + statuses + '&categoryId=' + category + '&dateFrom=' + datefrom + '&dateTo=' + dateto, { }) .then(({ data }) => { resolve(data.items) }) .catch(() => { reject(false) }) } else { reject(false) } }) }) }, getTask (taskId: any) { return new Promise((resolve, reject) => { Storage.get({ key: storageKey }).then((data) => { const auth = data.value !== null ? JSON.parse(data.value) : null if (auth && auth.token) { axios.get(apiUrl + '/api/support-app/tasks/' + taskId + '?token=' + auth.token, { // token: auth.token, }) .then(({ data }) => { resolve(data) }) .catch(() => { reject(false) }) } else { reject(false) } }) }) }, sendAcceptWorksSms (body: any) { return new Promise((resolve, reject) => { Storage.get({ key: storageKey }).then((data) => { const auth = data.value !== null ? JSON.parse(data.value) : null if (auth && auth.token) { axios.post(apiUrl + '/api/support-app/client-accept-works/send/?token=' + auth.token, body) .then(({ data }) => { resolve(data.success) }) .catch(() => { reject(false) }) } else { reject(false) } }) }) }, checkAcceptWorksSms (body: any) { return new Promise((resolve, reject) => { Storage.get({ key: storageKey }).then((data) => { const auth = data.value !== null ? JSON.parse(data.value) : null if (auth && auth.token) { axios.post(apiUrl + '/api/support-app/client-accept-works/check/?token=' + auth.token, body) .then(({ data }) => { resolve(data.success) }) .catch(() => { reject(false) }) } else { reject(false) } }) }) }, getReasons () { return new Promise((resolve, reject) => { Storage.get({ key: storageKey }).then((data) => { const auth = data.value !== null ? JSON.parse(data.value) : null if (auth && auth.token) { axios.get(apiUrl + '/api/support-app/dict/problems?token=' + auth.token, { // token: auth.token, }) .then(({ data }) => { resolve(data.item) }) .catch(() => { reject(false) }) } else { reject(false) } }) }) }, getCategories () { return new Promise((resolve, reject) => { Storage.get({ key: storageKey }).then((data) => { const auth = data.value !== null ? JSON.parse(data.value) : null if (auth && auth.token) { axios.get(apiUrl + '/api/support-app/dict/categories?token=' + auth.token, { // token: auth.token, }) .then(({ data }) => { resolve(data.items) }) .catch(() => { reject(false) }) } else { reject(false) } }) }) }, tvcomSubscription (taskId: any) { return new Promise((resolve, reject) => { Storage.get({ key: storageKey }).then((data) => { const auth = data.value !== null ? JSON.parse(data.value) : null if (auth && auth.token) { axios.post( `${apiUrl}/api/support-app/tasks/${taskId}/tvcom-subscription?token=${auth.token}`) .then(() => resolve(true)) .catch(() => reject(false)) } else { reject(false) } }) }) }, getStatuses () { return new Promise((resolve, reject) => { Storage.get({ key: storageKey }).then((data) => { const auth = data.value !== null ? JSON.parse(data.value) : null if (auth && auth.token) { axios.get(apiUrl + '/api/support-app/dict/statuses?token=' + auth.token) .then(({ data }) => { resolve(data.items) }) .catch(() => { reject(false) }) } else { reject(false) } }) }) }, setStatusTask (taskId: any, taskStatus: any) { return new Promise((resolve, reject) => { Storage.get({ key: storageKey }).then((data) => { const auth = data.value !== null ? JSON.parse(data.value) : null if (auth && auth.token) { axios.post(apiUrl + '/api/support-app/tasks/' + taskId + '?token=' + auth.token, // formData { statusId: taskStatus } ) .then(({ data }) => { resolve(data) }) .catch(() => { reject(false) }) } else { reject(false) } }) }) }, setProblemStatusTask (taskId: any, taskStatus: any, comment: any, photos: any) { return new Promise((resolve, reject) => { Storage.get({ key: storageKey }).then((data) => { const auth = data.value !== null ? JSON.parse(data.value) : null if (auth && auth.token) { axios.post(apiUrl + '/api/support-app/tasks/' + taskId + '?token=' + auth.token, { statusId: taskStatus, comment: comment, image: photos } ) .then(({ data }) => { resolve(data) }) .catch(() => { reject(false) }) } else { reject(false) } }) }) }, sendCoordinates (coordinates: any) { return new Promise((resolve, reject) => { Storage.get({ key: storageKey }).then((data) => { const auth = data.value !== null ? JSON.parse(data.value) : null coordinates['uid'] = auth.uid; if (auth && auth.token) { axios.post(apiUrl + '/api/support-app/gps-trace?token=' + auth.token, coordinates) .then(({ data }) => { resolve(data) }) .catch(() => { reject(false) }) } else { reject(false) } }) }) } } export default tasks
Editor is loading...