(req, res)
| 112 | */ |
| 113 | |
| 114 | const getProgress = async (req, res) => { |
| 115 | const { dev, page = PROGRESSES_PAGE_SIZE, size = PROGRESSES_SIZE, type, userId, taskId } = req.query; |
| 116 | try { |
| 117 | if (dev === "true") { |
| 118 | const { progressDocs, totalProgressCount } = await progressesModel.getPaginatedProgressDocument(req.query); |
| 119 | const limit = parseInt(size, 10); |
| 120 | const offset = parseInt(page, 10) * limit; |
| 121 | const nextPage = offset + limit < totalProgressCount ? parseInt(page, 10) + 1 : null; |
| 122 | const prevPage = page > 0 ? parseInt(page, 10) - 1 : null; |
| 123 | let baseUrl = `${req.baseUrl}`; |
| 124 | if (type) { |
| 125 | baseUrl += `?type=${type}`; |
| 126 | } else if (userId) { |
| 127 | baseUrl += `?userId=${userId}`; |
| 128 | } else if (taskId) { |
| 129 | baseUrl += `?taskId=${taskId}`; |
| 130 | } |
| 131 | const nextLink = nextPage !== null ? `${baseUrl}&page=${nextPage}&size=${size}&dev=${dev}` : null; |
| 132 | const prevLink = prevPage !== null ? `${baseUrl}&page=${prevPage}&size=${size}&dev=${dev}` : null; |
| 133 | return res.json({ |
| 134 | message: PROGRESS_DOCUMENT_RETRIEVAL_SUCCEEDED, |
| 135 | count: progressDocs.length, |
| 136 | data: progressDocs, |
| 137 | links: { |
| 138 | prev: prevLink, |
| 139 | next: nextLink, |
| 140 | }, |
| 141 | }); |
| 142 | } |
| 143 | const data = await progressesModel.getProgressDocument(req.query); |
| 144 | return res.json({ |
| 145 | message: PROGRESS_DOCUMENT_RETRIEVAL_SUCCEEDED, |
| 146 | count: data.length, |
| 147 | data, |
| 148 | }); |
| 149 | } catch (error) { |
| 150 | if (error instanceof NotFound) { |
| 151 | return res.status(404).json({ |
| 152 | message: error.message, |
| 153 | }); |
| 154 | } |
| 155 | logger.error(error.message); |
| 156 | return res.status(500).json({ |
| 157 | message: INTERNAL_SERVER_ERROR_MESSAGE, |
| 158 | }); |
| 159 | } |
| 160 | }; |
| 161 | |
| 162 | /** |
| 163 | * @typedef {Object} ProgressQueryParams |
nothing calls this directly
no outgoing calls
no test coverage detected