diff --git a/actions/dealsActions.js b/actions/dealsActions.js index a1c3731..83272c7 100644 --- a/actions/dealsActions.js +++ b/actions/dealsActions.js @@ -8,6 +8,22 @@ import { eachSeries } from 'async'; import * as actionTypes from '../constants/actionTypes'; import * as currentState from '../reducers/initialState'; +if(process.browser) +{ + FormData.prototype.appendObject = function(obj, namespace) + { + let keyName; + for (var key in obj) + { + if (obj.hasOwnProperty(key)) + { + keyName = [namespace, '[', key, ']'].join(''); + this.append(keyName, obj[key]); + } + } + }; +} + export const getDeals = ({ dispatch, update = false }) => { const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/deals`; @@ -217,6 +233,41 @@ export const getDealContracts = ({ dispatch, deal_id }) => } }); + reject(); + }); + }); +} + +export const uploadDocument = ({ number, entity, id, filename, file }) => +{ + return new Promise((resolve, reject) => + { + let data = new FormData(); + data.append('file', file); + + const payload = new URLSearchParams({ + number, + entity, + id, + filename, + }); + + axios.post(`${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/deals/upload?${ payload.toString() }`, data, + { + headers: { + "Content-Type": "multipart/form-data", + }, + withCredentials: true, + }) + .then(async (response) => + { + console.log("ACTION", "deals", "uploadDocument", "response.data", response.data); + + resolve(); + }) + .catch((error) => + { + console.error(error); reject(); }); }); diff --git a/actions/logsActions.js b/actions/logsActions.js index 4e57f6d..896cd2d 100644 --- a/actions/logsActions.js +++ b/actions/logsActions.js @@ -17,7 +17,7 @@ export const logDocumentAccess = (payload) => return new Promise((resolve, reject) => { - payload.lk_user_id = global.store.getState().user; + payload.lk_user_id = global.store.getState().user.email; payload.acc_number = global.store.getState().company.active; axios.post(url, payload, { diff --git a/components/DealsStatus/SingleDeal.js b/components/DealsStatus/SingleDeal.js index 17cc191..5cd268f 100644 --- a/components/DealsStatus/SingleDeal.js +++ b/components/DealsStatus/SingleDeal.js @@ -1,10 +1,11 @@ import React from "react" import numeral from "numeral"; import moment from "moment"; +import { eachLimit } from "async"; import { SpinnerCircular } from "spinners-react"; import FileDropzoneDeals from "../FileDropzoneDeals"; -import { acceptDealOffers } from "../../actions"; +import { acceptDealOffers, uploadDocument } from "../../actions"; class Step extends React.Component { @@ -31,7 +32,6 @@ class Step extends React.Component } } - _handle_onSwitch = () => { const { statuscode_id } = this.props; @@ -264,24 +264,68 @@ class DocumentsForm extends Step this.state = { open: false, files: {}, + uploading: false, + completed: false, }; this.status = [ 102 ]; } - _renderHeaderButtons = () => + _handle_onSendFiles = (event) => { - const { open, files } = this.state; + event.stopPropagation(); +// event.preventDefault(); - if(open && Object.keys(files).length > 0) + const { files } = this.state; + const files_array = []; + + for(let g in files) { - return ( -
- -
- ) + for(let f in files[g]) + { + files_array.push(files[g][f]) + } } - return null; + this.setState({ uploading: true }, () => + { + eachLimit(files_array, 1, (file, callback) => + { + console.log({ file, props: this.props }); + const { opp_number } = this.props; + + const payload = { + number: opp_number, + entity: "opportunity", + id: file.group, + filename: file.name, + file, + }; + + uploadDocument(payload) + .then(() => + { + this._onSendFileStats(file.group, file.index); + + callback(); + }, 1000) + }, () => + { + console.log("ready"); + this.setState({ uploading: false }, () => + { + this._checkFilesCompleted(); + }); + }); + }); + } + + _onSendFileStats = (group, index) => + { + const files = { ...this.state.files }; + + files[group][index].sent = true; + + this.setState({ files }); } _handle_onAddFile = (file_id, files) => @@ -299,12 +343,18 @@ class DocumentsForm extends Step if(!e) { + files[nf].index = nf; + files[nf].group = file_id; + files[nf].sent = false; document_files.push(files[nf]); } existed_files[ file_id ] = document_files; - this.setState({ files: existed_files }); + this.setState({ files: existed_files }, () => + { + this._checkFilesCompleted(); + }); } } @@ -330,15 +380,84 @@ class DocumentsForm extends Step delete files[file_id]; } - this.setState({ files }); + this.setState({ files }, () => + { + this._checkFilesCompleted(); + }); + } + + _checkFilesCompleted = () => + { + //Object.keys(files).length > 0 + const { files } = this.state; + const { documents } = this.props; + + let c = true; + for(let g in documents) + { + const group = documents[g].doc_id; + + if(files[group] === undefined || files[group].length === 0) + { + c = false; + break; + } + else + { + for(let f in files[group]) + { + if(!files[group][f].sent) + { + c = false; + break; + } + } + } + } + + /* + if(c) + { + for(let g in files) + { + for(let f in files[g]) + { + if(!files[g][f].sent) + { + c = false; + break; + } + } + } + } + */ + + console.log({ c }) + this.setState({ completed: c }); + } + + _renderHeaderButtons = () => + { + const { open, uploading, completed, } = this.state; + + if(open && !uploading && !completed) + { + return ( +
+ +
+ ) + } + + return null; } render() { const { index, statuscode_id, dealSelected, documents, questionnaire_status } = this.props; - const { open, files } = this.state; + const { open, files, uploading } = this.state; - console.log("DocumentsForm", { documents }); +// console.log("DocumentsForm", { documents }); return (
-1 ? "current" : statuscode_id > this.status[ 0 ] ? "done" : "" }`}> @@ -383,6 +502,7 @@ class DocumentsForm extends Step
{ this._handle_onAddFile(document.doc_id, file) } } onDeleteFile={ (file) => this._handle_onDeleteFile(document.doc_id, file) } @@ -391,7 +511,7 @@ class DocumentsForm extends Step
)) } - )} + ) } {/*}
diff --git a/components/FileDropzoneDeals/index.js b/components/FileDropzoneDeals/index.js index c24e757..dd3e1da 100644 --- a/components/FileDropzoneDeals/index.js +++ b/components/FileDropzoneDeals/index.js @@ -1,6 +1,7 @@ import Dropzone from 'react-dropzone'; import FileDropzone from "../FileDropzone"; import moment from "moment"; +import { SpinnerCircular } from 'spinners-react'; const LIMIT = 10000000; const LIMIT_FILES = 10; @@ -9,7 +10,7 @@ export default class FileDropzoneDeals extends FileDropzone { render() { - const { files, onAddFile, onDeleteFile, } = this.props; + const { files, onAddFile, onDeleteFile, uploading, } = this.props; return ( <> @@ -17,9 +18,23 @@ export default class FileDropzoneDeals extends FileDropzone
{ files.map((file, index) => (
-
onDeleteFile(file) }> -
-
+ { file.sent ? ( +
+
+
+ ) : ( + <> + { uploading ? ( +
+ +
+ ) : ( +
onDeleteFile(file) }> +
+
+ ) } + + ) }
PDF
@@ -34,7 +49,7 @@ export default class FileDropzoneDeals extends FileDropzone {*/}
) } - { files.length < LIMIT_FILES && ( + { !uploading && files.length < LIMIT_FILES && ( onAddFile(acceptedFiles) } maxFiles={ LIMIT_FILES }> { ({getRootProps, getInputProps}) => (
diff --git a/css/main/style.css b/css/main/style.css index 3a18e1c..d0e44d6 100644 --- a/css/main/style.css +++ b/css/main/style.css @@ -6102,12 +6102,29 @@ main .dropdown_blocks_list.zero-margin.gibdd .dropdown_block .block_body .fines_ padding-right: 16px; padding-top: 10px; cursor: pointer; + width: 30px; + min-width: 30px; + padding-left: 3px; } .horizontal_dropzone_files .file .delete .icon { width: 16px; height: 16px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M8 14C11.3137 14 14 11.3137 14 8C14 4.68629 11.3137 2 8 2C4.68629 2 2 4.68629 2 8C2 11.3137 4.68629 14 8 14Z' fill='%23ED0A34' stroke='%23ED0A34' stroke-miterlimit='10'/%3E%3Cpath d='M10 6L6 10' stroke='white' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M10 10L6 6' stroke='white' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); } +.horizontal_dropzone_files .file .loading { + width: 30px; + min-width: 30px; +} +.horizontal_dropzone_files .file .loading .success { + width: 24px; + min-width: 24px; + height: 30px; + min-height: 30px; + background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12 21C16.9706 21 21 16.9706 21 12C21 7.02944 16.9706 3 12 3C7.02944 3 3 7.02944 3 12C3 16.9706 7.02944 21 12 21Z' stroke='%235FB158' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M16.125 9.75L10.625 15L7.875 12.375' stroke='%235FB158' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E%0A"); + background-repeat: no-repeat; + background-position: center; + background-position-y: 6px; +} .horizontal_dropzone_files .file .doc_icon { display: flex; align-items: center; diff --git a/css/main/style.less b/css/main/style.less index 9028a88..994c61b 100644 --- a/css/main/style.less +++ b/css/main/style.less @@ -7019,6 +7019,9 @@ main .dropdown_blocks_list.zero-margin.gibdd .dropdown_block { padding-right: 16px; padding-top: 10px; cursor: pointer; + width: 30px; + min-width: 30px; + padding-left: 3px; .icon { width: 16px; @@ -7027,6 +7030,23 @@ main .dropdown_blocks_list.zero-margin.gibdd .dropdown_block { } } + .loading { + width: 30px; + min-width: 30px; + + .success { + width: 24px; + min-width: 24px; + height: 30px; + min-height: 30px; + + background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12 21C16.9706 21 21 16.9706 21 12C21 7.02944 16.9706 3 12 3C7.02944 3 3 7.02944 3 12C3 16.9706 7.02944 21 12 21Z' stroke='%235FB158' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M16.125 9.75L10.625 15L7.875 12.375' stroke='%235FB158' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E%0A"); + background-repeat: no-repeat; + background-position: center; + background-position-y: 6px; + } + } + .doc_icon { display: flex; align-items: center; diff --git a/lib/CRMRequestPost/index.js b/lib/CRMRequestPost/index.js index e50782a..b131ec1 100644 --- a/lib/CRMRequestPost/index.js +++ b/lib/CRMRequestPost/index.js @@ -43,7 +43,7 @@ export default async function CRMRequestPost(req, res, path, params, array = fal await axios.post(path, payload, { headers: { - //"Content-Type": "application/json", + "Content-Type": "application/json", "Authorization": `Bearer ${ crm_jwt }`, }, withCredentials: true, diff --git a/pages/api/contract/agreement.js b/pages/api/contract/agreement.js index 15256a6..2488b25 100644 --- a/pages/api/contract/agreement.js +++ b/pages/api/contract/agreement.js @@ -1,56 +1,6 @@ -// Next.js API route support: https://nextjs.org/docs/api-routes/introduction -import axios from 'axios'; -import { Cookies } from 'react-cookie'; -import cookie from 'cookie'; -import moment from 'moment'; -import jwt from 'jsonwebtoken'; -import { cors } from '../../../lib/cors'; +import CRMRequestGet from '../../../lib/CRMRequestGet'; export default async function handler(req, res) { - await cors(req, res); - - if(req.headers.cookie !== undefined) - { - const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : ""); - if(cookies.jwt !== undefined && cookies.jwt !== null) - { - var client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT); - var crm_jwt = jwt.sign(client_jwt_decoded, process.env.JWT_SECRET_CRM, { noTimestamp: true }); - - console.log("----------"); - console.log(crm_jwt); - console.log("----------"); - - try - { - console.log(`${ process.env.CRM_API_HOST }/lk/Contract/GetDocumentList`, { ...client_jwt_decoded, contract_number: req.body.number }); - - await axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetDocumentList`, { - params: { ...client_jwt_decoded, contract_number: req.body.number }, - headers: { "Authorization": `Bearer ${ crm_jwt }`, }, - withCredentials: true, - }) - .then((crm_response) => - { - console.log(`${ process.env.CRM_API_HOST }/lk/Contract/GetDocumentList`, "RESPONSE", crm_response.data); - res.status(200).json(crm_response.data); - }) - .catch((error) => - { - console.error(error); - res.status(500); - }); - } - catch(e) - { - console.error(e); - res.status(500); - } - } - else - { - res.status(403); - } - } + await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/GetDocumentList`, { contract_number: req.body.number }); } \ No newline at end of file diff --git a/pages/api/contract/documents.js b/pages/api/contract/documents.js index e2f47c1..d18e93e 100644 --- a/pages/api/contract/documents.js +++ b/pages/api/contract/documents.js @@ -11,50 +11,65 @@ export default async function handler(req, res) { await cors(req, res); - if(req.headers.cookie !== undefined) + return new Promise(async (resolve) => { - const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : ""); - if(cookies.jwt !== undefined && cookies.jwt !== null) + if(req.headers.cookie !== undefined) { - var client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT); - var crm_jwt = jwt.sign(client_jwt_decoded, process.env.JWT_SECRET_CRM, { noTimestamp: true }); + const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : ""); + if(cookies.jwt !== undefined && cookies.jwt !== null) + { + var client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT); + var crm_jwt = jwt.sign(client_jwt_decoded, process.env.JWT_SECRET_CRM, { noTimestamp: true }); - const result = { - upd: [], - upd_avans: [], - billfines: [], - }; + const result = { + upd: [], + upd_avans: [], + billfines: [], + }; - axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetUPDListByContract`, { - params: { ...client_jwt_decoded, contract_number: req.body.number }, - headers: { "Authorization": `Bearer ${ crm_jwt }`, }, - }) - .then((crm_response) => - { - console.log(inspect(crm_response.data, true, null, true)); - for(let i in crm_response.data) - { - if(crm_response.data[i].type === "UPD") + axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetUPDListByContract`, { + params: { ...client_jwt_decoded, contract_number: req.body.number }, + headers: { "Authorization": `Bearer ${ crm_jwt }`, }, + }) + .then((crm_response) => + { + console.log(inspect(crm_response.data, true, null, true)); + for(let i in crm_response.data) { - result.upd = crm_response.data[i].upd; + if(crm_response.data[i].type === "UPD") + { + result.upd = crm_response.data[i].upd; + } + if(crm_response.data[i].type === "UPD_Avans") + { + result.upd_avans = crm_response.data[i].upd; + } + if(crm_response.data[i].type === "BillFine") + { + result.billfines = crm_response.data[i].upd; + } } - if(crm_response.data[i].type === "UPD_Avans") - { - result.upd_avans = crm_response.data[i].upd; - } - if(crm_response.data[i].type === "BillFine") - { - result.billfines = crm_response.data[i].upd; - } - } - res.status(200).json(result); - }) - .catch((error) => { console.error(error); resolve(); }); + res.status(200).json(result); + resolve(); + }) + .catch((error) => + { + console.error(error); + res.status(500).send(); + resolve(); + }); + } + else + { + res.status(403).send(); + resolve(); + } } else { - res.status(403); + res.status(403).send(); + resolve(); } - } + }); } \ No newline at end of file diff --git a/pages/api/contract/fines.js b/pages/api/contract/fines.js index 220f60c..1bf0f94 100644 --- a/pages/api/contract/fines.js +++ b/pages/api/contract/fines.js @@ -1,44 +1,6 @@ -// Next.js API route support: https://nextjs.org/docs/api-routes/introduction -import axios from 'axios'; -import { Cookies } from 'react-cookie'; -import cookie from 'cookie'; -import moment from 'moment'; -import jwt from 'jsonwebtoken'; -import { cors } from '../../../lib/cors'; -import { inspect } from 'util'; +import CRMRequestGet from '../../../lib/CRMRequestGet'; export default async function handler(req, res) { - await cors(req, res); - - if(req.headers.cookie !== undefined) - { - const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : ""); - if(cookies.jwt !== undefined && cookies.jwt !== null) - { - var client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT); - var crm_jwt = jwt.sign(client_jwt_decoded, process.env.JWT_SECRET_CRM, { noTimestamp: true }); - - const result = { - fines: [], - }; - - axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetFineGIBDDList`, { - params: { ...client_jwt_decoded, contract_number: req.body.number }, - headers: { "Authorization": `Bearer ${ crm_jwt }`, }, - }) - .then((crm_response) => - { - result.fines = crm_response.data; - - res.status(200).json(result); - }) - .catch((error) => { console.error(error); }); - - } - else - { - res.status(403); - } - } + await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/GetFineGIBDDList`, { contract_number: req.body.number }); } \ No newline at end of file diff --git a/pages/api/contract/helpcard.js b/pages/api/contract/helpcard.js index 8c1e151..b24e9ff 100644 --- a/pages/api/contract/helpcard.js +++ b/pages/api/contract/helpcard.js @@ -1,46 +1,6 @@ -// Next.js API route support: https://nextjs.org/docs/api-routes/introduction -import axios from 'axios'; -import { Cookies } from 'react-cookie'; -import cookie from 'cookie'; -import moment from 'moment'; -import jwt from 'jsonwebtoken'; -import { cors } from '../../../lib/cors'; +import CRMRequestGet from '../../../lib/CRMRequestGet'; export default async function handler(req, res) { - await cors(req, res); - - if(req.headers.cookie !== undefined) - { - const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : ""); - if(cookies.jwt !== undefined && cookies.jwt !== null) - { - var client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT); - var crm_jwt = jwt.sign(client_jwt_decoded, process.env.JWT_SECRET_CRM, { noTimestamp: true }); - - const response = await new Promise((resolve) => - { - axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetHelpCard`, { - params: { ...client_jwt_decoded, contract_number: req.body.number }, - headers: { "Authorization": `Bearer ${ crm_jwt }`, }, - withCredentials: true, - }) - .then((crm_response) => - { - resolve(crm_response.data); - }) - .catch((error) => - { - console.error(error); - resolve(error); - }); - }); - - res.status(200).json(response); - } - else - { - res.status(403); - } - } + await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/GetHelpCard`, { contract_number: req.body.number }); } \ No newline at end of file diff --git a/pages/api/contract/index.js b/pages/api/contract/index.js index 8723949..6dac597 100644 --- a/pages/api/contract/index.js +++ b/pages/api/contract/index.js @@ -1,66 +1,6 @@ -// Next.js API route support: https://nextjs.org/docs/api-routes/introduction -import axios from 'axios'; -import { Cookies } from 'react-cookie'; -import cookie from 'cookie'; -import moment from 'moment'; -import jwt from 'jsonwebtoken'; -import { cors } from '../../../lib/cors'; +import CRMRequestGet from '../../../lib/CRMRequestGet'; export default async function handler(req, res) { - await cors(req, res); - - if(req.headers.cookie !== undefined) - { - const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : ""); - - console.log("req.body"); - console.log(req.body); - - if(cookies.jwt !== undefined && cookies.jwt !== null) - { - console.log("cookies.jwt"); - console.log(cookies.jwt); - - var client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT); - var crm_jwt = jwt.sign(client_jwt_decoded, process.env.JWT_SECRET_CRM, { noTimestamp: true }); - - console.log("client_jwt_decoded", client_jwt_decoded); - console.log("crm_jwt", crm_jwt); - - console.log(`${ process.env.CRM_API_HOST }/lk/Contract/GetSchedulePayments`); - - try - { - await axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetSchedulePayments`, { - params: { ...client_jwt_decoded, contract_number: req.body.number }, - headers: { - "Authorization": `Bearer ${ crm_jwt }`, - }, - withCredentials: true, - }) - .then((crm_response) => - { - console.log("API", "contract", "crm_response.data"); - //console.log("API", "contract", crm_response.data); - - res.status(200).json(crm_response.data); - }) - .catch((error) => - { - console.error(error); - res.status(500); - }); - } - catch(e) - { - console.error(e); - res.status(500); - } - } - else - { - res.status(403); - } - } + await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/GetSchedulePayments`, { contract_number: req.body.number }); } \ No newline at end of file diff --git a/pages/api/contract/info.js b/pages/api/contract/info.js index 9557149..4bf0953 100644 --- a/pages/api/contract/info.js +++ b/pages/api/contract/info.js @@ -1,49 +1,6 @@ -// Next.js API route support: https://nextjs.org/docs/api-routes/introduction -import axios from 'axios'; -import { Cookies } from 'react-cookie'; -import cookie from 'cookie'; -import moment from 'moment'; -import jwt from 'jsonwebtoken'; -import { cors } from '../../../lib/cors'; +import CRMRequestGet from '../../../lib/CRMRequestGet'; export default async function handler(req, res) { - await cors(req, res); - - if(req.headers.cookie !== undefined) - { - const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : ""); - if(cookies.jwt !== undefined && cookies.jwt !== null) - { - var client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT); - var crm_jwt = jwt.sign(client_jwt_decoded, process.env.JWT_SECRET_CRM, { noTimestamp: true }); - - try - { - await axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetAddInfoForContract`, { - params: { ...client_jwt_decoded, contract_number: req.body.number }, - headers: { "Authorization": `Bearer ${ crm_jwt }`, }, - withCredentials: true, - }) - .then((crm_response) => - { - res.status(200).json(crm_response.data); - }) - .catch((error) => - { - console.error(error); - res.status(500); - }); - } - catch(e) - { - console.error(e); - res.status(500); - } - } - else - { - res.status(403); - } - } + await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/GetAddInfoForContract`, { contract_number: req.body.number }); } \ No newline at end of file diff --git a/pages/api/contract/insurance.js b/pages/api/contract/insurance.js index 96ef598..65e8549 100644 --- a/pages/api/contract/insurance.js +++ b/pages/api/contract/insurance.js @@ -10,103 +10,108 @@ export default async function handler(req, res) { await cors(req, res); - if(req.headers.cookie !== undefined) + return new Promise(async (resolve) => { - const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : ""); - - console.log("req.body"); - console.log(req.body); - - if(cookies.jwt !== undefined && cookies.jwt !== null) + if(req.headers.cookie !== undefined) { - console.log("cookies.jwt"); - console.log(cookies.jwt); + const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : ""); - var client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT); - var crm_jwt = jwt.sign(client_jwt_decoded, process.env.JWT_SECRET_CRM, { noTimestamp: true }); + console.log("req.body"); + console.log(req.body); - console.log("client_jwt_decoded", client_jwt_decoded); - console.log("crm_jwt", crm_jwt); - - console.log(`${ process.env.CRM_API_HOST }/lk/Contract/GetOsago`); - - const result = { - osago: null, - kasko: null, - nsib: null, - }; - - await Promise.all([ - new Promise((resolve) => { - axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetOsago`, { - params: { ...client_jwt_decoded, contract_number: req.body.number }, - headers: { "Authorization": `Bearer ${ crm_jwt }`, }, - }) - .then((crm_response) => { result.osago = crm_response.data; resolve(); }) - .catch((error) => { console.error(error); resolve(); }); - }), - new Promise((resolve) => { - axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetKasko`, { - params: { ...client_jwt_decoded, contract_number: req.body.number }, - headers: { "Authorization": `Bearer ${ crm_jwt }`, }, - }) - .then((crm_response) => { result.kasko = crm_response.data; resolve(); }) - .catch((error) => { console.error(error); resolve(); }); - }), - new Promise((resolve) => { - axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetNsib`, { - params: { ...client_jwt_decoded, contract_number: req.body.number }, - headers: { "Authorization": `Bearer ${ crm_jwt }`, }, - }) - .then((crm_response) => { result.nsib = crm_response.data; resolve(); }) - .catch((error) => { console.error(error); resolve(); }); - }), - new Promise((resolve) => { - axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetFinGap`, { - params: { ...client_jwt_decoded, contract_number: req.body.number }, - headers: { "Authorization": `Bearer ${ crm_jwt }`, }, - }) - .then((crm_response) => { - result.fingap = crm_response.data; - /*result.fingap = [ - { - paid: true, - period_type: "current", - invoice_url: null, - company: "АО \"ГСК \"ЮГОРИЯ\"", - site: null, - phone: null, - number: "ТестФингап", - url: null, - period: "14.07.2021 - 13.07.2022", - amount: 1200000.00 - }, - { - paid: false, - period_type: "prolong", - invoice_url: "353082cc-f38f-4da6-bcd4-3a6048eceb10", - company: "АО \"ГСК \"ЮГОРИЯ\"", - site: null, - phone: null, - number: "ТестФингап", - url: null, - period: "14.07.2022 - 13.07.2023", - amount: null - } - ];*/ - resolve(); - }) - .catch((error) => { console.error(error); resolve(); }); - }), - ]) - .then(() => + if(cookies.jwt !== undefined && cookies.jwt !== null) { - res.status(200).json(result); - }); + console.log("cookies.jwt"); + console.log(cookies.jwt); + + var client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT); + var crm_jwt = jwt.sign(client_jwt_decoded, process.env.JWT_SECRET_CRM, { noTimestamp: true }); + + console.log("client_jwt_decoded", client_jwt_decoded); + console.log("crm_jwt", crm_jwt); + + console.log(`${ process.env.CRM_API_HOST }/lk/Contract/GetOsago`); + + const result = { + osago: null, + kasko: null, + nsib: null, + }; + + await Promise.all([ + new Promise((resolve_osago) => { + axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetOsago`, { + params: { ...client_jwt_decoded, contract_number: req.body.number }, + headers: { "Authorization": `Bearer ${ crm_jwt }`, }, + }) + .then((crm_response) => { + result.osago = crm_response.data; + resolve_osago(); + }) + .catch((error) => { + console.error(error); + resolve_osago(); + }); + }), + new Promise((resolve_kasko) => { + axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetKasko`, { + params: { ...client_jwt_decoded, contract_number: req.body.number }, + headers: { "Authorization": `Bearer ${ crm_jwt }`, }, + }) + .then((crm_response) => { + result.kasko = crm_response.data; + resolve_kasko(); + }) + .catch((error) => { + console.error(error); + resolve_kasko(); + }); + }), + new Promise((resolve_nsib) => { + axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetNsib`, { + params: { ...client_jwt_decoded, contract_number: req.body.number }, + headers: { "Authorization": `Bearer ${ crm_jwt }`, }, + }) + .then((crm_response) => { + result.nsib = crm_response.data; + resolve_nsib(); + }) + .catch((error) => { + console.error(error); + resolve_nsib(); + }); + }), + new Promise((resolve_fingap) => { + axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetFinGap`, { + params: { ...client_jwt_decoded, contract_number: req.body.number }, + headers: { "Authorization": `Bearer ${ crm_jwt }`, }, + }) + .then((crm_response) => { + result.fingap = crm_response.data; + resolve_fingap(); + }) + .catch((error) => { + console.error(error); + resolve_fingap(); + }); + }), + ]) + .then(() => + { + res.status(200).json(result); + resolve(); + }); + } + else + { + res.status(403).send(); + resolve(); + } } else { - res.status(403); + res.status(403).send(); + resolve(); } - } + }); } \ No newline at end of file diff --git a/pages/api/contract/materials.js b/pages/api/contract/materials.js index 93e62ae..0783432 100644 --- a/pages/api/contract/materials.js +++ b/pages/api/contract/materials.js @@ -10,14 +10,14 @@ export default async function handler(req, res) { await cors(req, res); - if(req.headers.cookie !== undefined) + return new Promise(async (resolve) => { - const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : ""); - if(cookies.jwt !== undefined && cookies.jwt !== null) + if(req.headers.cookie !== undefined) { - if(jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT)) + const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : ""); + if(cookies.jwt !== undefined && cookies.jwt !== null) { - const response = await new Promise((resolve, reject) => + if(jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT)) { axios.post(`${ process.env.NEXT_PUBLIC_API_HOST }/api/account/materials/`, { }) @@ -26,27 +26,34 @@ export default async function handler(req, res) console.log("RESPONSE"); console.log(api_response.data); - resolve(api_response.data); + res.status(200).json(api_response.data); + resolve(); }) .catch((error) => { console.log("error"); console.error(error); - reject([]); + res.status(500).send(); + resolve(); }); - }); - - res.status(200).json(response); + } + else + { + res.status(403).send(); + resolve(); + } } else { - res.status(403); + res.status(403).send(); + resolve(); } } else { - res.status(403); + res.status(403).send(); + resolve(); } - } + }); } \ No newline at end of file diff --git a/pages/api/contract/penalties.js b/pages/api/contract/penalties.js index ab9cf05..0d366f3 100644 --- a/pages/api/contract/penalties.js +++ b/pages/api/contract/penalties.js @@ -1,51 +1,6 @@ -// Next.js API route support: https://nextjs.org/docs/api-routes/introduction -import axios from 'axios'; -import { Cookies } from 'react-cookie'; -import cookie from 'cookie'; -import moment from 'moment'; -import jwt from 'jsonwebtoken'; -import { cors } from '../../../lib/cors'; +import CRMRequestGet from '../../../lib/CRMRequestGet'; export default async function handler(req, res) { - console.log("API", "penalties"); - await cors(req, res); - - if(req.headers.cookie !== undefined) - { - const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : ""); - if(cookies.jwt !== undefined && cookies.jwt !== null) - { - var client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT); - var crm_jwt = jwt.sign(client_jwt_decoded, process.env.JWT_SECRET_CRM, { noTimestamp: true }); - - const response = await new Promise((resolve) => - { - console.log("API", "penalties", `${ process.env.CRM_API_HOST }/lk/Contract/GetPlannedFines`, { contract_number: req.body.number, planned_date: req.body.date }); - - axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetPlannedFines`, { - params: { ...client_jwt_decoded, contract_number: req.body.number, planned_date: req.body.date }, - headers: { "Authorization": `Bearer ${ crm_jwt }`, }, - withCredentials: true, - }) - .then((crm_response) => - { - console.log("API", "penalties", "crm_response.data", crm_response.data); - - resolve(crm_response.data); - }) - .catch((error) => - { - console.error(error); - resolve(error); - }); - }); - - res.status(200).json(response); - } - else - { - res.status(403); - } - } + await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/GetPlannedFines`, { contract_number: req.body.number, planned_date: req.body.date }); } \ No newline at end of file diff --git a/pages/api/contract/registration.js b/pages/api/contract/registration.js index a16c75d..da1243e 100644 --- a/pages/api/contract/registration.js +++ b/pages/api/contract/registration.js @@ -1,46 +1,6 @@ -// Next.js API route support: https://nextjs.org/docs/api-routes/introduction -import axios from 'axios'; -import { Cookies } from 'react-cookie'; -import cookie from 'cookie'; -import moment from 'moment'; -import jwt from 'jsonwebtoken'; -import { cors } from '../../../lib/cors'; +import CRMRequestGet from '../../../lib/CRMRequestGet'; export default async function handler(req, res) { - await cors(req, res); - - if(req.headers.cookie !== undefined) - { - const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : ""); - if(cookies.jwt !== undefined && cookies.jwt !== null) - { - var client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT); - var crm_jwt = jwt.sign(client_jwt_decoded, process.env.JWT_SECRET_CRM, { noTimestamp: true }); - - const response = await new Promise((resolve) => - { - axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetRegistration`, { - params: { ...client_jwt_decoded, contract_number: req.body.number }, - headers: { "Authorization": `Bearer ${ crm_jwt }`, }, - withCredentials: true, - }) - .then((crm_response) => - { - resolve(crm_response.data); - }) - .catch((error) => - { - console.error(error); - resolve(error); - }); - }); - - res.status(200).json(response); - } - else - { - res.status(403); - } - } + await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/GetRegistration`, { contract_number: req.body.number }); } \ No newline at end of file diff --git a/pages/api/contract/rules.js b/pages/api/contract/rules.js index 4271a17..0c0046b 100644 --- a/pages/api/contract/rules.js +++ b/pages/api/contract/rules.js @@ -10,14 +10,14 @@ export default async function handler(req, res) { await cors(req, res); - if(req.headers.cookie !== undefined) + return new Promise(async (resolve) => { - const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : ""); - if(cookies.jwt !== undefined && cookies.jwt !== null) + if(req.headers.cookie !== undefined) { - if(jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT)) + const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : ""); + if(cookies.jwt !== undefined && cookies.jwt !== null) { - const response = await new Promise((resolve, reject) => + if(jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT)) { axios.post(`${ process.env.NEXT_PUBLIC_API_HOST }/api/account/rules/`, { date: req.body.date, @@ -27,27 +27,34 @@ export default async function handler(req, res) console.log("RESPONSE"); console.log(api_response.data); - resolve(api_response.data); + res.status(200).json(api_response.data); + resolve(); }) .catch((error) => { console.log("error"); console.error(error); - reject([]); + res.status(500).send(); + resolve(); }); - }); - - res.status(200).json(response); + } + else + { + res.status(403).send(); + resolve(); + } } else { - res.status(403); + res.status(403).send(); + resolve(); } } else { - res.status(403); + res.status(403).send(); + resolve(); } - } + }); } \ No newline at end of file diff --git a/pages/api/contract/telematic.js b/pages/api/contract/telematic.js index 4274f46..e49ea3d 100644 --- a/pages/api/contract/telematic.js +++ b/pages/api/contract/telematic.js @@ -1,46 +1,6 @@ -// Next.js API route support: https://nextjs.org/docs/api-routes/introduction -import axios from 'axios'; -import { Cookies } from 'react-cookie'; -import cookie from 'cookie'; -import moment from 'moment'; -import jwt from 'jsonwebtoken'; -import { cors } from '../../../lib/cors'; +import CRMRequestGet from '../../../lib/CRMRequestGet'; export default async function handler(req, res) { - await cors(req, res); - - if(req.headers.cookie !== undefined) - { - const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : ""); - if(cookies.jwt !== undefined && cookies.jwt !== null) - { - var client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT); - var crm_jwt = jwt.sign(client_jwt_decoded, process.env.JWT_SECRET_CRM, { noTimestamp: true }); - - const response = await new Promise((resolve) => - { - axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetTelematics`, { - params: { ...client_jwt_decoded, contract_number: req.body.number }, - headers: { "Authorization": `Bearer ${ crm_jwt }`, }, - withCredentials: true, - }) - .then((crm_response) => - { - resolve(crm_response.data); - }) - .catch((error) => - { - console.error(error); - resolve(error); - }); - }); - - res.status(200).json(response); - } - else - { - res.status(403); - } - } + await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/GetTelematics`, { contract_number: req.body.number }); } \ No newline at end of file diff --git a/pages/api/deals/index.js b/pages/api/deals/index.js index 7594011..c24e4b3 100644 --- a/pages/api/deals/index.js +++ b/pages/api/deals/index.js @@ -3,82 +3,9 @@ GET /lk/ConsiderationOpportunity */ -import axios from 'axios'; -import { Cookies } from 'react-cookie'; -import cookie from 'cookie'; -import moment from 'moment'; -import jwt from 'jsonwebtoken'; -import { cors } from '../../../lib/cors'; +import CRMRequestGet from '../../../lib/CRMRequestGet'; export default async function handler(req, res) { - await cors(req, res); - - return new Promise(async (resolve) => - { - if(req.headers.cookie !== undefined) - { - const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : ""); - - console.log("req.body"); - console.log(req.body); - - if(cookies.jwt !== undefined && cookies.jwt !== null) - { - console.log("cookies.jwt"); - console.log(cookies.jwt); - - var client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT); - const crm_payload = { acc_number: client_jwt_decoded.acc_number }; - var crm_jwt = jwt.sign(crm_payload, process.env.JWT_SECRET_CRM, { noTimestamp: true }); - - console.log("client_jwt_decoded", client_jwt_decoded); - console.log("crm_jwt", crm_jwt); - - const url = `${ process.env.CRM_API_HOST }/lk/ConsiderationOpportunity/`; - console.log({ url }); - - try - { - await axios.get(url, { - params: crm_payload, - headers: { - "Authorization": `Bearer ${ crm_jwt }`, - }, - withCredentials: true, - }) - .then((crm_response) => - { - console.log("API", "contract", "crm_response.data"); - //console.log("API", "contract", crm_response.data); - - res.status(200).json(crm_response.data); - resolve(); - }) - .catch((error) => - { - console.error(error); - res.status(500).send(); - resolve(); - }); - } - catch(e) - { - console.error(e); - res.status(500).send(); - resolve(); - } - } - else - { - res.status(403).send(); - resolve(); - } - } - else - { - res.status(403).send(); - resolve(); - } - }); + await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/ConsiderationOpportunity/`, {}); } \ No newline at end of file diff --git a/pages/api/deals/upload.js b/pages/api/deals/upload.js index de3a5ca..34b586d 100644 --- a/pages/api/deals/upload.js +++ b/pages/api/deals/upload.js @@ -1,4 +1,107 @@ /* 2.7.5 - Метод отправки документов по Сделке на проверку POST /lk/document -*/ \ No newline at end of file +*/ + +import axios from 'axios'; +import { Cookies } from 'react-cookie'; +import cookie from 'cookie'; +import moment from 'moment'; +import jwt from 'jsonwebtoken'; +import { inspect } from 'util'; +import FormData from 'form-data'; +import multer from 'multer'; + +import { cors } from '../../../lib/cors'; + +const storage = multer.memoryStorage(); +const upload = multer({ storage: storage }); + +export default async function handler(req, res) +{ + await cors(req, res); + + console.log("Qqqqqqq", req); + const { number, entity, id, filename } = req.query; + + return new Promise((resolve) => + { + if(req.headers.cookie !== undefined) + { + const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : ""); + + if(cookies.jwt !== undefined && cookies.jwt !== null) + { + var client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT); + var crm_jwt = jwt.sign({ acc_number: client_jwt_decoded.acc_number }, process.env.JWT_SECRET_CRM, { noTimestamp: true }); + + const payload = new URLSearchParams({ + name: number, + entity: entity, + documentTypeNumber: id, + documentName: filename, + }); + const path = `${ process.env.CRM_API_HOST }/lk/incident/RequestClient/UploadDocument?${ payload.toString() }`; + +// res.status(200).json({ path }); +// resolve(); + + upload.single("file")(req, {}, err => + { + const { file } = req; + file.originalname = Buffer.from(file.originalname, 'latin1').toString('utf8'); + + const data = new FormData(); + data.append("file", file.buffer, file.originalname); + + try + { + axios.post(path, data, + { + headers: { + "Content-Type": `multipart/form-data; boundary=${ data._boundary }`, + "Authorization": `Bearer ${ crm_jwt }`, + }, + withCredentials: true, + }) + .then((crm_response) => + { + res.status(200).json(crm_response.data); + resolve(); + }) + .catch((error) => + { + console.error("-".repeat(30), "error.response.data:"); + console.error(error.response.data); + + res.status(500).json(error.response.data); + resolve(); + }); + } + catch(e) + { + console.error(e); + res.status(500).send(e); + resolve(); + } + }); + } + else + { + res.status(403).send(); + resolve(); + } + } + else + { + res.status(403).send(); + resolve(); + } + }); +} + +export const config = { + api: { + bodyParser: false + } +} \ No newline at end of file diff --git a/pages/api/file/download.js b/pages/api/file/download.js index 1921027..a56c9c5 100644 --- a/pages/api/file/download.js +++ b/pages/api/file/download.js @@ -21,7 +21,7 @@ export default async function handler(req, res) try { axios.get(`${ process.env.CRM_API_HOST }/file/GetFile/`, { - params: { ...client_jwt_decoded, id: req.query.id }, + params: { acc_number: client_jwt_decoded.acc_number, id: req.query.id }, responseType: 'arraybuffer', headers: { "Authorization": `Bearer ${ crm_jwt }`, @@ -42,22 +42,26 @@ export default async function handler(req, res) console.log("-".repeat(50)); res.status(200).send(crm_response.data); + resolve(); }) .catch((error) => { console.error(error); - res.status(500); + res.status(500).send(); + resolve(); }); } catch(e) { console.error(e); - res.status(500); + res.status(500).send(); + resolve(); } } else { - res.status(403); + res.status(403).send(); + resolve(); } } } \ No newline at end of file diff --git a/pages/contract/agreement.js b/pages/contract/agreement.js index 1f5950b..435dbcf 100644 --- a/pages/contract/agreement.js +++ b/pages/contract/agreement.js @@ -123,6 +123,7 @@ class ContractPage extends React.Component log={{ contract_number: this.props.number, document_type: type, + document_name: file.number, document_date: file.date, description: file.type, }} diff --git a/pages/contract/services.js b/pages/contract/services.js index cc4f237..2e7c5a4 100644 --- a/pages/contract/services.js +++ b/pages/contract/services.js @@ -312,16 +312,16 @@ class ContractServicesPage extends React.Component { this._checkInsuranceAvailable() ? (
{ insurance.kasko !== undefined && insurance.kasko !== null && insurance.kasko !== "" && insurance.kasko.map !== undefined && insurance.kasko.map((entry, index) => ( - + )) } { insurance.osago !== undefined && insurance.osago !== null && insurance.osago !== "" && insurance.osago.map !== undefined && insurance.osago.map((entry, index) => ( - + )) } { insurance.nsib !== undefined && insurance.nsib !== null && insurance.nsib !== "" && insurance.nsib.map !== undefined && insurance.nsib.map((entry, index) => ( - + )) } { insurance.fingap !== undefined && insurance.fingap !== null && insurance.fingap !== "" && insurance.fingap.map !== undefined && insurance.fingap.map((entry, index) => ( - + )) }
) : ( diff --git a/pages/support/appeals.js b/pages/support/appeals.js index df02b3f..3237478 100644 --- a/pages/support/appeals.js +++ b/pages/support/appeals.js @@ -103,7 +103,6 @@ class SupportAppealsPage extends React.Component const active_count = this._activeAppealsCount(); //console.log(appeals); - return ( @@ -166,13 +165,14 @@ class SupportAppealsPage extends React.Component
{ appeal.documents.map((file, index) => { if(file.doc_direction !== "incoming") { return null; } + return ( ) }) }