Skip to content

Commit 5f5f596

Browse files
authored
Feat #120 - Get previous submissions paginated (#121)
* get submission by id * retrieve submissions by category * get submission by organization * relocate submission unit tests
1 parent 873b87e commit 5f5f596

30 files changed

+2569
-2315
lines changed

apps/server/swagger/parameters.yml

+14
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,17 @@ components:
3838
type: string
3939
enum: ['flat', 'compound']
4040
description: Optional query parameter to define the data format. Choose 'flat' for a simple, single-level collection of records, or 'compound' for a nested, schema-centric structure. The default value is 'flat'
41+
OnlyActive:
42+
description: Optional query parameter to filter results to include only active submissions. Default value is false
43+
name: onlyActive
44+
in: query
45+
schema:
46+
type: boolean
47+
required: false
48+
Organization:
49+
description: Optional query parameter to filter results to include only submissions associated to an specific organization. By default, returns submissions from all organizations
50+
name: organization
51+
in: query
52+
schema:
53+
type: string
54+
required: false

apps/server/swagger/schemas.yml

+21-7
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ components:
5555
$ref: '#/components/responses/Error'
5656

5757
schemas:
58-
ActiveSubmissionResult:
58+
SubmissionResult:
5959
type: object
6060
properties:
6161
id:
@@ -161,12 +161,26 @@ components:
161161
type: string
162162
description: User name who last updated the submission
163163

164-
ActiveSubmissionsSummaryResult:
165-
type: array
166-
items:
167-
$ref: '#/components/schemas/ActiveSubmissionSummary'
164+
SubmissionsSummaryResult:
165+
type: object
166+
properties:
167+
pagination:
168+
type: object
169+
properties:
170+
currentPage:
171+
type: number
172+
pageSize:
173+
type: number
174+
totalPages:
175+
type: number
176+
totalRecords:
177+
type: number
178+
records:
179+
type: array
180+
items:
181+
$ref: '#/components/schemas/SubmissionSummary'
168182

169-
ActiveSubmissionSummary:
183+
SubmissionSummary:
170184
type: object
171185
properties:
172186
id:
@@ -258,7 +272,7 @@ components:
258272
description: Name of user who last updated the submission
259273

260274
ActiveSubmissionSummaryResult:
261-
$ref: '#/components/schemas/ActiveSubmissionSummary'
275+
$ref: '#/components/schemas/SubmissionSummary'
262276

263277
BatchError:
264278
type: object

apps/server/swagger/submission-api.yml

+13-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/submission/{submissionId}:
44
get:
5-
summary: Get active submission by ID
5+
summary: Get submission by ID
66
tags:
77
- Submission
88
parameters:
@@ -12,11 +12,11 @@
1212
required: true
1313
responses:
1414
200:
15-
description: Active Submission
15+
description: Submission details
1616
content:
1717
application/json:
1818
schema:
19-
$ref: '#/components/schemas/ActiveSubmissionResult'
19+
$ref: '#/components/schemas/SubmissionResult'
2020

2121
401:
2222
$ref: '#/components/responses/UnauthorizedError'
@@ -42,7 +42,7 @@
4242
content:
4343
application/json:
4444
schema:
45-
$ref: '#/components/schemas/ActiveSubmissionResult'
45+
$ref: '#/components/schemas/SubmissionResult'
4646
400:
4747
$ref: '#/components/responses/BadRequest'
4848
401:
@@ -91,7 +91,7 @@
9191
content:
9292
application/json:
9393
schema:
94-
$ref: '#/components/schemas/ActiveSubmissionResult'
94+
$ref: '#/components/schemas/SubmissionResult'
9595
400:
9696
$ref: '#/components/responses/BadRequest'
9797
401:
@@ -107,18 +107,22 @@
107107

108108
/submission/category/{categoryId}:
109109
get:
110-
summary: Retrieve the Active Submissions for a category in this user session
110+
summary: Retrieve the Submissions for a category in this user session
111111
tags:
112112
- Submission
113113
parameters:
114114
- $ref: '#/components/parameters/path/CategoryId'
115+
- $ref: '#/components/parameters/query/Page'
116+
- $ref: '#/components/parameters/query/PageSize'
117+
- $ref: '#/components/parameters/query/OnlyActive'
118+
- $ref: '#/components/parameters/query/Organization'
115119
responses:
116120
200:
117-
description: Active Submissions
121+
description: Submissions details
118122
content:
119123
application/json:
120124
schema:
121-
$ref: '#/components/schemas/ActiveSubmissionsSummaryResult'
125+
$ref: '#/components/schemas/SubmissionsSummaryResult'
122126

123127
401:
124128
$ref: '#/components/responses/UnauthorizedError'
@@ -132,6 +136,7 @@
132136
/submission/category/{categoryId}/organization/{organization}:
133137
get:
134138
summary: Retrieve the Active Submission for a category and organization in this user session
139+
deprecated: true
135140
tags:
136141
- Submission
137142
parameters:

