From 4e0e0de5fb6726bad1f3f943b38ef7ffa7f5ffbf Mon Sep 17 00:00:00 2001 From: Chika Date: Tue, 22 Dec 2020 21:14:03 +0300 Subject: [PATCH] server is only for dev & fix getUser --- .env | 2 - .gitignore | 2 + Dockerfile | 4 ++ docker-compose.yml | 4 +- package.json | 40 ++++++------------ .../Calculation/lib/fetchData/index.js | 6 +-- .../lib/fetchData/queries/ownerQuery.ts | 6 +-- .../lib/fetchData/queries/systemUserQuery.ts | 4 +- .../services/CalculationService/index.ts | 17 +------- .../Effects/actions/createKP.js | 4 +- src/client/tools/user.ts | 25 +++++------ src/core/constants/domain.js | 2 - src/core/types/Calculation/Responses.ts | 7 +--- src/core/types/user.ts | 4 +- src/server/controllers/UsersController.ts | 12 ------ src/server/entities/index.ts | 1 - src/server/index.ts | 41 +------------------ src/server/routes/index.ts | 2 - src/server/routes/users.ts | 8 ---- webpack.config.server.js | 2 - 20 files changed, 46 insertions(+), 147 deletions(-) delete mode 100644 .env delete mode 100644 src/core/constants/domain.js delete mode 100644 src/server/controllers/UsersController.ts delete mode 100644 src/server/entities/index.ts delete mode 100644 src/server/routes/users.ts diff --git a/.env b/.env deleted file mode 100644 index cd1d11d..0000000 --- a/.env +++ /dev/null @@ -1,2 +0,0 @@ -GENERATE_SOURCEMAP=false -REACT_APP_CRM=dev \ No newline at end of file diff --git a/.gitignore b/.gitignore index 23c2144..6a0ccd4 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ # misc .DS_Store +.env .env.local .env.development.local .env.test.local @@ -25,3 +26,4 @@ yarn.lock *.log package-lock.json /.vscode +.eslintcache diff --git a/Dockerfile b/Dockerfile index 37b198f..acfb491 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,9 @@ FROM node:14-alpine as builder +ENV NODE_ENV=production +ENV REACT_APP_CRM=prod +ENV GENERATE_SOURCEMAP=false + WORKDIR /app COPY package.json /app/ diff --git a/docker-compose.yml b/docker-compose.yml index f97ebbe..8ff8439 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,8 +2,6 @@ version: '3.3' services: auth: build: ./EvoCalculator.Auth - ports: - - '8888:8888' networks: - calc_network restart: always @@ -25,6 +23,8 @@ services: proxy: restart: always build: ./EvoCalculator.Proxy + environment: + - CRM_URL=http://... ports: - '4000:80' networks: diff --git a/package.json b/package.json index 56d504f..ae71ff9 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "evo_calculator", + "name": "evocalculator.client", "private": true, "dependencies": { "@apollo/client": "^3.3.4", @@ -9,29 +9,16 @@ "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.3.2", "@testing-library/user-event": "^7.1.2", - "@types/graphql": "^14.5.0", - "antd": "^4.9.2", - "axios": "^0.21.0", - "body-parser": "^1.19.0", - "class-validator": "^0.12.2", - "compression": "^1.7.4", - "cookie-parser": "^1.4.5", + "antd": "^4.9.4", + "axios": "^0.21.1", "cors": "^2.8.5", "craco-less": "^1.17.1", - "cross-fetch": "^3.0.6", - "dotenv": "^8.2.0", - "dotenv-webpack": "^6.0.0", - "express": "^4.17.1", - "express-http-proxy": "^1.6.2", - "express-ntlm": "^2.5.2", "graphql": "^15.4.0", - "helmet": "^4.2.0", "js-cookie": "^2.2.1", "lodash": "^4.17.20", "luxon": "^1.25.0", "mobx": "^6.0.4", "mobx-react-lite": "^3.1.6", - "morgan": "^1.10.0", "normalize.css": "^8.0.1", "pluralize": "^8.0.0", "react": "^17.0.1", @@ -39,50 +26,47 @@ "react-router": "^5.2.0", "react-router-dom": "^5.2.0", "react-scripts": "^4.0.1", - "recompose": "^0.30.0", - "reflect-metadata": "^0.1.13", "styled-components": "^5.2.1", "styled-system": "^5.1.5", - "ts-loader": "^8.0.11", - "typescript": "4.1.2", + "ts-loader": "^8.0.12", + "typescript": "4.1.3", "use-debounce": "^5.1.0", "uuid": "^8.3.2", "validator": "^13.5.1" }, "devDependencies": { - "@types/body-parser": "^1.19.0", - "@types/compression": "^1.7.0", - "@types/cookie-parser": "^1.4.2", "@types/cors": "^2.8.8", "@types/express": "^4.17.9", - "@types/express-http-proxy": "^1.6.1", "@types/jest": "^26.0.15", "@types/lodash": "^4.14.165", "@types/luxon": "^1.25.0", - "@types/morgan": "^1.9.2", "@types/node": "^14.14.12", "@types/pluralize": "^0.0.29", "@types/react-router-dom": "^5.1.6", "@types/styled-components": "^5.1.2", "@types/styled-system": "^5.1.10", + "cross-env": "^7.0.3", + "express": "^4.17.1", + "express-http-proxy": "^1.6.2", "http-proxy-middleware": "^1.0.6", "nodemon": "^2.0.6", "rimraf": "^3.0.2", + "wait-on": "^5.2.0", "webpack-cli": "^4.2.0", "webpack-node-externals": "^2.5.2" }, "scripts": { "test": "craco test", "eject": "react-scripts eject", - "dev": "cross-env NODE_ENV=development dotenv -e .env -- concurrently -p name -c \"yellow,magenta,blue\" -n \"webpack-server,nodemon-server,CRA\" \"npm run dev:server:webpack\" \"npm run dev:server:nodemon\" \"npm run dev:client\"", + "dev": "cross-env NODE_ENV=development REACT_APP_CRM=dev concurrently -p name -c \"yellow,magenta,blue\" -n \"webpack-server,nodemon-server,CRA\" \"npm run dev:server:webpack\" \"npm run dev:server:nodemon\" \"npm run dev:client\"", "dev:client:only": "craco start", "dev:client": "wait-on -l tcp:3001 && craco start", "dev:server": "concurrently -p name -c \"yellow,magenta\" -n \"webpack-server,nodemon-server\" \"npm run dev:server:webpack\" \"npm run dev:server:nodemon\"", "dev:server:webpack": "webpack --config webpack.config.server.js --watch", "dev:server:nodemon": "rimraf build/server.js && wait-on -l build/server.js && nodemon build/server.js", - "build": "dotenv -e .env npm run build:client && npm run build:server", + "build": "npm run build:client && npm run build:server", "build:client": "craco build", - "build:server": "cross-env NODE_ENV=production webpack --config webpack.config.server.js" + "build:server": "webpack --config webpack.config.server.js" }, "eslintConfig": { "extends": "react-app" diff --git a/src/client/Containers/Calculation/lib/fetchData/index.js b/src/client/Containers/Calculation/lib/fetchData/index.js index a48ea7e..1fb5da5 100644 --- a/src/client/Containers/Calculation/lib/fetchData/index.js +++ b/src/client/Containers/Calculation/lib/fetchData/index.js @@ -9,21 +9,21 @@ import systemUserQuery from './queries/systemUserQuery'; export default () => new Promise((resolve, reject) => { - const { username: UserName, domainname: DomainName, FullName } = getUser(); + const { domainname } = getUser(); Promise.all([ CrmService.crmgqlquery({ ...initialOwnerQuery, variables: { statecode: 0, - fullName: FullName, + domainname, }, }), CrmService.crmgqlquery(optionsQuery), CrmService.crmgqlquery(staticDataQuery), CrmService.crmgqlquery({ ...systemUserQuery, - variables: { username: `${DomainName}\\${UserName}` }, + variables: { domainname }, }), CrmService.crmgqlquery(insuranceQuery), ]) diff --git a/src/client/Containers/Calculation/lib/fetchData/queries/ownerQuery.ts b/src/client/Containers/Calculation/lib/fetchData/queries/ownerQuery.ts index 291bef8..082f17a 100644 --- a/src/client/Containers/Calculation/lib/fetchData/queries/ownerQuery.ts +++ b/src/client/Containers/Calculation/lib/fetchData/queries/ownerQuery.ts @@ -2,8 +2,8 @@ import { IQueryToCRMGQL } from 'core/types/Calculation/Requests'; import { gql } from '@apollo/client'; const query = gql` - query($statecode: Int, $fullName: String) { - selectLead: leads(statecode: $statecode, owner_domainname: $fullName) { + query($statecode: Int, $domainname: String) { + selectLead: leads(statecode: $statecode, owner_domainname: $domainname) { customerid leadid fullname @@ -15,7 +15,7 @@ const query = gql` } selectOpportunity: opportunities( statecode: $statecode - owner_domainname: $fullName + owner_domainname: $domainname ) { opportunityid name diff --git a/src/client/Containers/Calculation/lib/fetchData/queries/systemUserQuery.ts b/src/client/Containers/Calculation/lib/fetchData/queries/systemUserQuery.ts index 252d16b..e896106 100644 --- a/src/client/Containers/Calculation/lib/fetchData/queries/systemUserQuery.ts +++ b/src/client/Containers/Calculation/lib/fetchData/queries/systemUserQuery.ts @@ -2,8 +2,8 @@ import { gql } from '@apollo/client'; export default { query: gql` - query($username: String) { - systemuser(domainname: $username) { + query($domainname: String) { + systemuser(domainname: $domainname) { evo_job_titleid businessunitid firstname diff --git a/src/client/services/CalculationService/index.ts b/src/client/services/CalculationService/index.ts index 4ae1365..e5cf897 100644 --- a/src/client/services/CalculationService/index.ts +++ b/src/client/services/CalculationService/index.ts @@ -2,24 +2,9 @@ import axios from 'axios'; import { getServerUrl } from 'client/common/urls'; import { CORE_PROXY_URL } from 'core/constants/urls'; import { IPreparedData } from 'core/types/Calculation/Requests'; -import { - IGetCalculationResponse, - IGetUserResponse, -} from 'core/types/Calculation/Responses'; +import { IGetCalculationResponse } from 'core/types/Calculation/Responses'; export default class { - static getUser = (): Promise => - new Promise((resolve, reject) => { - axios - .get('/api/users/getUser') - .then(res => { - resolve(res.data); - }) - .catch(err => { - reject(err); - }); - }); - static calculate = ( preparedData: IPreparedData, ): Promise => diff --git a/src/client/stores/CalculationStore/Effects/actions/createKP.js b/src/client/stores/CalculationStore/Effects/actions/createKP.js index 24b6dea..6171290 100644 --- a/src/client/stores/CalculationStore/Effects/actions/createKP.js +++ b/src/client/stores/CalculationStore/Effects/actions/createKP.js @@ -30,7 +30,7 @@ export default async () => { preparedPayments, } = calculationRes; - const domainName = (await getUser()).FullName || ''; + const { domainname } = getUser(); // if (process.env.NODE_ENV === 'development') { console.log('domainName', domainName); console.log('values', values); @@ -41,7 +41,7 @@ export default async () => { // } CrmService.createKp({ - domainName, + domainName: domainname, calculation: { insurances, preparedValues, diff --git a/src/client/tools/user.ts b/src/client/tools/user.ts index 7856823..1dd479d 100644 --- a/src/client/tools/user.ts +++ b/src/client/tools/user.ts @@ -1,26 +1,23 @@ import { User } from 'core/types/user'; import Cookies from 'js-cookie'; -function getUserObj(user: User) { - return { - ...user, - fullname: `${user.domainname}\\${user.username}`, - }; -} - export const getUser = (): User => { - const { username, domainname } = Cookies.get(); + let { username, domain } = Cookies.get(); if (process.env.NODE_ENV === 'development') { - if (!username || !domainname) { - const username = prompt('Enter username'); - const domainname = prompt('Enter domainname'); - if (username && domainname) { + if (!username || !domain) { + username = prompt('Enter username'); + domain = prompt('Enter domain'); + if (username && domain) { Cookies.set('username', username); - Cookies.set('domainname', domainname); + Cookies.set('domain', domain); } } } - const user: User = getUserObj({ username, domainname }); + const user: User = { + username, + domain, + domainname: `${domain}\\${username}`, + }; return user; }; diff --git a/src/core/constants/domain.js b/src/core/constants/domain.js deleted file mode 100644 index 34fa00f..0000000 --- a/src/core/constants/domain.js +++ /dev/null @@ -1,2 +0,0 @@ -export const domainName = 'EVOLEASING'; -export const LDAP_URL = 'ldap://evoleasing.ru'; diff --git a/src/core/types/Calculation/Responses.ts b/src/core/types/Calculation/Responses.ts index a64095e..b6d3d24 100644 --- a/src/core/types/Calculation/Responses.ts +++ b/src/core/types/Calculation/Responses.ts @@ -1,7 +1,6 @@ -import { User } from 'core/types/user'; import { TCRMEntity } from '../Entities/crmEntities'; import { TEntities } from '../Entities/crmEntityNames'; -import { IColumn, PostValues, ColumnsNames } from './Core'; +import { ColumnsNames, IColumn, PostValues } from './Core'; export interface IGetCRMEntitiesResponse { entities: TEntities; @@ -11,7 +10,3 @@ export interface IGetCalculationResponse { columns: { [column in ColumnsNames]?: IColumn }; postValues: PostValues; } - -export interface IGetUserResponse { - user: User; -} diff --git a/src/core/types/user.ts b/src/core/types/user.ts index 951d0f6..83c54a9 100644 --- a/src/core/types/user.ts +++ b/src/core/types/user.ts @@ -1,5 +1,5 @@ export type User = { - domainname?: string; + domain?: string; username?: string; - fullname?: string; + domainname?: string; }; diff --git a/src/server/controllers/UsersController.ts b/src/server/controllers/UsersController.ts deleted file mode 100644 index bc6ab2e..0000000 --- a/src/server/controllers/UsersController.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Request, Response } from 'express'; - -class UsersController { - static getUser = async (req: Request, res: Response): Promise => { - res.send({ - //@ts-ignore - user: req.ntlm, - }); - }; -} - -export default UsersController; diff --git a/src/server/entities/index.ts b/src/server/entities/index.ts deleted file mode 100644 index d6d1738..0000000 --- a/src/server/entities/index.ts +++ /dev/null @@ -1 +0,0 @@ -export default []; diff --git a/src/server/index.ts b/src/server/index.ts index d78ab5b..5dd4e35 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -1,57 +1,18 @@ -import bodyParser from 'body-parser'; -import compression from 'compression'; import cors from 'cors'; import express from 'express'; -import ntlm from 'express-ntlm'; -import helmet from 'helmet'; -import morgan from 'morgan'; -import path from 'path'; -import 'reflect-metadata'; import { SERVER_PORT } from './../core/constants/urls'; -import { domainName, LDAP_URL } from './../core/constants/domain'; import routes from './routes'; -const isDevelopmentMode = process.env.NODE_ENV === 'development'; - const app = express(); -/** AUTHENTICATION */ -if (!isDevelopmentMode) - app.use( - ntlm({ - domain: domainName, - domaincontroller: LDAP_URL, - }), - ); -/** AUTHENTICATION */ - /**EXTENTIONS */ -app.use(cors({ origin: isDevelopmentMode && '*' })); -app.use(helmet({ contentSecurityPolicy: { reportOnly: true } })); -app.use(bodyParser.json()); -app.use( - bodyParser.urlencoded({ - extended: true, - }), -); -app.use(compression()); -app.use(morgan(isDevelopmentMode ? 'dev' : 'tiny')); +app.use(cors({ origin: process.env.NODE_ENV === 'development' && '*' })); /**EXTENTIONS */ /**ROUTES */ app.use('/', routes); /**ROUTES */ -/**CLIENT */ -if (!isDevelopmentMode) { - const root_dir = path.resolve('build'); - app.use(express.static(root_dir)); - app.get('*', function (req, res) { - res.sendFile('index.html', { root: root_dir }); - }); -} -/**CLIENT */ - app.listen(SERVER_PORT, () => { console.log('ENV: ', process.env.NODE_ENV); console.log(`Server now listening on port: ${SERVER_PORT}`); diff --git a/src/server/routes/index.ts b/src/server/routes/index.ts index a6734d7..7b39006 100644 --- a/src/server/routes/index.ts +++ b/src/server/routes/index.ts @@ -1,10 +1,8 @@ import { Router } from 'express'; -import users from './users'; import proxy from './proxy'; const routes = Router(); -routes.use('/api/users', users); routes.use('/proxy', proxy); export default routes; diff --git a/src/server/routes/users.ts b/src/server/routes/users.ts deleted file mode 100644 index 00d6576..0000000 --- a/src/server/routes/users.ts +++ /dev/null @@ -1,8 +0,0 @@ -import UsersController from "../controllers/UsersController"; -import { Router } from "express"; - -const router = Router(); - -router.get("/getUser", UsersController.getUser); - -export default router; diff --git a/webpack.config.server.js b/webpack.config.server.js index 9ce1617..61840c2 100644 --- a/webpack.config.server.js +++ b/webpack.config.server.js @@ -1,6 +1,5 @@ const path = require('path'); const nodeExternals = require('webpack-node-externals'); -const dotenv = require('dotenv-webpack'); module.exports = { mode: process.env.NODE_ENV || 'development', @@ -37,5 +36,4 @@ module.exports = { }, ], }, - plugins: [new dotenv()], };