Skip to content

Commit

Permalink
Merge pull request #84 from NSWC-Crane/CHRIS_DEV
Browse files Browse the repository at this point in the history
Reference pull request for full details.
  • Loading branch information
crodriguez6497 authored Jul 9, 2024
2 parents 8beda34 + fc518ff commit a99c62a
Show file tree
Hide file tree
Showing 51 changed files with 277 additions and 213 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG BASE_IMAGE="node:lts-alpine"
FROM ${BASE_IMAGE} as build
FROM ${BASE_IMAGE} AS build
ARG COMMIT_BRANCH="unspecified"
ARG COMMIT_SHA="unspecified"
ARG COMMIT_TAG="unspecified"
Expand Down
11 changes: 6 additions & 5 deletions api/Services/assetLabelService.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ exports.getAssetLabels = async function getAssetLabels(req, res, next) {
ORDER BY t3.labelName
`;
let [rowAssetLabels] = await connection.query(sql, [req.params.collectionId]);
var assetLabels = rowAssetLabels.map((row) => ({
const assetLabels = rowAssetLabels.map((row) => ({
"assetId": row.assetId,
"assetName": row.assetName,
"labelId": row.labelId,
Expand Down Expand Up @@ -76,7 +76,7 @@ exports.getAssetLabelsByAsset = async function getAssetLabelsByAsset(req, res, n
ORDER BY t3.labelName
`;
let [rowAssetLabels] = await connection.query(sql, [req.params.assetId]);
var assetLabels = rowAssetLabels.map((row) => ({
const assetLabels = rowAssetLabels.map((row) => ({
"assetId": row.assetId,
"assetName": row.assetName,
"labelId": row.labelId,
Expand Down Expand Up @@ -110,7 +110,7 @@ exports.getAssetLabelsByLabel = async function getAssetLabelsByLabel(req, res, n
ORDER BY t3.labelName
`;
let [rowAssetLabels] = await connection.query(sql, [req.params.labelId]);
var assetLabels = rowAssetLabels.map((row) => ({
const assetLabels = rowAssetLabels.map((row) => ({
"assetId": row.assetId,
"assetName": row.assetName,
"labelId": row.labelId,
Expand Down Expand Up @@ -150,7 +150,8 @@ exports.getAssetLabel = async function getAssetLabel(req, res, next) {
WHERE t1.assetId = ? AND t1.labelId = ?
ORDER BY t3.labelName
`;
var assetLabel = rowAssetLabel.length > 0 ? [rowAssetLabel[0]] : [];
let [rowAssetLabel] = await connection.query(sql, [req.params.assetId, req.params.labelId]);
const assetLabel = rowAssetLabel.length > 0 ? [rowAssetLabel[0]] : [];
return assetLabel.assetLabel;
});
} catch (error) {
Expand Down Expand Up @@ -199,7 +200,7 @@ exports.postAssetLabel = async function postAssetLabel(req, res, next) {
`;
let [rowAssetLabel] = await connection.query(sql, [req.body.assetId, req.body.labelId]);

var assetLabel = rowAssetLabel.length > 0 ? rowAssetLabel[0] : null;
const assetLabel = rowAssetLabel.length > 0 ? rowAssetLabel[0] : null;
return (assetLabel);
});
} catch (error) {
Expand Down
10 changes: 5 additions & 5 deletions api/Services/assetService.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ exports.getAssets = async function getAssets(req, res, next) {
return await withConnection(async (connection) => {
let sql = "SELECT * FROM cpat.asset ORDER BY assetName;"
let [rowAssets] = await connection.query(sql);
var assets = rowAssets.map(row => ({
const assets = rowAssets.map(row => ({
"assetId": row.assetId,
"assetName": row.assetName,
"description": row.description,
Expand Down Expand Up @@ -56,7 +56,7 @@ exports.getAssetsByCollection = async function getAssetsByCollection(req, res, n
return await withConnection(async (connection) => {
const sql = "SELECT * FROM cpat.asset WHERE collectionId = ? ORDER BY assetName;";
let [rowAssets] = await connection.query(sql, [req.params.collectionId]);
var assets = rowAssets.map(row => ({
const assets = rowAssets.map(row => ({
"assetId": row.assetId,
"assetName": row.assetName,
"description": row.description,
Expand Down Expand Up @@ -279,12 +279,12 @@ exports.deleteAsset = async function deleteAsset(req, res, next) {

exports.deleteAssetsByPoamId = async function deleteAssetsByPoamId(req, res, next) {
if (!req.params.poamId) {
throw {
return next({
status: 400,
errors: {
poamId: 'is required',
},
};
}
});
}
try {
await withConnection(async (connection) => {
Expand Down
14 changes: 7 additions & 7 deletions api/Services/collectionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ exports.getCollections = async function getCollections(userNameInput, req, res,
return await withConnection(async (connection) => {
let sql = "SELECT collectionId, collectionName FROM cpat.collection;"
let [row] = await connection.query(sql)
var size = Object.keys(row).length
const size = Object.keys(row).length

var user = {
const user = {
collections: []
}

Expand Down Expand Up @@ -59,13 +59,13 @@ exports.getCollections = async function getCollections(userNameInput, req, res,
isAdmin = row[0].isAdmin;
userName = row[0].userName;

var user = {
const user = {
collections: []
}
if (isAdmin == 1) {
let sql2 = "SELECT * FROM collection;"
let [row2] = await connection.query(sql2)
var size = Object.keys(row2).length
const size = Object.keys(row2).length

for (let counter = 0; counter < size; counter++) {
user.collections.push({
Expand All @@ -77,8 +77,8 @@ exports.getCollections = async function getCollections(userNameInput, req, res,
} else {
let sql = "SELECT * FROM collectionpermissions WHERE userId = ?";
let [row2] = await connection.query(sql, [userId])
var numberOfCollections = Object.keys(row2).length
var nonAdminCollections = {
const numberOfCollections = Object.keys(row2).length
const nonAdminCollections = {
collections: []
}
for (let counter = 0; counter < numberOfCollections; counter++) {
Expand Down Expand Up @@ -128,7 +128,7 @@ exports.postCollection = async function postCollection(req, res, next) {
let sql = "SELECT * FROM cpat.collection WHERE collectionId = LAST_INSERT_ID();"
let [rowCollection] = await connection.query(sql)

var collection = rowCollection[0]
const collection = rowCollection[0]
return (collection)
});
} catch (error) {
Expand Down
17 changes: 6 additions & 11 deletions api/Services/importService.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,17 @@ exports.processPoamFile = async function processPoamFile(file, userId) {
if (!file) {
throw new Error("Please upload an Excel file!");
}

if (!userId) {
throw new Error("userId is required");
}

try {
const workbook = new ExcelJS.Workbook();
await workbook.xlsx.load(file.buffer);
if (workbook.worksheets.length === 0) {
throw new Error('No worksheets found in the workbook');
}
const worksheet = workbook.worksheets[0];
await processPoamWorksheet(worksheet, userId);
} catch (error) {
throw error;
const workbook = new ExcelJS.Workbook();
await workbook.xlsx.load(file.buffer);
if (workbook.worksheets.length === 0) {
throw new Error('No worksheets found in the workbook');
}
const worksheet = workbook.worksheets[0];
await processPoamWorksheet(worksheet, userId);
};

async function processPoamWorksheet(worksheet, userId) {
Expand Down
4 changes: 2 additions & 2 deletions api/Services/labelService.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ exports.getLabels = async function getLabels(req, res, next) {
let sql = "SELECT * FROM cpat.label WHERE collectionId = ? ORDER BY labelName;";
let [rowLabels] = await connection.query(sql, [req.params.collectionId]);

var labels = rowLabels.map(row => ({
const labels = rowLabels.map(row => ({
labelId: row.labelId,
labelName: row.labelName,
description: row.description,
Expand Down Expand Up @@ -73,7 +73,7 @@ exports.getLabel = async function getLabel(req, res, next) {
let sql = "SELECT * FROM cpat.label WHERE labelId = ? AND collectionId = ?";
let [rowLabel] = await connection.query(sql, [req.params.labelId, req.params.collectionId]);

var label = rowLabel.length > 0 ? [rowLabel[0]] : [];
const label = rowLabel.length > 0 ? [rowLabel[0]] : [];

return { label };
});
Expand Down
8 changes: 4 additions & 4 deletions api/Services/metricsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ exports.getCollectionPoamStatus = async function getCollectionPoamStatus(req, re
let sql = "SELECT status, COUNT(*) AS statusCount FROM poam WHERE collectionId = ? GROUP BY status;"
let [rows] = await connection.query(sql, [req.params.collectionId])

var size = Object.keys(rows).length
const size = Object.keys(rows).length

var poamStatus = []
const poamStatus = []

for (let counter = 0; counter < size; counter++) {
poamStatus.push({
Expand Down Expand Up @@ -103,9 +103,9 @@ exports.getCollectionPoamSeverity = async function getCollectionPoamSeverity(req
let sql = "SELECT rawSeverity, COUNT(*) AS severityCount FROM poam WHERE collectionId = ? GROUP BY rawSeverity;"
let [rows] = await connection.query(sql, [req.params.collectionId])

var size = Object.keys(rows).length
const size = Object.keys(rows).length

var poamSeverity = []
const poamSeverity = []

for (let counter = 0; counter < size; counter++) {
poamSeverity.push({
Expand Down
12 changes: 6 additions & 6 deletions api/Services/poamApproverService.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ exports.getPoamApprovers = async function getPoamApprovers(req, res, next) {
WHERE poamId = ?;
`;
let [rows] = await connection.query(sql, [req.params.poamId]);
var poamApprovers = rows.map(row => ({
const poamApprovers = rows.map(row => ({
...row,
approvedDate: row.approvedDate ? row.approvedDate.toISOString() : null,
}));
Expand Down Expand Up @@ -73,7 +73,7 @@ exports.getPoamApproversByCollection = async function getPoamApproversByCollecti
WHERE T3.collectionId = ?
`;
let [rows] = await connection.query(sql, [req.params.collectionId]);
var poamApprovers = rows.map(row => ({
const poamApprovers = rows.map(row => ({
...row,
approvedDate: row.approvedDate ? row.approvedDate.toISOString() : null,
}));
Expand Down Expand Up @@ -112,7 +112,7 @@ exports.getPoamApproversByCollectionUser = async function getPoamApproversByColl
WHERE T3.collectionId = ? AND T1.userId = ?
`;
let [rows] = await connection.query(sql, [req.params.collectionId, req.params.userId]);
var poamApprovers = rows.map(row => ({
const poamApprovers = rows.map(row => ({
...row,
approvedDate: row.approvedDate ? row.approvedDate.toISOString() : null,
}));
Expand Down Expand Up @@ -143,7 +143,7 @@ exports.getPoamApproversByUserId = async function getPoamApproversByUserId(req,
WHERE T1.userId = ?
`;
let [rows] = await connection.query(sql, [req.params.userId]);
var poamApprovers = rows.map(row => ({
const poamApprovers = rows.map(row => ({
...row,
approvedDate: row.approvedDate ? row.approvedDate.toISOString() : null,
}));
Expand Down Expand Up @@ -205,7 +205,7 @@ exports.postPoamApprover = async function postPoamApprover(req, res, next) {
}
let sql = "SELECT * FROM cpat.poamapprovers WHERE poamId = ? AND userId = ?";
let [row] = await connection.query(sql, [req.body.poamId, req.body.userId]);
var poamApprover = row.map(row => ({
const poamApprover = row.map(row => ({
...row,
approvedDate: row.approvedDate ? row.approvedDate.toISOString() : null,
}))[0];
Expand Down Expand Up @@ -395,7 +395,7 @@ exports.putPoamApprover = async function putPoamApprover(req, res, next) {

let sql = "SELECT * FROM cpat.poamapprovers WHERE poamId = ? AND userId = ?";
let [row] = await connection.query(sql, [req.body.poamId, req.body.userId]);
var poamApprover = row.map(row => ({
const poamApprover = row.map(row => ({
...row,
approvedDate: row.approvedDate ? row.approvedDate.toISOString() : null,
}))[0];
Expand Down
10 changes: 5 additions & 5 deletions api/Services/poamAssetService.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ exports.getPoamAssets = async function getPoamAssets(req, res, next) {
INNER JOIN cpat.asset t2 ON t1.assetId = t2.assetId
`;
let [rowPoamAssets] = await connection.query(sql);
var poamAssets = rowPoamAssets.map(row => ({
const poamAssets = rowPoamAssets.map(row => ({
assetId: row.assetId,
assetName: row.assetName,
poamId: row.poamId,
Expand Down Expand Up @@ -62,7 +62,7 @@ exports.getPoamAssetsByPoamId = async function getPoamAssetsByPoamId(req, res, n
WHERE t1.poamId = ?
`;
let [rowPoamAssets] = await connection.query(sql, [req.params.poamId]);
var poamAssets = rowPoamAssets.map(row => ({
const poamAssets = rowPoamAssets.map(row => ({
assetId: row.assetId,
assetName: row.assetName,
poamId: row.poamId,
Expand Down Expand Up @@ -114,7 +114,7 @@ exports.getPoamAssetsByAssetId = async function getPoamAssetsByAssetId(req, res,
WHERE t1.assetId = ?
`;
let [rowPoamAssets] = await connection.query(sql, [req.params.assetId]);
var poamAssets = rowPoamAssets.map(row => ({
const poamAssets = rowPoamAssets.map(row => ({
assetId: row.assetId,
assetName: row.assetName,
poamId: row.poamId,
Expand Down Expand Up @@ -156,7 +156,7 @@ exports.getAssetLabel = async function getAssetLabel(req, res, next) {
ORDER BY t3.labelName
`;
let [rowAssetLabel] = await connection.query(sql, [req.params.assetId, req.params.labelId]);
var assetLabel = rowAssetLabel.length > 0 ? [rowAssetLabel[0]] : [];
const assetLabel = rowAssetLabel.length > 0 ? [rowAssetLabel[0]] : [];
return { assetLabel };
});
} catch (error) {
Expand Down Expand Up @@ -186,7 +186,7 @@ exports.postPoamAsset = async function postPoamAsset(req, res, next) {
INNER JOIN cpat.asset t2 ON t1.assetId = t2.assetId
WHERE t1.poamId = ? AND t1.assetId = ?`;
let [rowPoamAsset] = await connection.query(sql, [req.body.poamId, req.body.assetId]);
var poamAsset = rowPoamAsset.length > 0 ? rowPoamAsset[0] : [];
const poamAsset = rowPoamAsset.length > 0 ? rowPoamAsset[0] : [];
if (req.body.poamLog[0].userId) {
let assetNameQuery = `SELECT assetName FROM cpat.asset WHERE assetId = ?`;
let [[assetNameResult]] = await connection.query(assetNameQuery, [req.body.assetId]);
Expand Down
10 changes: 5 additions & 5 deletions api/Services/poamAssigneeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ exports.getPoamAssignees = async function getPoamAssignees() {
ORDER BY t2.fullName
`;
let [rowPoamAssignees] = await connection.query(sql);
var poamAssignees = rowPoamAssignees.map(row => ({
const poamAssignees = rowPoamAssignees.map(row => ({
userId: row.userId,
fullName: row.fullName,
poamId: row.poamId,
Expand All @@ -57,7 +57,7 @@ exports.getPoamAssigneesByPoamId = async function getPoamAssigneesByPoamId(poamI
ORDER BY t2.fullName
`;
let [rowPoamAssignees] = await connection.query(sql, [poamId]);
var poamAssignees = rowPoamAssignees.map(row => ({
const poamAssignees = rowPoamAssignees.map(row => ({
userId: row.userId,
fullName: row.fullName,
poamId: row.poamId,
Expand All @@ -82,7 +82,7 @@ exports.getPoamAssigneesByUserId = async function getPoamAssigneesByUserId(req,
ORDER BY t2.fullName
`;
let [rowPoamAssignees] = await connection.query(sql, [req.params.userId]);
var poamAssignees = rowPoamAssignees.map(row => ({
const poamAssignees = rowPoamAssignees.map(row => ({
userId: row.userId,
fullName: row.fullName,
poamId: row.poamId,
Expand Down Expand Up @@ -110,13 +110,13 @@ exports.getPoamAssignee = async function getPoamAssignee(req, res, next) {
ORDER BY t2.fullName
`;
let [rowPoamAssignees] = await connection.query(sql, [req.params.userId, req.params.poamId]);
var poamAssignees = rowPoamAssignees.map(row => ({
const poamAssignees = rowPoamAssignees.map(row => ({
userId: row.userId,
fullName: row.fullName,
poamId: row.poamId,
poamStatus: row.status,
}));
var poamAssignee = poamAssignees.length > 0 ? [poamAssignees[0]] : [];
const poamAssignee = poamAssignees.length > 0 ? [poamAssignees[0]] : [];
return { poamAssignee };
});
};
Expand Down
6 changes: 3 additions & 3 deletions api/Services/poamExtensionMilestoneService.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ exports.getPoamExtensionMilestones = async function getPoamExtensionMilestones(p
return await withConnection(async (connection) => {
let sql = "SELECT * FROM cpat.poamExtensionMilestones WHERE poamId = ?;";
let [rows] = await connection.query(sql, [poamId]);
var poamExtensionMilestones = rows.map(row => ({ ...row }));
const poamExtensionMilestones = rows.map(row => ({ ...row }));
return { poamExtensionMilestones };
});
} catch (error) {
Expand Down Expand Up @@ -77,7 +77,7 @@ exports.postPoamExtensionMilestone = async function postPoamExtensionMilestone(p
let sql = "SELECT * FROM cpat.poamExtensionMilestones WHERE poamId = ?";
let [rows] = await connection.query(sql, [poamId]);

var poamExtensionMilestone = rows.map(row => ({ ...row }));
const poamExtensionMilestone = rows.map(row => ({ ...row }));

if (requestBody.poamLog && requestBody.poamLog.length > 0) {
let userId = requestBody.poamLog[0].userId;
Expand Down Expand Up @@ -132,7 +132,7 @@ exports.putPoamExtensionMilestone = async function putPoamExtensionMilestone(poa
sql_query = "SELECT * FROM cpat.poamExtensionMilestones WHERE poamId = ?;";
let [rows] = await connection.query(sql_query, [poamId]);

var poamExtensionMilestone = rows.map(row => ({ ...row }));
const poamExtensionMilestone = rows.map(row => ({ ...row }));

if (requestBody.poamLog && requestBody.poamLog.length > 0) {
let userId = requestBody.poamLog[0].userId;
Expand Down
Loading

0 comments on commit a99c62a

Please sign in to comment.