-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #343 from hms-dbmi-cellenics/1836-metadata-tracks-…
…endpoints [BIOMAGE-1836] Implement metadata tracks-specific endpoints
- Loading branch information
Showing
15 changed files
with
948 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
const MetadataTrack = require('../model/MetadataTrack'); | ||
|
||
const getLogger = require('../../utils/getLogger'); | ||
const { OK, NotFoundError } = require('../../utils/responses'); | ||
|
||
const logger = getLogger('[MetadataTrackController] - '); | ||
|
||
const createMetadataTrack = async (req, res) => { | ||
const { | ||
params: { experimentId, metadataTrackKey }, | ||
} = req; | ||
|
||
logger.log(`Creating metadata track ${metadataTrackKey} in experiment ${experimentId}`); | ||
|
||
await new MetadataTrack().createNewMetadataTrack(experimentId, metadataTrackKey); | ||
|
||
logger.log(`Finished creating metadata track ${metadataTrackKey} in experiment ${experimentId}`); | ||
|
||
res.json(OK()); | ||
}; | ||
|
||
const patchMetadataTrack = async (req, res) => { | ||
const { | ||
params: { experimentId, metadataTrackKey: oldKey }, | ||
body: { key }, | ||
} = req; | ||
|
||
logger.log(`Patching metadata track ${oldKey} in experiment ${experimentId}`); | ||
|
||
const result = await new MetadataTrack() | ||
.update({ experiment_id: experimentId, key: oldKey }, { key }); | ||
|
||
if (result.length === 0) { | ||
throw new NotFoundError(`Metadata track ${oldKey} not found`); | ||
} | ||
|
||
logger.log(`Finished patching metadata track ${oldKey} in experiment ${experimentId}, changed to ${key}`); | ||
res.json(OK()); | ||
}; | ||
|
||
const deleteMetadataTrack = async (req, res) => { | ||
const { | ||
params: { experimentId, metadataTrackKey }, | ||
} = req; | ||
|
||
logger.log(`Creating metadata track ${metadataTrackKey} in experiment ${experimentId}`); | ||
|
||
const result = await new MetadataTrack().delete( | ||
{ experiment_id: experimentId, key: metadataTrackKey }, | ||
); | ||
|
||
if (result.length === 0) { | ||
throw new NotFoundError(`Metadata track ${metadataTrackKey} not found`); | ||
} | ||
|
||
logger.log(`Finished creating metadata track ${metadataTrackKey} in experiment ${experimentId}`); | ||
|
||
res.json(OK()); | ||
}; | ||
|
||
const patchValueForSample = async (req, res) => { | ||
const { | ||
params: { experimentId, sampleId, metadataTrackKey }, | ||
body: { value }, | ||
} = req; | ||
|
||
logger.log(`Patching value of metadata track ${metadataTrackKey} in sample ${sampleId} in experiment ${experimentId}`); | ||
|
||
await new MetadataTrack().patchValueForSample(experimentId, sampleId, metadataTrackKey, value); | ||
|
||
logger.log(`Finished patching value of metadata track ${metadataTrackKey} in sample ${sampleId} in experiment ${experimentId}, changed to ${value}`); | ||
res.json(OK()); | ||
}; | ||
|
||
module.exports = { | ||
createMetadataTrack, | ||
patchMetadataTrack, | ||
deleteMetadataTrack, | ||
patchValueForSample, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const { | ||
createMetadataTrack, | ||
patchMetadataTrack, | ||
patchValueForSample, | ||
deleteMetadataTrack, | ||
} = require('../controllers/metadataTrackController'); | ||
|
||
const { expressAuthorizationMiddleware } = require('../middlewares/authMiddlewares'); | ||
|
||
module.exports = { | ||
'metadataTrack#createMetadataTrack': [ | ||
expressAuthorizationMiddleware, | ||
(req, res, next) => createMetadataTrack(req, res).catch(next), | ||
], | ||
'metadataTrack#patchMetadataTrack': [ | ||
expressAuthorizationMiddleware, | ||
(req, res, next) => patchMetadataTrack(req, res).catch(next), | ||
], | ||
'metadataTrack#patchSampleInMetadataTrackValue': [ | ||
expressAuthorizationMiddleware, | ||
(req, res, next) => patchValueForSample(req, res).catch(next), | ||
], | ||
'metadataTrack#deleteMetadataTrack': [ | ||
expressAuthorizationMiddleware, | ||
(req, res, next) => deleteMetadataTrack(req, res).catch(next), | ||
], | ||
}; |
Oops, something went wrong.