Skip to content

Commit

Permalink
Merge pull request #24 from saranshbalyan-1234/3
Browse files Browse the repository at this point in the history
3
  • Loading branch information
saranshbalyan-1234 authored Apr 13, 2024
2 parents 3f50f19 + e96089c commit 1814448
Show file tree
Hide file tree
Showing 115 changed files with 2,461 additions and 2,199 deletions.
44 changes: 38 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
},
"extends": [
"standard",
"eslint:recommended",
"eslint:all",
"plugin:promise/recommended",
"plugin:eqeqeq-fix/recommended",
"plugin:react/recommended",
"plugin:react/all",
"plugin:react-hooks/recommended"
],
"parserOptions": {
Expand All @@ -25,13 +25,45 @@
"indent": [2],
"quotes": [2, "single"],
"linebreak-style": [2, "unix"],
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "error"
// "no-console":"error"
"no-console":"off",
"no-ternary":"off",
"radix": "off",
"max-statements":"off",
"max-lines-per-function":"off",
"sort-keys-fix/sort-keys-fix": "warn",
"id-length":"off",
"no-magic-numbers":"off",
"require-unicode-regexp":"off",
"max-params":"off",
"prefer-destructuring":"off",
"no-multi-assign":"off",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"consistent-return":"off",
"max-lines":"off",
"no-plusplus":"off",
"no-continue":"off",
"no-await-in-loop":"off",
"sort-imports": ["error", {
"ignoreCase": true,
"ignoreDeclarationSort": true,
"ignoreMemberSort": true,
"memberSyntaxSortOrder": ["multiple", "all","single","none"]
}]
},
"settings": {
"react": {
"version": "detect"
}
}
},
"plugins":[
"react",
"promise",
"react",
"react-hooks",
"eqeqeq-fix",
"sort-keys-fix",
"unused-imports",
"simple-import-sort"
]
}
32 changes: 15 additions & 17 deletions Controllers/constantController.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
import getError from '#utils/error.js';
import { permissionList } from '#constants/permission.js';
import { actionEvents } from '#constants/actionEvents.js';
import { permissionList } from '#constants/permission.js';
import getError from '#utils/error.js';

const getAllPermission = async (req, res) => {
/* #swagger.tags = ["Constant"]
#swagger.security = [{"apiKeyAuth": []}]
*/
const getAllPermission = (req, res) => {
/*
* #swagger.tags = ["Constant"]
* #swagger.security = [{"apiKeyAuth": []}]
*/
try {
const data = permissionList.sort((a, b) => {
return a.name > b.name ? 1 : -1;
});
const data = permissionList.sort((a, b) => a.name > b.name ? 1 : -1);
return res.status(200).json(data);
} catch (error) {
getError(error, res);
}
};

const getAllActionEvent = async (req, res) => {
/* #swagger.tags = ["Constant"]
#swagger.security = [{"apiKeyAuth": []}]
*/
const getAllActionEvent = (req, res) => {
/*
* #swagger.tags = ["Constant"]
* #swagger.security = [{"apiKeyAuth": []}]
*/
try {
const data = actionEvents.sort((a, b) => {
return a.name > b.name ? 1 : -1;
});
const data = actionEvents.sort((a, b) => a.name > b.name ? 1 : -1);
return res.status(200).json(data);
} catch (error) {
getError(error, res);
}
};

export { getAllPermission, getAllActionEvent };
export { getAllActionEvent, getAllPermission };
73 changes: 35 additions & 38 deletions Controllers/dashboardController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Op, Sequelize } from 'sequelize';

import db from '#utils/dataBaseConnection.js';
import getError from '#utils/error.js';
import { Sequelize, Op } from 'sequelize';
const User = db.users;
const TestCase = db.testCases;
const ReusableProcess = db.reusableProcess;
Expand All @@ -9,20 +10,17 @@ const UserProject = db.userProjects;
const Project = db.projects;
const ExecutionHistory = db.executionHistory;
export const dashboard = async (req, res) => {
/* #swagger.tags = ["Dashboard"]
#swagger.security = [{"apiKeyAuth": []}]
*/
/*
* #swagger.tags = ["Dashboard"]
* #swagger.security = [{"apiKeyAuth": []}]
*/
try {
const user = await User.schema(req.database).findAll();

// Users Start
const Active = user.filter((el) => {
return el.active === true;
}).length;
const Active = user.filter((el) => el.active === true).length;

const Unverified = user.filter((el) => {
return el.verifiedAt === null;
}).length;
const Unverified = user.filter((el) => el.verifiedAt === null).length;
const Inactive = user.length - Active - Unverified;

// Users End
Expand All @@ -35,19 +33,20 @@ export const dashboard = async (req, res) => {
where: { executedByUser: req.user.id }
});
return res.status(200).json({
executionHistoryCount,
project: userProject,
user: { total: user.length, Active, Inactive, Unverified },
executionHistoryCount
user: { Active, Inactive, Unverified, total: user.length }
});
} catch (error) {
getError(error, res);
}
};

export const createdReport = async (req, res) => {
/* #swagger.tags = ["Dashboard"]
#swagger.security = [{"apiKeyAuth": []}]
*/
/*
* #swagger.tags = ["Dashboard"]
* #swagger.security = [{"apiKeyAuth": []}]
*/
try {
const reusableProcess = await ReusableProcess.schema(req.database).count({
where: { createdByUser: req.body.userId }
Expand All @@ -64,48 +63,46 @@ export const createdReport = async (req, res) => {
});

return res.status(200).json({
Object: object,
Projects: projects,
TestCase: testCase,
Reusable: reusableProcess,
Object: object
TestCase: testCase
});
} catch (error) {
getError(error, res);
}
};

export const executionReport = async (req, res) => {
/* #swagger.tags = ["Dashboard"]
#swagger.security = [{"apiKeyAuth": []}]
*/
/*
* #swagger.tags = ["Dashboard"]
* #swagger.security = [{"apiKeyAuth": []}]
*/
try {
const totalHistory = await ExecutionHistory.schema(req.database).findAll({
where: req.body
});

const incompleteHistory = totalHistory.filter((el) => {
return el.dataValues.finishedAt === null;
});
const incompleteHistory = totalHistory.filter((el) => el.dataValues.finishedAt === null);

const passedHistory = totalHistory.filter((el) => {
return el.dataValues.result === true;
});
const passedHistory = totalHistory.filter((el) => el.dataValues.result === true);
const failedHistory = totalHistory.length - passedHistory.length - incompleteHistory.length;
return res.status(200).json({
Total: totalHistory.length,
Failed: failedHistory,
Incomplete: incompleteHistory.length,
Passed: passedHistory.length,
Failed: failedHistory
Total: totalHistory.length
});
} catch (error) {
getError(error, res);
}
};

export const detailedExecutionReport = async (req, res) => {
/* #swagger.tags = ["Dashboard"]
#swagger.security = [{"apiKeyAuth": []}]
*/
/*
* #swagger.tags = ["Dashboard"]
* #swagger.security = [{"apiKeyAuth": []}]
*/
try {
const startDate = new Date(req.body.startDate);
const endDate = new Date(req.body.endDate);
Expand All @@ -121,19 +118,19 @@ export const detailedExecutionReport = async (req, res) => {
}

const passedHistory = await ExecutionHistory.schema(req.database).count({
where: { ...payload, result: true },
attributes: [[Sequelize.fn('DATE', Sequelize.col('createdAt')), 'Date']],
group: [Sequelize.fn('DATE', Sequelize.col('createdAt')), 'Date']
group: [Sequelize.fn('DATE', Sequelize.col('createdAt')), 'Date'],
where: { ...payload, result: true }
});
const failedHistory = await ExecutionHistory.schema(req.database).count({
where: { ...payload, result: false },
attributes: [[Sequelize.fn('DATE', Sequelize.col('createdAt')), 'Date']],
group: [Sequelize.fn('DATE', Sequelize.col('createdAt')), 'Date']
group: [Sequelize.fn('DATE', Sequelize.col('createdAt')), 'Date'],
where: { ...payload, result: false }
});
const incompleteHistory = await ExecutionHistory.schema(req.database).count({
where: { ...payload, result: null },
attributes: [[Sequelize.fn('DATE', Sequelize.col('createdAt')), 'Date']],
group: [Sequelize.fn('DATE', Sequelize.col('createdAt')), 'Date']
group: [Sequelize.fn('DATE', Sequelize.col('createdAt')), 'Date'],
where: { ...payload, result: null }
});
const totalCount = await ExecutionHistory.schema(req.database).count({
where: { executedByUser: req.body.executedByUser || req.user.id }
Expand Down Expand Up @@ -177,7 +174,7 @@ export const detailedExecutionReport = async (req, res) => {
value: (el[1].Incomplete || 0) + (el[1].Failed || 0) + (el[1].Passed || 0)
});
});
return res.status(200).json({ totalCount, data: finalData });
return res.status(200).json({ data: finalData, totalCount });
} catch (error) {
getError(error, res);
}
Expand Down
25 changes: 15 additions & 10 deletions Encryption/Controller/aes.controller.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
import getError from '#utils/error.js';
import { encryptWithAES, decryptWithAES } from '../Service/aes.service.js';

const encryptData = async (req, res) => {
/* #swagger.tags = ["Encryption"]
#swagger.security = [{"apiKeyAuth": []}] */
import { decryptWithAES, encryptWithAES } from '../Service/aes.service.js';

const encryptData = (req, res) => {
/*
* #swagger.tags = ["Encryption"]
* #swagger.security = [{"apiKeyAuth": []}]
*/
try {
const data = req.body.data;
const { data } = req.body;
const encrypted = encryptWithAES(data);
return res.status(200).json(encrypted);
} catch (error) {
getError(error, res);
}
};

const decryptData = async (req, res) => {
/* #swagger.tags = ["Encryption"]
#swagger.security = [{"apiKeyAuth": []}] */
const decryptData = (req, res) => {
/*
* #swagger.tags = ["Encryption"]
* #swagger.security = [{"apiKeyAuth": []}]
*/
try {
const encrypted = req.body.encrypted;
const { encrypted } = req.body;
const decrypted = decryptWithAES(encrypted);
return res.status(200).json(decrypted);
} catch (error) {
getError(error, res);
}
};

export { encryptData, decryptData };
export { decryptData, encryptData };
3 changes: 2 additions & 1 deletion Encryption/Routes/aes.routes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import express from 'express';
import { encryptData, decryptData } from '../Controller/aes.controller.js';

import { decryptData, encryptData } from '../Controller/aes.controller.js';
const Router = express.Router();

Router.post('/decrypt', decryptData);
Expand Down
27 changes: 16 additions & 11 deletions Encryption/Service/aes.service.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import getError from '#utils/error.js';
import crypto from 'crypto';

import getError from '#utils/error.js';

const secretKey = 'saranshbalyan123saranshbalyan123';
const initializationVector = 'c3e84932d4eca8d8860e087613ca4313';

// Function to encrypt using AES CBC
function encryptWithAES (text, key = secretKey, iv = initializationVector) {
const encryptWithAES = (text, key = secretKey, iv = initializationVector) => {
try {
const cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(key), Buffer.from(iv, 'hex'));
let encrypted = cipher.update(JSON.stringify(text), 'utf-8', 'hex');
Expand All @@ -14,10 +15,10 @@ function encryptWithAES (text, key = secretKey, iv = initializationVector) {
} catch (e) {
getError(e);
}
}
};

// Function to decrypt using AES CBC
function decryptWithAES (encryptedText, key = secretKey, iv = initializationVector) {
const decryptWithAES = (encryptedText, key = secretKey, iv = initializationVector) => {
try {
const decipher = crypto.createDecipheriv('aes-256-cbc', Buffer.from(key), Buffer.from(iv, 'hex'));
let decrypted = decipher.update(encryptedText, 'hex', 'utf-8');
Expand All @@ -26,13 +27,17 @@ function decryptWithAES (encryptedText, key = secretKey, iv = initializationVect
} catch (e) {
getError(e);
}
}
};

// const plaintext = "Hello, AES CBC encryption!";
// const encryptedText = encryptWithAES(plaintext, secretKey,initializationVector );
// console.log("Encrypted:",encryptedText);
/*
* Const plaintext = "Hello, AES CBC encryption!";
* const encryptedText = encryptWithAES(plaintext, secretKey,initializationVector );
* console.log("Encrypted:",encryptedText);
*/

// const decryptedText = decryptWithAES("8600ce43592fecadc5b8edba44f0e81a", secretKey, initializationVector);
// console.log("Decrypted:", decryptedText);
/*
* Const decryptedText = decryptWithAES("8600ce43592fecadc5b8edba44f0e81a", secretKey, initializationVector);
* console.log("Decrypted:", decryptedText);
*/

export { encryptWithAES, decryptWithAES };
export { decryptWithAES, encryptWithAES };
Loading

0 comments on commit 1814448

Please sign in to comment.