Skip to content

Commit 2265cee

Browse files
committed
Used JSDoc annotations to provide type information for the controller functions
1 parent 0ab2700 commit 2265cee

File tree

1 file changed

+97
-12
lines changed

1 file changed

+97
-12
lines changed

controllers/progresses.js

Lines changed: 97 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,40 @@ const { RESPONSE_MESSAGES } = require("../constants/progresses");
44
const { PROGRESS_DOCUMENT_RETRIEVAL_SUCCEEDED, PROGRESS_DOCUMENT_CREATED_SUCCEEDED } = RESPONSE_MESSAGES;
55

66
/**
7-
* Adds Progress Document
8-
*
9-
* @param req {Object} - Express request object
10-
* @param res {Object} - Express response object
7+
* @typedef {Object} ProgressRequestBody
8+
* @property {string} type - The type of progress document.
9+
* @property {string} completed - The completed progress.
10+
* @property {string} planned - The planned progress.
11+
* @property {string} blockers - The blockers.
12+
* @property {string} [taskId] - The task ID (optional).
1113
*/
14+
15+
/**
16+
* @typedef {Object} ProgressDocument
17+
* @property {string} type - The type of progress document.
18+
* @property {string} completed - The completed progress.
19+
* @property {string} planned - The planned progress.
20+
* @property {string} blockers - The blockers.
21+
* @property {string} userId - The User ID
22+
* @property {string} [taskId] - The task ID (optional).
23+
* @property {number} createdAt - The timestamp when the progress document was created.
24+
* @property {number} date - The timestamp for the day the progress document was created.
25+
*/
26+
27+
/**
28+
* @typedef {Object} ProgressResponse
29+
* @property {ProgressDocument} data - The progress document data.
30+
* @property {string} message - The success message.
31+
*/
32+
33+
/**
34+
* Creates a new progress document.
35+
* @param {Object} req - The HTTP request object.
36+
* @param {ProgressRequestBody} req.body - The progress document data.
37+
* @param {Object} res - The HTTP response object.
38+
* @returns {Promise<void>} A Promise that resolves when the response is sent.
39+
*/
40+
1241
const createProgress = async (req, res) => {
1342
const {
1443
body: { type },
@@ -36,11 +65,39 @@ const createProgress = async (req, res) => {
3665
};
3766

3867
/**
39-
* Gets Progress Document
40-
*
41-
* @param req {Object} - Express request object
42-
* @param res {Object} - Express response object
68+
* @typedef {Object} ProgressQueryParams
69+
* @property {string} [type] - The type of progress document.
70+
* @property {string} [taskId] - The task ID (optional).
71+
* @property {string} [userId] - The user ID (optional).
72+
*/
73+
74+
/**
75+
* @typedef {Object} ProgressDocument
76+
* @property {string} type - The type of progress document.
77+
* @property {string} completed - The completed progress.
78+
* @property {string} planned - The planned progress.
79+
* @property {string} blockers - The blockers.
80+
* @property {string} userId - The User ID
81+
* @property {string} [taskId] - The task ID (optional).
82+
* @property {number} createdAt - The timestamp when the progress document was created.
83+
* @property {number} date - The timestamp for the day the progress document was created.
4384
*/
85+
86+
/**
87+
* @typedef {Object} GetProgressResponse
88+
* @property {string} message - The success message.
89+
* @property {number} count - The no of progress documents retrieved
90+
* @property {[ProgressDocument]} data - An array of progress documents
91+
*/
92+
93+
/**
94+
* Retrieves the progress documents based on provided query parameters.
95+
* @param {Object} req - The HTTP request object.
96+
* @param {ProgressQueryParams} req.query - The query parameters
97+
* @param {Object} res - The HTTP response object.
98+
* @returns {Promise<void>} A Promise that resolves when the response is sent.
99+
*/
100+
44101
const getProgress = async (req, res) => {
45102
try {
46103
const data = await getProgressDocument(req.query);
@@ -62,11 +119,39 @@ const getProgress = async (req, res) => {
62119
};
63120

64121
/**
65-
* Gets Progress Records within the specified date range
66-
*
67-
* @param req {Object} - Express request object
68-
* @param res {Object} - Express response object
122+
* @typedef {Object} ProgressQueryParams
123+
* @property {string} [taskId] - The task ID (optional).
124+
* @property {string} [userId] - The user ID (optional).
125+
* @property {string} startDate - The start date of the date range to retrieve progress records for.
126+
* @property {string} endDate - The end date of the date range to retrieve progress records for.
127+
*/
128+
129+
/**
130+
* @typedef {Object} progressRecord
131+
* @property {boolean} date - the boolean indicating whether the progress was recorded or not for that date
132+
/**
133+
134+
/**
135+
* @typedef {Object} ProgressRangeData
136+
* @property {string} startDate - the start date for the progress records
137+
* @property {string} endDate - the end date for the progress records
138+
* @property {Object.<string, progressRecord>} progressRecords - An object where the keys are dates and the values are progress records.
139+
/**
140+
141+
/**
142+
* @typedef {Object} GetProgressRangeDataResponse
143+
* @property {string} message - The success message.
144+
* @property {ProgressRangeData} data - The progress range data.
69145
*/
146+
147+
/**
148+
* Retrieves the progress documents based on provided query parameters.
149+
* @param {Object} req - The HTTP request object.
150+
* @param {ProgressQueryParams} req.query - The query parameters
151+
* @param {Object} res - The HTTP response object.
152+
* @returns {Promise<void>} A Promise that resolves when the response is sent.
153+
*/
154+
70155
const getProgressRangeData = async (req, res) => {
71156
try {
72157
const data = await getRangeProgressData(req.query);

0 commit comments

Comments
 (0)