Skip to content

Commit 6ca49f2

Browse files
committed
change task res.json
1 parent c8f88e9 commit 6ca49f2

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

controllers/tasks.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ const addNewTask = async (req, res) => {
2929
dependsOn,
3030
};
3131
const taskDependency = await dependencyModel.addDependency(data);
32+
const task = {
33+
...taskDetails,
34+
dependsOn: taskDependency,
35+
id: taskId,
36+
};
3237
return res.json({
3338
message: "Task created successfully!",
34-
task: taskDetails,
35-
id: taskId,
36-
dependsOn: taskDependency,
39+
task,
3740
});
3841
} catch (err) {
3942
logger.error(`Error while creating new task: ${err}`);

middlewares/validators/tasks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const createTask = async (req, res, next) => {
2323
assignee: joi.string().optional(),
2424
priority: joi.string().required(),
2525
percentCompleted: joi.number().required(),
26-
dependsOn: joi.array().items().optional(),
26+
dependsOn: joi.array().items(joi.string()).optional(),
2727
participants: joi.array().items(joi.string()).optional(),
2828
category: joi.string().optional(),
2929
level: joi.number().optional(),
@@ -84,7 +84,7 @@ const updateTask = async (req, res, next) => {
8484
.optional(),
8585
assignee: joi.string().optional(),
8686
percentCompleted: joi.number().optional(),
87-
dependsOn: joi.array().items().optional(),
87+
dependsOn: joi.array().items(joi.string()).optional(),
8888
participants: joi.array().items(joi.string()).optional(),
8989
completionAward: joi
9090
.object()

models/tasks.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const firestore = require("../utils/firestore");
22
const tasksModel = firestore.collection("tasks");
33
const ItemModel = firestore.collection("itemTags");
4+
const dependencyModel = firestore.collection("taskDependencies");
45
const userUtils = require("../utils/users");
5-
const dependencyModel = firestore.collection("TaskDependencies");
66
const { fromFirestoreData, toFirestoreData, buildTasks } = require("../utils/tasks");
77
const { TASK_TYPE, TASK_STATUS, TASK_STATUS_OLD } = require("../constants/tasks");
88
const { IN_PROGRESS, BLOCKED, SMOKE_TESTING, COMPLETED } = TASK_STATUS;
@@ -67,7 +67,8 @@ const addDependency = async (data) => {
6767
const fetchTasks = async () => {
6868
try {
6969
const tasksSnapshot = await tasksModel.get();
70-
const tasks = buildTasks(tasksSnapshot);
70+
const dependencySnapshot = await dependencyModel.get();
71+
const tasks = buildTasks(tasksSnapshot, dependencySnapshot);
7172
const promises = tasks.map(async (task) => fromFirestoreData(task));
7273
const updatedTasks = await Promise.all(promises);
7374
const taskList = updatedTasks.map((task) => {

0 commit comments

Comments
 (0)