Skip to content

Commit

Permalink
Merge pull request #44 from NSWC-Crane/CHRIS_DEV
Browse files Browse the repository at this point in the history
BIG UPDATE. Reference pull request for full details.
  • Loading branch information
crodriguez6497 authored Mar 8, 2024
2 parents b3933a1 + 92b6169 commit d9c0ac6
Show file tree
Hide file tree
Showing 22 changed files with 1,544 additions and 152 deletions.
28 changes: 23 additions & 5 deletions Api/Controllers/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,34 @@ module.exports.getCollection = async function getCollection(req, res, next){
res.status(201).json(getCollection)
}

module.exports.getCollectionPoamStats = async function getCollectionPoamStats(req, res, next){
//let collectionId = req.params.collectionId
//console.log(userName)
// console.log("getCollectionPoamStats")
module.exports.getCollectionPoamStatus = async function getCollectionPoamStatus(req, res, next){

var getCollection = await collectionService.getCollectionPoamStats(req, res, next)
var getCollection = await collectionService.getCollectionPoamStatus(req, res, next)

res.status(201).json(getCollection)
}

module.exports.getCollectionPoamLabel = async function getCollectionPoamLabel(req, res, next){

var getCollection = await collectionService.getCollectionPoamLabel(req, res, next)

res.status(201).json(getCollection)
}

module.exports.getCollectionPoamSeverity = async function getCollectionPoamSeverity(req, res, next) {

var getCollection = await collectionService.getCollectionPoamSeverity(req, res, next)

res.status(201).json(getCollection)
}

module.exports.getCollectionPoamEstimatedCompletion = async function getCollectionPoamEstimatedCompletion(req, res, next) {

var getCollection = await collectionService.getCollectionPoamEstimatedCompletion(req, res, next)

res.status(201).json(getCollection)
}

module.exports.getCollections = async function getCollections(req, res, next){


Expand Down
54 changes: 54 additions & 0 deletions Api/Controllers/PoamLabel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
!#######################################################################
! C-PATTM SOFTWARE
! CRANE C-PATTM plan of action and milestones software. Use is governed by the Open Source Academic Research License Agreement contained in the file
! crane_C_PAT.1_license.txt, which is part of this software package. BY
! USING OR MODIFYING THIS SOFTWARE, YOU ARE AGREEING TO THE TERMS AND
! CONDITIONS OF THE LICENSE.
!########################################################################
*/

const poamLabelService = require('../Services/mysql/poamLabelService')

module.exports.getPoamLabels = async function getPoamLabels(req, res, next){
// res.status(201).json({message: "getPoamLabels Method called successfully"})
var poamLabels = await poamLabelService.getPoamLabels(req,res,next);
res.status(201).json(poamLabels)
}

module.exports.getPoamLabelByPoam = async function getPoamLabelByPoam(req, res, next){
// res.status(201).json({message: "getAsseLabelByPoam Method called successfully"});
var poamLabels = await poamLabelService.getPoamLabelsByPoam(req,res,next);
res.status(201).json(poamLabels)
}

module.exports.getPoamLabelByLabel = async function getPoamLabelByLabel(req, res, next){
//res.status(201).json({message: "getAsseLabelByLabel Method called successfully"});
var poamLabels = await poamLabelService.getPoamLabelsByLabel(req,res,next);
res.status(201).json(poamLabels)
}

module.exports.getPoamLabel = async function getPoamLabel(req, res, next){
// res.status(201).json({message: "getAsseLabel Method called successfully"});
var poamLabel = await poamLabelService.getPoamLabel(req,res,next);
res.status(201).json(poamLabel)
}

module.exports.postPoamLabel = async function postPoamLabel(req, res, next){
// res.status(201).json({message: "post:PoamLabel Method called successfully"});
var poamLabel = await poamLabelService.postPoamLabel(req,res,next);
res.status(201).json(poamLabel)
}

module.exports.putPoamLabel = async function putPoamLabel(req, res, next){
res.status(201).json({message: "putPoamLabel Method called successfully, There is only a unique index on poam and label id's, nothing to update!!!"});
// var poamLabel = await poamLabelService.putPoam(req,res,next);
// res.status(201).json(poamLabel)
}

module.exports.deletePoamLabel= async function deletePoamLabel(req, res, next){
//res.status(201).json({message: "deletePoamLabel Method called successfully"});
var poamLabel = await poamLabelService.deletePoamLabel(req,res,next);
res.status(201).json(poamLabel)
}

8 changes: 0 additions & 8 deletions Api/Services/mysql/assetLabelService.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const dbUtils = require('./utils')
const mysql = require('mysql2')

exports.getAssetLabels = async function getAssetLabels(req, res, next) {
//console.log("getAssetLabels (Service) ...");

try {
let connection
Expand All @@ -23,10 +22,6 @@ exports.getAssetLabels = async function getAssetLabels(req, res, next) {
"INNER JOIN poamtracking.asset t2 ON t1.assetId = t2.assetId " +
"INNER JOIN poamtracking.label t3 ON t1.labelId = t3.labelId " +
"ORDER BY t3.labelName"
// SELECT t1.assetId, assetName, t1.labelId, labelName FROM assetlabels t1
// INNER JOIN asset t2 ON t1.assetId = t2.assetId
// INNER JOIN label t3 ON t1.labelId = t3.labelId
//console.log("getLabels sql: ", sql)

let [rowAssetLabels] = await connection.query(sql)
console.log("rowAssets: ", rowAssetLabels[0])
Expand All @@ -37,7 +32,6 @@ exports.getAssetLabels = async function getAssetLabels(req, res, next) {
var assetLabels = []

for (let counter = 0; counter < size; counter++) {
// console.log("Before setting permissions size: ", size, ", counter: ",counter);

assetLabels.push({
"assetId": rowAssetLabels[counter].assetId,
Expand Down Expand Up @@ -326,10 +320,8 @@ exports.deleteAssetLabel = async function deleteAssetLabel(req, res, next) {
connection = await dbUtils.pool.getConnection()
let sql = "DELETE FROM poamtracking.assetlabels WHERE assetId=" + req.params.assetId +
" AND labelId = " + req.params.labelId + ";"
//console.log("deleteLabel sql: ", sql)

await connection.query(sql)
// console.log("rowPermissions: ", rowPermissions[0])
await connection.release()

var assetLabel = []
Expand Down
123 changes: 112 additions & 11 deletions Api/Services/mysql/collectionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,39 +242,140 @@ exports.getCollection = async function getCollection(userName, collectionId, req

}

exports.getCollectionPoamStats = async function getCollectionPoamStats( req, res, next){

// console.log("collectionId: ", req.params.collectionId)
exports.getCollectionPoamStatus = async function getCollectionPoamStatus( req, res, next){

try{
let connection
connection = await dbUtils.pool.getConnection()
//if user is admin check, if so dump all collections
let sql = "SELECT status, COUNT(*) AS statusCount FROM poam WHERE collectionId = ? GROUP BY status;"
let [rows] = await connection.query(sql, [req.params.collectionId])
// console.log("rows: ", rows)
// let response = new collectionObj(row[0].collectionId, row[0].collectionName,row[0].description, row[0].created,row[0].grantCount,row[0].poamCount)

await connection.release()
var size = Object.keys(rows).length

var poamStats = []
var poamStatus = []

for (let counter = 0; counter < size; counter++) {
// console.log("Before setting permissions size: ", size, ", counter: ",counter);

poamStats.push({
poamStatus.push({
...rows[counter]
});
}

return {poamStats: poamStats} ;
return {poamStatus: poamStatus} ;
}
catch(error)
{
return {"null" : "Undefined collection"}
}
}

exports.getCollectionPoamLabel = async function getCollectionPoamLabel(req, res, next) {
let connection;
try {
connection = await dbUtils.pool.getConnection();
let sql = `
SELECT l.labelName, COUNT(pl.labelId) AS labelCount
FROM poamtracking.poamlabels pl
INNER JOIN poamtracking.poam p ON pl.poamId = p.poamId
INNER JOIN poamtracking.label l ON pl.labelId = l.labelId
WHERE p.collectionId = ?
GROUP BY l.labelName;
`;
let [rows] = await connection.query(sql, [req.params.collectionId]);

let poamLabel = rows.map(row => ({
label: row.labelName,
labelCount: row.labelCount
}));

return { poamLabel };
} catch (error) {
console.error("Error fetching POAM label counts: ", error);
throw new Error("Unable to fetch POAM label counts");
} finally {
if (connection) await connection.release();
}
}


exports.getCollectionPoamSeverity = async function getCollectionPoamSeverity(req, res, next) {

try {
let connection
connection = await dbUtils.pool.getConnection()
let sql = "SELECT rawSeverity, COUNT(*) AS severityCount FROM poam WHERE collectionId = ? GROUP BY rawSeverity;"
let [rows] = await connection.query(sql, [req.params.collectionId])

await connection.release()
var size = Object.keys(rows).length

var poamSeverity = []

for (let counter = 0; counter < size; counter++) {
poamSeverity.push({
severity: rows[counter].rawSeverity,
severityCount: rows[counter].severityCount
});
}

return { poamSeverity: poamSeverity };
}
catch (error) {
return { "null": "Undefined collection" }
}
}

exports.getCollectionPoamEstimatedCompletion = async function getCollectionPoamEstimatedCompletion(req, res, next) {
try {
let connection = await dbUtils.pool.getConnection();
let sql = `
SELECT
scheduledCompletionDate,
extensionTimeAllowed,
DATEDIFF(
DATE_ADD(scheduledCompletionDate, INTERVAL IFNULL(extensionTimeAllowed, 0) DAY),
CURDATE()
) AS daysUntilCompletion
FROM poam
WHERE collectionId = ?
`;

let [rows] = await connection.query(sql, [req.params.collectionId]);
await connection.release();

let buckets = {
"OVERDUE": 0,
"< 30 Days": 0,
"30-60 Days": 0,
"60-90 Days": 0,
"90-180 Days": 0,
"180-365 Days": 0,
"> 365 Days": 0,
};

rows.forEach(row => {
let days = row.daysUntilCompletion;
if (days <= 0) buckets["OVERDUE"]++;
else if (days <= 30) buckets["< 30 Days"]++;
else if (days <= 60) buckets["30-60 Days"]++;
else if (days <= 90) buckets["60-90 Days"]++;
else if (days <= 180) buckets["90-180 Days"]++;
else if (days <= 365) buckets["180-365 Days"]++;
else if (days > 365) buckets["> 365 Days"]++;
});

let poamEstimatedCompletion = Object.keys(buckets).map(key => ({
estimatedCompletion: key,
estimatedCompletionCount: buckets[key],
}));

return { poamEstimatedCompletion };
} catch (error) {
console.error("Error fetching POAM estimated completion data:", error);
return { "error": "Failed to fetch POAM estimated completion data" };
}
}

exports.postCollection = async function postCollection(req, res, next) {
// console.log("inSide postCollection req.body: ", req.body)
let connection;
Expand Down
Loading

0 comments on commit d9c0ac6

Please sign in to comment.