Skip to content

Commit

Permalink
feat:add taskTitle field to sendTaskUpdate util (#2029)
Browse files Browse the repository at this point in the history
Co-authored-by: Amit Prakash <[email protected]>
  • Loading branch information
tejaskh3 and iamitprakash committed May 5, 2024
1 parent 4342eb6 commit 60ef429
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions controllers/progresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ const createProgress = async (req, res) => {
body: { type, completed, planned, blockers, taskId },
} = req;
try {
const data = await createProgressDocument({ ...req.body, userId: req.userData.id });
await sendTaskUpdate(completed, blockers, planned, req.userData.username, taskId);
const { data, taskTitle } = await createProgressDocument({ ...req.body, userId: req.userData.id });
await sendTaskUpdate(completed, blockers, planned, req.userData.username, taskId, taskTitle);
return res.status(201).json({
data,
message: `${type.charAt(0).toUpperCase() + type.slice(1)} ${PROGRESS_DOCUMENT_CREATED_SUCCEEDED}`,
Expand Down
6 changes: 4 additions & 2 deletions models/progresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ const createProgressDocument = async (progressData) => {
const { type, taskId } = progressData;
const createdAtTimestamp = new Date().getTime();
const progressDateTimestamp = getProgressDateTimestamp();
let taskTitle;
if (taskId) {
await assertTaskExists(taskId);
taskTitle = await assertTaskExists(taskId);
}
const query = buildQueryForPostingProgress(progressData);
const existingDocumentSnapshot = await query.where("date", "==", progressDateTimestamp).get();
Expand All @@ -35,7 +36,8 @@ const createProgressDocument = async (progressData) => {
}
const progressDocumentData = { ...progressData, createdAt: createdAtTimestamp, date: progressDateTimestamp };
const { id } = await progressesCollection.add(progressDocumentData);
return { id, ...progressDocumentData };
const data = { id, ...progressDocumentData };
return { data, taskTitle };
};

/**
Expand Down
12 changes: 10 additions & 2 deletions test/unit/utils/sendTaskUpdate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ describe("sendTaskUpdate function", function () {
"No blockers",
"Plan for the next phase",
"userName",
"taskId"
"taskId",
"Task title"
);
expect(result).to.equal(undefined);
});
Expand All @@ -31,7 +32,14 @@ describe("sendTaskUpdate function", function () {
const error = new Error("Error");
fetchMock.rejects(error);
try {
await sendTaskUpdate("Task completed", "No blockers", "Plan for the next phase", "userName", "taskId");
await sendTaskUpdate(
"Task completed",
"No blockers",
"Plan for the next phase",
"userName",
"taskId",
"task title"
);
} catch (err) {
expect(err).to.be.equal(error);
}
Expand Down
1 change: 1 addition & 0 deletions utils/progresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const assertTaskExists = async (taskId) => {
if (!taskData) {
throw new NotFound(`Task with id ${taskId} does not exist.`);
}
return taskData;
};

/**
Expand Down
3 changes: 2 additions & 1 deletion utils/sendTaskUpdate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { generateCloudFlareHeaders } from "../utils/discord-actions.js";
const DISCORD_BASE_URL = config.get("services.discordBot.baseUrl");

export const sendTaskUpdate = async (completed, blockers, planned, userName, taskId) => {
export const sendTaskUpdate = async (completed, blockers, planned, userName, taskId, taskTitle) => {
try {
const headers = generateCloudFlareHeaders();
const body = {
Expand All @@ -11,6 +11,7 @@ export const sendTaskUpdate = async (completed, blockers, planned, userName, tas
planned,
userName,
taskId,
taskTitle,
},
};
await fetch(`${DISCORD_BASE_URL}/task/update`, {
Expand Down

0 comments on commit 60ef429

Please sign in to comment.