(progressData)
| 25 | * @throws {Error} If a progress document has already been created for the given user or task on the current day. |
| 26 | **/ |
| 27 | const 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. |
no test coverage detected