packages/data-provider/src/controllers/submissionController.ts

+38-14
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import { validateRequest } from '../utils/requestValidation.js';
99
import {
1010
dataDeleteBySystemIdRequestSchema,
1111
dataEditRequestSchema,
12-
submissionActiveByIdRequestSchema,
1312
submissionActiveByOrganizationRequestSchema,
14-
submissionActiveyByCategoryRequestSchema,
13+
submissionByIdRequestSchema,
1514
submissionCommitRequestSchema,
1615
submissionDeleteEntityNameRequestSchema,
1716
submissionDeleteRequestSchema,
17+
submissionsByCategoryRequestSchema,
1818
uploadSubmissionRequestSchema,
1919
} from '../utils/schemas.js';
2020
import { BATCH_ERROR_TYPE, BatchError, SUBMISSION_ACTION_TYPE, SUPPORTED_FILE_EXTENSIONS } from '../utils/types.js';
@@ -23,6 +23,8 @@ const controller = (dependencies: BaseDependencies) => {
2323
const service = submissionService(dependencies);
2424
const dataService = submittedDataService(dependencies);
2525
const { logger } = dependencies;
26+
const defaultPage = 1;
27+
const defaultPageSize = 20;
2628
const LOG_MODULE = 'SUBMISSION_CONTROLLER';
2729
return {
2830
commit: validateRequest(submissionCommitRequestSchema, async (req, res, next) => {
@@ -162,29 +164,51 @@ const controller = (dependencies: BaseDependencies) => {
162164
next(error);
163165
}
164166
}),
165-
getActiveByCategory: validateRequest(submissionActiveyByCategoryRequestSchema, async (req, res, next) => {
167+
getSubmissionsByCategory: validateRequest(submissionsByCategoryRequestSchema, async (req, res, next) => {
166168
try {
167169
const categoryId = Number(req.params.categoryId);
170+
const onlyActive = req.query.onlyActive?.toLowerCase() === 'true';
171+
const organization = req.query.organization;
172+
const page = parseInt(String(req.query.page)) || defaultPage;
173+
const pageSize = parseInt(String(req.query.pageSize)) || defaultPageSize;
168174

169-
logger.info(LOG_MODULE, `Request Active Submission categoryId '${categoryId}'`);
175+
logger.info(
176+
LOG_MODULE,
177+
`Request Submission categoryId '${categoryId}'`,
178+
`pagination params: page '${page}' pageSize '${pageSize}'`,
179+
`onlyActive '${onlyActive}'`,
180+
`organization '${organization}'`,
181+
);
170182

171183
// TODO: get userName from auth
172184
const userName = '';
173185

174-
const activeSubmissions = await service.getActiveSubmissionsByCategory({ categoryId, userName });
186+
const submissionsResult = await service.getSubmissionsByCategory(
187+
categoryId,
188+
{ page, pageSize },
189+
{ onlyActive, userName, organization },
190+
);
175191

176-
if (!activeSubmissions || activeSubmissions.length === 0) {
177-
throw new NotFound('Active Submission not found');
192+
if (isEmpty(submissionsResult.result)) {
193+
throw new NotFound('Submissions not found');
178194
}
179195

180-
logger.info(LOG_MODULE, `Found '${activeSubmissions.length}' Active Submissions`);
196+
const response = {
197+
pagination: {
198+
currentPage: page,
199+
pageSize: pageSize,
200+
totalPages: Math.ceil(submissionsResult.metadata.totalRecords / pageSize),
201+
totalRecords: submissionsResult.metadata.totalRecords,
202+
},
203+
records: submissionsResult.result,
204+
};
181205

182-
return res.status(200).send(activeSubmissions);
206+
return res.status(200).send(response);
183207
} catch (error) {
184208
next(error);
185209
}
186210
}),
187-
getActiveById: validateRequest(submissionActiveByIdRequestSchema, async (req, res, next) => {
211+
getSubmissionById: validateRequest(submissionByIdRequestSchema, async (req, res, next) => {
188212
try {
189213
const submissionId = Number(req.params.submissionId);
190214

@@ -193,13 +217,13 @@ const controller = (dependencies: BaseDependencies) => {
193217
// TODO: get userName from auth
194218
// const userName = '';
195219

196-
const activeSubmission = await service.getActiveSubmissionById(submissionId);
220+
const submission = await service.getSubmissionById(submissionId);
197221

198-
if (isEmpty(activeSubmission)) {
199-
throw new NotFound('Active Submission not found');
222+
if (isEmpty(submission)) {
223+
throw new NotFound('Submission not found');
200224
}
201225

202-
return res.status(200).send(activeSubmission);
226+
return res.status(200).send(submission);
203227
} catch (error) {
204228
next(error);
205229
}

0 commit comments

Comments
 (0)