Skip to content

Commit

Permalink
Merge pull request #875 from Worktez/dev-angular
Browse files Browse the repository at this point in the history
Internal Release 7.6
  • Loading branch information
simran142002 authored Dec 27, 2022
2 parents 604bafe + cf3eb84 commit a6f9464
Show file tree
Hide file tree
Showing 35 changed files with 887 additions and 99 deletions.
12 changes: 6 additions & 6 deletions functions/model/performanceChart/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ const { db } = require("../application/lib");
/**
* Description
* @param {any} orgDomain
* @param {any} teamId
* @param {any} teamName
* @param {any} chartName
* @param {any} inputJson
* @return {any}
*/
exports.setOrganizationsChart = function(orgDomain, teamId, chartName, inputJson) {
const setChart = db.collection("Organizations").doc(orgDomain).collection("Teams").doc(teamId).collection("Charts").doc(chartName).set(inputJson);
exports.setOrganizationsChart = function(orgDomain, teamName, chartName, inputJson) {
const setChart = db.collection("Organizations").doc(orgDomain).collection("Teams").doc(teamName).collection("Charts").doc(chartName).set(inputJson);
return Promise.resolve(setChart);
};

/**
* Description
* @param {any} orgDomain
* @param {any} teamId
* @param {any} teamName
* @param {any} chartName
* @param {any} inputJson
* @return {any}
*/
exports.updateChart = function(orgDomain, teamId, chartName, inputJson) {
const setChart = db.collection("Organizations").doc(orgDomain).collection("Teams").doc(teamId).collection("Charts").doc(chartName).update(inputJson);
exports.updateChart = function(orgDomain, teamName, chartName, inputJson) {
const setChart = db.collection("Organizations").doc(orgDomain).collection("Teams").doc(teamName).collection("Charts").doc(chartName).update(inputJson);
return Promise.resolve(setChart);
};

Expand Down
12 changes: 12 additions & 0 deletions functions/model/performanceChart/performanceChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const { functions, cors, fastify, requestHandler } = require("../application/lib
const { getPerformanceChartData } = require("./tark/getPerformanceChartData");
const { getUserPerformanceChartData } = require("./tark/getUserPerformanceChartData");
const { getSprintEvaluationGraph } = require("./tark/getSprintEvaluationGraph");
const { getSprintBurndownChartData } = require("./tark/getSprintBurndownChart");

/**
* Description
Expand Down Expand Up @@ -55,6 +56,17 @@ fastify.post("/sprintEvaluationGraph", (req, res) => {
getSprintEvaluationGraph(req, res);
});

/**
* Description
* @param {any} "/getSprintBurndownChart"
* @param {any} req
* @param {any} res
* @returns {any}
*/
fastify.post("/getSprintBurndownChart", (req, res) => {
getSprintBurndownChartData(req, res);
});

/**
* Description
* @param {any} req
Expand Down
70 changes: 70 additions & 0 deletions functions/model/performanceChart/tark/getSprintBurndownChart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* eslint-disable linebreak-style */
/* eslint-disable max-len */
/* eslint-disable guard-for-in */
/* eslint-disable object-curly-spacing */

/** *********************************************************
* Copyright (C) 2022
* Worktez
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the MIT License
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the MIT License for more details.
***********************************************************/

const { createSprintName } = require("../../application/lib");
const { getTeamUseTeamId } = require("../../teams/lib");
const { getOrganizationsChartDetails } = require("../lib");
const { updateSprintBurndownChartData } = require("./updateSprintBurndownChart");

exports.getSprintBurndownChartData = function(request, response) {
const data = request.body.data;
const orgDomain = data.OrganizationDomain;
const teamId = data.TeamId;
const sprintNumber = parseInt(request.body.data.SprintNumber);
const fullSprintName = createSprintName(sprintNumber);
let result;
let teamName;
let status = 200;
let dataFound = false;

const sprintEvaluationGraphPromise = getTeamUseTeamId(orgDomain, teamId).then((team) => {
teamName = team.TeamName;
const p1 = getOrganizationsChartDetails(orgDomain, teamName, "SprintBurndownChart").then((doc) => {
let responseData = [];
if (doc == undefined) {
updateSprintBurndownChartData(orgDomain, teamId, fullSprintName);
result = {data: {status: "ERROR", data: "undefined"}};
} else {
for (const i in doc) {
if (i===fullSprintName) {
const chartData = doc[i];
responseData = chartData;
dataFound = true;
}
}
if (dataFound == false) {
console.log("got here");
updateSprintBurndownChartData(orgDomain, teamId, fullSprintName);
}
result = { data: { status: "OK", data: responseData } };
}
});
return Promise.resolve(p1);
}).catch((error) => {
status = 500;
console.log("Error:", error);
});
return Promise.resolve(sprintEvaluationGraphPromise).then(() => {
console.log("Fetched Sprint Burndown Chart Data Successfully");
return response.status(status).send(result);
}).catch((error) => {
console.error("Error Fetching Sprint Burndown Chart Data", error);
return response.status(status).send(result);
});
};
109 changes: 109 additions & 0 deletions functions/model/performanceChart/tark/updateSprintBurndownChart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/* eslint-disable linebreak-style */
/* eslint-disable max-len */
/* eslint-disable object-curly-spacing */
/* eslint-disable eol-last */

/** *********************************************************
* Copyright (C) 2022
* Worktez
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the MIT License
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the MIT License for more details.
***********************************************************/

const { getSprint } = require("../../sprints/lib");
const { getAllTasks } = require("../../tasks/lib");
const { getTeamUseTeamId } = require("../../teams/lib");
const { updateChart, setOrganizationsChart, getOrganizationsChartDetails } = require("../lib");

exports.updateSprintBurndownChartData = function(orgDomain, teamId, fullSprintName) {
let totalStoryPoints = 0;
const inputJson = {};
const tasks = [];
const p1 = getTeamUseTeamId(orgDomain, teamId).then((data)=>{
const teamName = data.TeamName;
const p2 = getSprint(orgDomain, teamName, fullSprintName).then((sprintDoc)=>{
const sprintNumber = sprintDoc.SprintNumber;
const sprintStartDate = new Date(sprintDoc.StartDate.replace("/", "-"));
const sprintEndDate = new Date(sprintDoc.EndDate.replace("/", "-"));
const date = new Date(sprintStartDate.getTime());
const dates = [];
while (date <= sprintEndDate) {
dates.push([new Date(date), 0]);
date.setDate(date.getDate() + 1);
}
const chartData = dates;

const p = getAllTasks(orgDomain, teamId, sprintNumber).then((taskCol) => {
taskCol.forEach((taskDoc) => {
tasks.push(taskDoc.data());
});


tasks.forEach((task) => {
const taskCreationDate = new Date(task.CreationDate.replace("/", "-"));
if (taskCreationDate.getTime()<sprintStartDate.getTime()) {
totalStoryPoints += task.StoryPointNumber;
}
});

chartData.forEach((element, index) => {
tasks.forEach((task) => {
let formattedDate;
let creationDate;
// To increase story points on task creation
if (task.CreationDate.includes("/")) {
// This condition is added to support the Previous data before the change in the ToolsService, Can be removed in future.
const dateArray = task.CreationDate.split("/");
creationDate = dateArray[1] + "/" + dateArray[0] + "/" + dateArray[2];
} else if (task.CreationDate.includes("-")) {
const dateArray = task.CreationDate.split("-");
creationDate = dateArray[1] + "/" + dateArray[0] + "/" + dateArray[2];
}
if (new Date(creationDate).toDateString() === element[0].toDateString()) {
totalStoryPoints += task.StoryPointNumber;
}

// To decrease story points on task completion

if (task.CompletionDate.includes("/")) {
// This condition is added to support the Previous data before the change in the ToolsService, Can be removed in future.
const dateArray = task.CompletionDate.split("/");
formattedDate = dateArray[1] + "/" + dateArray[0] + "/" + dateArray[2];
} else if (task.CompletionDate.includes("-")) {
const dateArray = task.CompletionDate.split("-");
formattedDate = dateArray[1] + "/" + dateArray[0] + "/" + dateArray[2];
}

if (task.Status == "Completed" && new Date(formattedDate).toDateString() === element[0].toDateString()) {
totalStoryPoints -= task.StoryPointNumber;
}
chartData[index] = totalStoryPoints;
});
});

inputJson[fullSprintName] = chartData;
const promise = getOrganizationsChartDetails(orgDomain, teamName, "SprintBurndownChart").then((data) => {
if (data != undefined) {
updateChart(orgDomain, teamName, "SprintBurndownChart", inputJson);
} else {
setOrganizationsChart(orgDomain, teamName, "SprintBurndownChart", inputJson);
}
return null;
}).catch((err) => {
console.log(err);
});
return Promise.resolve(promise);
});
return Promise.resolve(p);
});
return Promise.resolve(p2);
});
Promise.resolve(p1);
};
2 changes: 2 additions & 0 deletions functions/model/sprints/tark/createNewSprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const { getSprint, setSprint, updateSprint, setSprintActivity } = require("../li
const { getOrgUseAppKey } = require("../../organization/lib");
const { getTeamUseTeamId, updateTeamDetails } = require("../../teams/lib");
const { updateSprintEvaluationGraphData } = require("../../performanceChart/tark/updateSprintEvaluationGraph");
const { updateSprintBurndownChartData } = require("../../performanceChart/tark/updateSprintBurndownChart");

exports.createNewSprint = function(request, response) {
const appKey = request.body.data.AppKey;
Expand Down Expand Up @@ -104,6 +105,7 @@ exports.createNewSprint = function(request, response) {
let result;
return Promise.all(Promises).then(() => {
updateSprintEvaluationGraphData(orgDomain, teamId, createSprintName(newSprintId));
updateSprintBurndownChartData(orgDomain, teamId, createSprintName(newSprintId));
result = { data: "Sprint Created Successfully" };
console.log("Sprint Created Successfully");
return response.status(status).send(result);
Expand Down
2 changes: 2 additions & 0 deletions functions/model/tasks/tark/createTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const { getUserUseEmail } = require("../../users/lib");
const { sendNotification } = require("../../notifications/lib");
const { linkSubtask } = require("../../linker/tark/linkSubTask");
const { updateSprintEvaluationGraphData } = require("../../performanceChart/tark/updateSprintEvaluationGraph");
const { updateSprintBurndownChartData } = require("../../performanceChart/tark/updateSprintBurndownChart");

exports.createNewTask = function(request, response) {
const appKey = request.body.data.AppKey;
Expand Down Expand Up @@ -198,6 +199,7 @@ exports.createNewTask = function(request, response) {

const link = "https://worktez.com/TaskDetails/" + taskId;
updateSprintEvaluationGraphData(orgDomain, teamId, fullSprintName);
updateSprintBurndownChartData(orgDomain, teamId, fullSprintName);

taskMailer("Create_Task", taskId, orgDomain, senderName);
sendNotification(notificationMessage, senderEmail, assigneeUid, creationDate, time, orgDomain, link);
Expand Down
5 changes: 4 additions & 1 deletion functions/model/tasks/tark/editTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const { getUser } = require("../../users/lib");
const { updateSprintData } = require("../../sprints/tark/updateSprint");
const { getTeamUseTeamId } = require("../../teams/lib");
const { updateSprintEvaluationGraphData } = require("../../performanceChart/tark/updateSprintEvaluationGraph");

const { updateSprintBurndownChartData } = require("../../performanceChart/tark/updateSprintBurndownChart");

exports.editTask = function(request, response) {
const appKey = request.body.data.AppKey;
Expand Down Expand Up @@ -79,6 +79,8 @@ exports.editTask = function(request, response) {
updateSprintData(teamId, project, orgDomain, previousSprintName, oldStoryPointNumber, storyPointNumber, editedSprintNumber, orgId, editedSprintName, currentSprint).then(()=>{
updateSprintEvaluationGraphData(orgDomain, teamId, editedSprintName);
updateSprintEvaluationGraphData(orgDomain, teamId, previousSprintName);
updateSprintBurndownChartData(orgDomain, teamId, editedSprintName);
updateSprintBurndownChartData(orgDomain, teamId, previousSprintName);
});
});
return null;
Expand Down Expand Up @@ -110,6 +112,7 @@ exports.editTask = function(request, response) {
}
updateSprint(updateNewSprintJson, orgDomain, teamName, previousSprintName).then(()=>{
updateSprintEvaluationGraphData(orgDomain, teamId, previousSprintName);
updateSprintBurndownChartData(orgDomain, teamId, previousSprintName);
});
});
});
Expand Down
3 changes: 3 additions & 0 deletions functions/model/tasks/tark/logwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const { getOrgRawData, updateOrgRawData } = require("../../organization/lib");
const { getSprint, updateSprint } = require("../../sprints/lib");
const { getTask, updateTask } = require("../lib");
const { taskMailer } = require("../../mailer/lib");
const { updateSprintBurndownChartData } = require("../../performanceChart/tark/updateSprintBurndownChart");

exports.logWork = function(request, response) {
const assignee = request.body.data.Assignee;
Expand Down Expand Up @@ -93,6 +94,8 @@ exports.logWork = function(request, response) {
TotalUnCompletedTask: totalUnCompletedTask,
};
updateOrgRawData(updateRawDataInputJson, orgDomain);
console.log(taskId.slice(0, 4), "TEam id");
updateSprintBurndownChartData(orgDomain, taskId.slice(0, 3), fullSprintName);
}).catch((error) => {
status = 500;
console.log("Error:", error);
Expand Down
1 change: 1 addition & 0 deletions functions/model/teams/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ exports.setTeam = function(orgDomain, teamName, teamDescription, teamAdmin, team
FilterCounter: 0,
Scope: scope,
ProjectLink: "",
GitToken: "",
});
return Promise.resolve(setTeam);
};
Expand Down
60 changes: 60 additions & 0 deletions functions/model/teams/tark/addGitToken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* eslint-disable linebreak-style */
/* eslint-disable max-len */
/* eslint-disable object-curly-spacing */
/* eslint-disable eol-last */

/** *********************************************************
* Copyright (C) 2022
* Worktez
* Author: Swapnil Bankar <swapnilbankar1010@gmail.com>
* This program is free software; you can redistribute it and/or
* modify it under the terms of the MIT License
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the MIT License for more details.
***********************************************************/

const { updateTeamDetails, getTeam } = require("../lib");

exports.addGitToken = function(request, response) {
const orgDomain = request.body.data.OrganizationDomain;
const teamName = request.body.data.TeamName;
const gitToken = request.body.data.GitToken;

let status = 200;
let result = { data: "Error in updating team" };

const promise1 = getTeam(orgDomain, teamName)
.then((team) => {
if (team) {
const updateJson = {
GitToken: gitToken,
};
updateTeamDetails(updateJson, orgDomain, teamName);
result = { data: "Team Updated Successfully" };
console.log("Team Updated Successfully");
} else {
status = 500;
result = { data: "Error: Team doesn't exist" };
console.log("Error: Team doesn't exist");
}
})
.catch((error) => {
status = 500;
console.log("Error: ", error);
});

const Promises = [promise1];
Promise.all(Promises)
.then(() => {
return response.status(status).send(result);
})
.catch((error) => {
result = { data: error };
console.error("Error updating Team", error);
return response.status(status).send(result);
});
};
Loading

0 comments on commit a6f9464

Please sign in to comment.