After
unknown
typescript
4 years ago
4.3 kB
5
Indexable
import axios from 'axios' import { GPSCoordinates } from '@/types' import { apiUrl, authStorage } from '@/store/config' const TASK_STATUS_PROBLEM = 7 const tasks = { namespaced: true, state () { return {} }, actions: { /** * Get list of Tasks for given Statuses * @param statuses */ async getTasksList (statuses: number[]): Promise { const auth = await authStorage() return axios.get(`${apiUrl}/api/support-app/tasks?token=${auth.token}&statusId=${statuses}`) .then(({ data }) => resolve(data.items)) .catch(() => reject()) }, /** * Get detailed information about the Task * @param taskId */ async getTaskDetails (taskId: any): Promise { const auth = await authStorage() return axios.get(`${apiURL}/api/support-app/tasks/${taskId}?token=${auth.token}`) .then(({ data }) => resolve(data)) .catch(() => reject()) }, /** * Updates Task's status for given one * @param taskId * @param statusId */ async markTaskAs (taskId: number, statusId: number): Promise { const auth = await authStorage() const data = { statusId } return axios.post(`${apiUrl}/api/support-app/tasks/${taskId}?token=${auth.token}`, data) .then(({ data }) => resolve(data)) .catch(() => reject()) }, /** * Updates Task's status for Problem * @param taskId * @param photos * @param comment */ async markTaskAsProblem (taskId: number, photos: object, comment?: string): Promise { const auth = await authStorage() const data = { statusId: TASK_STATUS_PROBLEM, comment: comment, image: photos, } return axios.post(`${apiUrl}/api/support-app/tasks/${taskId}?token=${auth.token}`, data) .then(({ data }) => resolve(data)) .catch(() => reject()) }, /** * Get list of Statuses dictionary */ async getStatuses (): Promise { const auth = await authStorage() return axios.get(`${apiUrl}/api/support-app/dict/statuses?token=${auth.token}`) .then(({ data }) => resolve(data.items)) .catch(() => reject()) }, /** * Get list of Categories dictionary */ async getCategories (): Promise { const auth = await authStorage() return axios.get(`${apiUrl}/api/support-app/dict/categories?token=${auth.token}`) .then(({ data }) => resolve(data.items)) .catch(() => reject()) }, /** * Get list of Problem Reasons dictionary */ async getProblemReasons (): Promise { const auth = await authStorage() return axios.get(`${apiUrl}/api/support-app/dict/categories?token=${auth.token}`) .then(({ data }) => resolve(data.item)) .catch(() => reject()) }, /** * Send SMS for Accept Works * @param body */ async acceptWorksSMSend (body: any): Promise { const auth = await authStorage() return axios.post(`${apiUrl}/api/support-app/client-accept-works/send/?token=${auth.token}`, body) .then(({ data }) => resolve(data.success)) .catch(() => reject()) }, /** * Check SMS for Accept Works * @param body */ async acceptWorksSMSCheck (body: any): Promise { const auth = await authStorage() return axios.post(`${apiUrl}/api/support-app/client-accept-works/check/?token=${auth.token}`, body) .then(({ data }) => resolve(data.success)) .catch(() => reject()) }, /** * Subscribes TVcom for the Client * @param taskId */ async subscribeTvCom (taskId: any): Promise { const auth = await authStorage() return axios.post(`${apiUrl}/api/support-app/tasks/${taskId}/tvcom-subscription?token=${auth.token}`) .then(() => resolve(true)) .catch(() => reject(false)) }, /** * Send GPS coordinates to the server * @param coordinates */ async sendCoordinates (coordinates: GPSCoordinates): Promise { const auth = await authStorage() const data = { ...coordinates, uid: auth.uid } return axios.post(`${apiUrl}/api/support-app/gps-trace?token=${auth.token}`, data) } } } export default tasks
Editor is loading...