From 925614df39eeb57eaedc560935a7b7f053ee1602 Mon Sep 17 00:00:00 2001 From: cosa65 Date: Tue, 28 Nov 2023 11:28:05 -0300 Subject: [PATCH] Change endpoint to update upload stauts of a file to require sample file id instead of type and sample id Signed-off-by: cosa65 --- src/api.v2/controllers/sampleFileController.js | 8 ++++---- src/api.v2/model/SampleFile.js | 12 +++--------- src/specs/api.v2.yaml | 11 +++-------- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/api.v2/controllers/sampleFileController.js b/src/api.v2/controllers/sampleFileController.js index 9bbb8a937..bfea1b9dd 100644 --- a/src/api.v2/controllers/sampleFileController.js +++ b/src/api.v2/controllers/sampleFileController.js @@ -65,14 +65,14 @@ const beginUpload = async (req, res) => { const patchFile = async (req, res) => { const { - params: { experimentId, sampleId, sampleFileType }, + params: { experimentId, sampleFileId }, body: { uploadStatus }, } = req; - logger.log(`Patching file ${sampleFileType} for sample ${sampleId} in experiment ${experimentId}`); + logger.log(`Patching file ${sampleFileId} in experiment ${experimentId}`); - await new SampleFile().updateUploadStatus(sampleId, sampleFileType, uploadStatus); + await new SampleFile().updateUploadStatus(sampleFileId, uploadStatus); - logger.log(`Finished patching sample file for experiment ${experimentId}, sample ${sampleId}, sampleFileType ${sampleFileType}`); + logger.log(`Finished patching sample file for experiment ${experimentId}, file: ${sampleFileId}`); res.json(OK()); }; diff --git a/src/api.v2/model/SampleFile.js b/src/api.v2/model/SampleFile.js index 900bdafce..889152d13 100644 --- a/src/api.v2/model/SampleFile.js +++ b/src/api.v2/model/SampleFile.js @@ -33,16 +33,10 @@ class SampleFile extends BasicModel { return files; } - async updateUploadStatus(sampleId, sampleFileType, uploadStatus) { - await this.sql({ sf: tableNames.SAMPLE_FILE }) + async updateUploadStatus(sampleFileId, uploadStatus) { + return this.sql({ sf: tableNames.SAMPLE_FILE }) .update({ upload_status: uploadStatus }) - .whereExists( - this.sql({ sf_map: tableNames.SAMPLE_TO_SAMPLE_FILE_MAP }) - .select(['sample_file_id']) - .where('sf_map.sample_file_id', '=', this.sql.ref('sf.id')) - .where('sf_map.sample_id', '=', sampleId), - ) - .andWhere({ sample_file_type: sampleFileType }); + .where({ id: sampleFileId }); } } diff --git a/src/specs/api.v2.yaml b/src/specs/api.v2.yaml index 65462810d..85dcabc52 100644 --- a/src/specs/api.v2.yaml +++ b/src/specs/api.v2.yaml @@ -1574,9 +1574,9 @@ paths: application/json: schema: $ref: "#/components/schemas/HTTPError" + "/experiments/{experimentId}/sampleFiles/{sampleFileId}": patch: summary: Update a sample files property - description: Update property of a sample file operationId: patchFile x-eov-operation-id: sampleFile#patch x-eov-operation-handler: routes/sampleFile @@ -1587,13 +1587,7 @@ paths: description: ID of the experiment. schema: type: string - - name: sampleId - in: path - description: ID of the sample. - required: true - schema: - type: string - - name: sampleFileType + - name: sampleFileId in: path description: Type of the file. required: true @@ -1641,6 +1635,7 @@ paths: application/json: schema: $ref: "#/components/schemas/HTTPError" + "/experiments/{experimentId}/sampleFiles/{sampleFileId}/beginUpload": post: summary: Begins the multipart upload of a sample file