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