|
1 | 1 | const { Conflict, NotFound } = require("http-errors");
|
2 |
| -const { createProgressDocument, getProgressDocument, getRangeProgressData } = require("../models/progresses"); |
| 2 | +const { |
| 3 | + createProgressDocument, |
| 4 | + getProgressDocument, |
| 5 | + getRangeProgressData, |
| 6 | + getProgressByDate, |
| 7 | +} = require("../models/progresses"); |
3 | 8 | const { RESPONSE_MESSAGES } = require("../constants/progresses");
|
4 | 9 | const { PROGRESS_DOCUMENT_RETRIEVAL_SUCCEEDED, PROGRESS_DOCUMENT_CREATED_SUCCEEDED } = RESPONSE_MESSAGES;
|
5 | 10 |
|
@@ -171,4 +176,57 @@ const getProgressRangeData = async (req, res) => {
|
171 | 176 | }
|
172 | 177 | };
|
173 | 178 |
|
174 |
| -module.exports = { createProgress, getProgress, getProgressRangeData }; |
| 179 | +/** |
| 180 | + * @typedef {Object} progressPathParams |
| 181 | + * @property {string} type - The type of progress document user or task. |
| 182 | + * @property {string} typeId - The ID of the type. |
| 183 | + * @property {string} date - The iso format date of the query. |
| 184 | + */ |
| 185 | + |
| 186 | +/** |
| 187 | + * @typedef {Object} ProgressDocument |
| 188 | + * @property {string} id - The id of the progress document. |
| 189 | + * @property {string} type - The type of progress document. |
| 190 | + * @property {string} completed - The completed progress. |
| 191 | + * @property {string} planned - The planned progress. |
| 192 | + * @property {string} blockers - The blockers. |
| 193 | + * @property {string} userId - The User ID |
| 194 | + * @property {string} [taskId] - The task ID (optional). |
| 195 | + * @property {number} createdAt - The timestamp when the progress document was created. |
| 196 | + * @property {number} date - The timestamp for the day the progress document was created. |
| 197 | + */ |
| 198 | + |
| 199 | +/** |
| 200 | + * @typedef {Object} GetProgressByDateResponse |
| 201 | + * @property {string} message - The success message. |
| 202 | + * @property {ProgressDocument} data - An array of progress documents |
| 203 | + */ |
| 204 | + |
| 205 | +/** |
| 206 | + * Retrieves the progress documents based on provided query parameters. |
| 207 | + * @param {Object} req - The HTTP request object. |
| 208 | + * @param {progressPathParams} req.params - The query parameters |
| 209 | + * @param {Object} res - The HTTP response object. |
| 210 | + * @returns {Promise<void>} A Promise that resolves when the response is sent. |
| 211 | + */ |
| 212 | + |
| 213 | +const getProgressBydDateController = async (req, res) => { |
| 214 | + try { |
| 215 | + const data = await getProgressByDate(req.params); |
| 216 | + return res.json({ |
| 217 | + message: PROGRESS_DOCUMENT_RETRIEVAL_SUCCEEDED, |
| 218 | + data, |
| 219 | + }); |
| 220 | + } catch (error) { |
| 221 | + if (error instanceof NotFound) { |
| 222 | + return res.status(404).json({ |
| 223 | + message: error.message, |
| 224 | + }); |
| 225 | + } |
| 226 | + return res.status(400).json({ |
| 227 | + message: error.message, |
| 228 | + }); |
| 229 | + } |
| 230 | +}; |
| 231 | + |
| 232 | +module.exports = { createProgress, getProgress, getProgressRangeData, getProgressBydDateController }; |
0 commit comments