MCPcopy Create free account
hub / github.com/RealDevSquad/website-backend / createProgressDocument

Function createProgressDocument

models/progresses.js:27–44  ·  view source on GitHub ↗
(progressData)

Source from the content-addressed store, hash-verified

25 * @throws {Error} If a progress document has already been created for the given user or task on the current day.
26 **/
27const createProgressDocument = async (progressData) => {
28 const { type, taskId } = progressData;
29 const createdAtTimestamp = new Date().getTime();
30 const progressDateTimestamp = getProgressDateTimestamp();
31 let taskTitle;
32 if (taskId) {
33 taskTitle = await assertTaskExists(taskId);
34 }
35 const query = buildQueryForPostingProgress(progressData);
36 const existingDocumentSnapshot = await query.where("date", "==", progressDateTimestamp).get();
37 if (!existingDocumentSnapshot.empty) {
38 throw new Conflict(`${type.charAt(0).toUpperCase() + type.slice(1)} ${PROGRESS_ALREADY_CREATED}`);
39 }
40 const progressDocumentData = { ...progressData, createdAt: createdAtTimestamp, date: progressDateTimestamp };
41 const { id } = await progressesCollection.add(progressDocumentData);
42 const data = { id, ...progressDocumentData };
43 return { data, taskTitle };
44};
45
46/**
47 * This function retrieves the progress document for a specific user or task, or for all users or all tasks if no specific user or task is provided.

Callers 2

tasks.test.jsFile · 0.85

Calls 4

getProgressDateTimestampFunction · 0.85
assertTaskExistsFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected