Skip to content

Commit 16d4a50

Browse files
authored
Merge pull request #1705 from Real-Dev-Squad/remove-scripting-code
2 parents 6d31b55 + bc2421b commit 16d4a50

File tree

7 files changed

+0
-269
lines changed

7 files changed

+0
-269
lines changed

controllers/tasks.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -426,16 +426,6 @@ const assignTask = async (req, res) => {
426426
}
427427
};
428428

429-
const updateStatus = async (req, res) => {
430-
try {
431-
const response = await tasks.updateTaskStatus();
432-
return res.status(200).json(response);
433-
} catch (error) {
434-
logger.error("Error in migration scripts", error);
435-
return res.boom.badImplementation(INTERNAL_SERVER_ERROR);
436-
}
437-
};
438-
439429
module.exports = {
440430
addNewTask,
441431
fetchTasks,
@@ -446,5 +436,4 @@ module.exports = {
446436
updateTaskStatus,
447437
overdueTasks,
448438
assignTask,
449-
updateStatus,
450439
};

models/tasks.js

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@ const tasksModel = firestore.collection("tasks");
33
const ItemModel = firestore.collection("itemTags");
44
const dependencyModel = firestore.collection("taskDependencies");
55
const userUtils = require("../utils/users");
6-
const { updateTaskStatusToDone } = require("../services/tasks");
7-
const { chunks } = require("../utils/array");
8-
const { DOCUMENT_WRITE_SIZE } = require("../constants/constants");
96
const { fromFirestoreData, toFirestoreData, buildTasks } = require("../utils/tasks");
107
const { TASK_TYPE, TASK_STATUS, TASK_STATUS_OLD, TASK_SIZE } = require("../constants/tasks");
118
const { IN_PROGRESS, NEEDS_REVIEW, IN_REVIEW, ASSIGNED, BLOCKED, SMOKE_TESTING, COMPLETED, SANITY_CHECK } = TASK_STATUS;
129
const { OLD_ACTIVE, OLD_BLOCKED, OLD_PENDING, OLD_COMPLETED } = TASK_STATUS_OLD;
13-
const { INTERNAL_SERVER_ERROR } = require("../constants/errorMessages");
1410

1511
/**
1612
* Adds and Updates tasks
@@ -579,62 +575,6 @@ const getOverdueTasks = async (days = 0) => {
579575
}
580576
};
581577

582-
const updateTaskStatus = async () => {
583-
try {
584-
const snapshot = await tasksModel.where("status", "==", "COMPLETED").get();
585-
const tasksStatusCompleted = [];
586-
let summary = {
587-
totalTasks: snapshot.size,
588-
totalUpdatedStatus: 0,
589-
totalOperationsFailed: 0,
590-
updatedTaskDetails: [],
591-
failedTaskDetails: [],
592-
};
593-
594-
if (snapshot.size === 0) {
595-
return summary;
596-
}
597-
598-
snapshot.forEach((task) => {
599-
const id = task.id;
600-
const taskData = task.data();
601-
tasksStatusCompleted.push({ ...taskData, id });
602-
});
603-
const taskStatusCompletedChunks = chunks(tasksStatusCompleted, DOCUMENT_WRITE_SIZE);
604-
605-
const updatedTasksPromises = await Promise.all(
606-
taskStatusCompletedChunks.map(async (tasks) => {
607-
const res = await updateTaskStatusToDone(tasks);
608-
return {
609-
totalUpdatedStatus: res.totalUpdatedStatus,
610-
totalOperationsFailed: res.totalOperationsFailed,
611-
updatedTaskDetails: res.updatedTaskDetails,
612-
failedTaskDetails: res.failedTaskDetails,
613-
};
614-
})
615-
);
616-
617-
updatedTasksPromises.forEach((res) => {
618-
summary = {
619-
...summary,
620-
totalUpdatedStatus: (summary.totalUpdatedStatus += res.totalUpdatedStatus),
621-
totalOperationsFailed: (summary.totalOperationsFailed += res.totalOperationsFailed),
622-
updatedTaskDetails: [...summary.updatedTaskDetails, ...res.updatedTaskDetails],
623-
failedTaskDetails: [...summary.failedTaskDetails, ...res.failedTaskDetails],
624-
};
625-
});
626-
627-
if (summary.totalOperationsFailed === summary.totalTasks) {
628-
throw Error(INTERNAL_SERVER_ERROR);
629-
}
630-
631-
return summary;
632-
} catch (error) {
633-
logger.error(`Error in updating task status: ${error}`);
634-
throw error;
635-
}
636-
};
637-
638578
module.exports = {
639579
updateTask,
640580
fetchTasks,
@@ -651,5 +591,4 @@ module.exports = {
651591
fetchPaginatedTasks,
652592
getBuiltTasks,
653593
getOverdueTasks,
654-
updateTaskStatus,
655594
};

routes/tasks.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,4 @@ router.patch(
4040
);
4141
router.patch("/assign/self", authenticate, invalidateCache({ invalidationKeys: [ALL_TASKS] }), tasks.assignTask);
4242

43-
router.post("/migration", authenticate, authorizeRoles([SUPERUSER]), tasks.updateStatus);
44-
4543
module.exports = router;

services/tasks.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

test/integration/tasks.test.js

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const sinon = require("sinon");
33
const { expect } = chai;
44
const chaiHttp = require("chai-http");
55

6-
const firestore = require("../../utils/firestore");
76
const app = require("../../server");
87
const tasks = require("../../models/tasks");
98
const authService = require("../../services/authService");
@@ -1022,51 +1021,4 @@ describe("Tasks", function () {
10221021
expect(res.body.message).to.be.equal("No overdue tasks found");
10231022
});
10241023
});
1025-
1026-
describe("POST /tasks/migration", function () {
1027-
it("Should update status COMPLETED to DONE successful", async function () {
1028-
const taskData1 = { status: "COMPLETED" };
1029-
await firestore.collection("tasks").doc("updateTaskStatus1").set(taskData1);
1030-
const res = await chai.request(app).post("/tasks/migration").set("cookie", `${cookieName}=${superUserJwt}`);
1031-
expect(res).to.have.status(200);
1032-
expect(res.body.totalTasks).to.be.equal(1);
1033-
expect(res.body.totalUpdatedStatus).to.be.equal(1);
1034-
expect(res.body.updatedTaskDetails).to.deep.equal(["updateTaskStatus1"]);
1035-
expect(res.body.totalOperationsFailed).to.be.equal(0);
1036-
expect(res.body.failedTaskDetails).to.deep.equal([]);
1037-
});
1038-
1039-
it("Should not update if not found any COMPLETED task status ", async function () {
1040-
const res = await chai.request(app).post("/tasks/migration").set("cookie", `${cookieName}=${superUserJwt}`);
1041-
expect(res).to.have.status(200);
1042-
expect(res.body.totalTasks).to.be.equal(0);
1043-
expect(res.body.totalUpdatedStatus).to.be.equal(0);
1044-
expect(res.body.updatedTaskDetails).to.deep.equal([]);
1045-
expect(res.body.totalOperationsFailed).to.be.equal(0);
1046-
expect(res.body.failedTaskDetails).to.deep.equal([]);
1047-
});
1048-
1049-
it("should throw an error if firestore batch operations fail", async function () {
1050-
const stub = sinon.stub(firestore, "batch");
1051-
stub.returns({
1052-
update: function () {},
1053-
commit: function () {
1054-
throw new Error("Firestore batch commit failed!");
1055-
},
1056-
});
1057-
const taskData1 = { status: "COMPLETED" };
1058-
await firestore.collection("tasks").doc("updateTaskStatus1").set(taskData1);
1059-
const res = await chai.request(app).post("/tasks/migration").set("cookie", `${cookieName}=${superUserJwt}`);
1060-
expect(res.status).to.equal(500);
1061-
const response = res.body;
1062-
expect(response.message).to.be.equal("An internal server error occurred");
1063-
});
1064-
1065-
it("Should return 401 if not super_user", async function () {
1066-
const nonSuperUserId = await addUser(appOwner);
1067-
const nonSuperUserJwt = authService.generateAuthToken({ userId: nonSuperUserId });
1068-
const res = await chai.request(app).post("/tasks/migration").set("cookie", `${cookieName}=${nonSuperUserJwt}`);
1069-
expect(res).to.have.status(401);
1070-
});
1071-
});
10721024
});

test/unit/models/tasks.test.js

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
/* eslint-disable security/detect-object-injection */
66

77
const chai = require("chai");
8-
const sinon = require("sinon");
98
const { expect } = chai;
109
const cleanDb = require("../../utils/cleanDb");
1110
const tasksData = require("../../fixtures/tasks/tasks")();
@@ -305,45 +304,4 @@ describe("tasks", function () {
305304
expect(usersWithOverdueTasks.length).to.be.equal(4);
306305
});
307306
});
308-
309-
describe("update task status", function () {
310-
beforeEach(async function () {
311-
const addTasksPromises = [];
312-
tasksData.forEach((task) => {
313-
const taskData = {
314-
...task,
315-
status: "COMPLETED",
316-
};
317-
addTasksPromises.push(tasksModel.add(taskData));
318-
});
319-
320-
await Promise.all(addTasksPromises);
321-
});
322-
323-
afterEach(function () {
324-
sinon.restore();
325-
});
326-
327-
it("Should update task status COMPLETED to DONE", async function () {
328-
const res = await tasks.updateTaskStatus();
329-
expect(res.totalTasks).to.be.equal(8);
330-
expect(res.totalUpdatedStatus).to.be.equal(8);
331-
});
332-
333-
it("should throw an error if firebase batch operation fails", async function () {
334-
const stub = sinon.stub(firestore, "batch");
335-
stub.returns({
336-
update: function () {},
337-
commit: function () {
338-
throw new Error("Firestore batch update failed");
339-
},
340-
});
341-
try {
342-
await tasks.updateTaskStatus();
343-
} catch (error) {
344-
expect(error).to.be.an.instanceOf(Error);
345-
expect(error.message).to.equal("An internal server error occurred");
346-
}
347-
});
348-
});
349307
});

test/unit/services/tasks.test.js

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)