evoleasing-account/actions/edoActions.js
2023-10-19 15:48:56 +03:00

300 lines
6.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import axios from 'axios';
import { Cookies } from 'react-cookie';
import Router from 'next/router';
import moment from 'moment';
import { nSQL } from "@nano-sql/core";
import { eachSeries } from 'async';
import * as actionTypes from '../constants/actionTypes';
import * as currentState from '../reducers/initialState';
export const getEDOOperatorList = ({ dispatch, update = false }) =>
{
const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/edo/operators`;
console.log("ACTION", "edo", "getEDOOperatorList()", { url });
return new Promise((resolve, reject) =>
{
axios.post(url, {}, {
withCredentials: true,
})
.then((response) =>
{
console.log("ACTION", "edo", "getEDOOperatorList()", "response", response.data);
/*
dispatch({
type: actionTypes.EDO_OPERATORS_LIST,
data: {
list: [
{
"box_name": "ООО С К \"МОНОЛИТ-РУ\"",
"box_id": "7785f775578d4646aea1d323e703065d@diadoc.ru"
}, {
"box_name": "ООО СК \"МОНОЛИТ-РУ\" (роуминг, ООО «Такском» (Файлер))",
"box_id": "b8fbc5c395f54deabe6b8d84a10921f0@diadoc.ru"
}
]
}
});
*/
dispatch({
type: actionTypes.EDO_OPERATORS_LIST,
data: {
operators: response.data.box_edo,
message: response.data.message,
}
});
resolve();
})
.catch((error) =>
{
console.error("ACTION", "edo", "getEDOOperatorList()", "ERROR");
console.error(error);
dispatch({
type: actionTypes.EDO_OPERATORS_LIST,
data: {
operators: [],
message: "Невозможно получить список операторов ЭДО",
}
});
reject();
});
});
}
export const getEDOInvitesList = ({ dispatch, update = false }) =>
{
const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/edo/invites`;
console.log("ACTION", "edo", "getEDOInvitesList()", { url });
return new Promise((resolve, reject) =>
{
axios.post(url, {}, {
withCredentials: true,
})
.then((response) =>
{
console.log("ACTION", "edo", "getEDOInvitesList()", "response", response.data);
dispatch({
type: actionTypes.EDO_INVITES_LIST,
data: {
invites: response.data.box_edo
}
});
resolve();
})
.catch((error) =>
{
console.error("ACTION", "edo", "getEDOInvitesList()", "ERROR");
console.error(error);
dispatch({
type: actionTypes.EDO_INVITES_LIST,
data: {
invites: []
}
});
reject();
});
});
}
export const inviteToEDO = () =>
{
const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/edo/invite/send`;
console.log("ACTION", "edo", "inviteToEDO()", { url });
return new Promise((resolve, reject) =>
{
axios.post(url, {}, {
withCredentials: true,
})
.then((response) =>
{
console.log("ACTION", "edo", "inviteToEDO()", "response", response.data);
resolve(response.data);
})
.catch((error) =>
{
console.error("ACTION", "edo", "inviteToEDO()", "ERROR");
console.error(error);
reject(error.data);
});
});
}
export const createEDOProject = (payload) =>
{
const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/edo/project`;
console.log("ACTION", "edo", "createEDOProject()", { url });
return new Promise((resolve, reject) =>
{
axios.post(url, payload, {
withCredentials: true,
})
.then((response) =>
{
console.log("ACTION", "edo", "createEDOProject()", "response", response.data);
resolve(response.data);
})
.catch((error) =>
{
console.error("ACTION", "edo", "createEDOProject()", "ERROR");
console.error(error);
reject(error.data);
});
});
}
export const docEDOSign = (payload) =>
{
const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/edo/sign`;
if(parseInt(process.env.LOG, 10) === 1)
{
console.log("ACTION", "edo", "docEDOSign()", { url });
}
return new Promise((resolve, reject) =>
{
axios.post(url, payload, {
withCredentials: true,
})
.then((response) =>
{
if(parseInt(process.env.LOG, 10) === 1)
{
console.log("ACTION", "edo", "docEDOSign()", "response", response.data);
}
resolve(response.data);
})
.catch((error) =>
{
if(parseInt(process.env.LOG, 10) === 1)
{
console.error("ACTION", "edo", "docEDOSign()", "ERROR");
console.error(error);
}
reject(error.data);
});
});
}
export const docEDOCancel = ({ contract_number, doc_type_id, }) =>
{
const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/edo/cancel`;
console.log("ACTION", "edo", "docEDOCancel()", { url });
return new Promise((resolve, reject) =>
{
axios.post(url, { contract_number, doc_type_id, }, {
withCredentials: true,
})
.then((response) =>
{
console.log("ACTION", "edo", "docEDOCancel()", "response", response.data);
resolve(response.data);
})
.catch((error) =>
{
console.error("ACTION", "edo", "docEDOCancel()", "ERROR");
console.error(error);
reject(error.data);
});
});
}
export const docEDOConnect = (payload) =>
{
const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/contract/sign/document/connect`;
if(parseInt(process.env.LOG, 10) === 1)
{
console.log("ACTION", "edo", "docEDOConnect()", { url });
}
return new Promise((resolve, reject) =>
{
axios.post(url, payload, {
withCredentials: true,
})
.then((response) =>
{
if(parseInt(process.env.LOG, 10) === 1)
{
console.log("ACTION", "edo", "docEDOConnect()", "response", response.data);
}
resolve(response.data);
})
.catch((error) =>
{
if(parseInt(process.env.LOG, 10) === 1)
{
console.error("ACTION", "edo", "docEDOConnect()", "ERROR");
console.error(error);
}
reject(error.data);
});
});
}
export const docEDOStatus = (payload) =>
{
const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/contract/sign/document/status`;
if(parseInt(process.env.LOG, 10) === 1)
{
console.log("ACTION", "edo", "docEDOStatus()", { url });
}
return new Promise((resolve, reject) =>
{
axios.post(url, payload, {
withCredentials: true,
})
.then((response) =>
{
if(parseInt(process.env.LOG, 10) === 1)
{
console.log("ACTION", "edo", "docEDOStatus()", "response", response.data);
}
resolve(response.data);
})
.catch((error) =>
{
if(parseInt(process.env.LOG, 10) === 1)
{
console.error("ACTION", "edo", "docEDOStatus()", "ERROR");
console.error(error);
}
reject(error.data);
});
});
}