forked from hms-dbmi-cellenics/api
-
Notifications
You must be signed in to change notification settings - Fork 0
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 hms-dbmi-cellenics#488 from biomage-org/cell-level…
…-meta [Cell-level metadata] Update the Add metadata select
- Loading branch information
Showing
24 changed files
with
424 additions
and
98 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,48 @@ | ||
const { v4: uuidv4 } = require('uuid'); | ||
const _ = require('lodash'); | ||
const bucketNames = require('../../config/bucketNames'); | ||
const sqlClient = require('../../sql/sqlClient'); | ||
const CellLevelMeta = require('../model/CellLevelMeta'); | ||
const CellLevelMetaToExperiment = require('../model/CellLevelMetaToExperiment'); | ||
const { getFileUploadUrls } = require('../helpers/s3/signedUrl'); | ||
const OK = require('../../utils/responses/OK'); | ||
|
||
const uploadCellLevelMetadata = async (req, res) => { | ||
const { experimentId } = req.params; | ||
const { name, size } = req.body; | ||
|
||
const cellLevelMetaKey = uuidv4(); | ||
const bucketName = bucketNames.CELL_METADATA; | ||
const newCellLevelMetaFile = { | ||
id: cellLevelMetaKey, | ||
name, | ||
upload_status: 'uploading', | ||
}; | ||
const cellLevelMetaToExperimentMap = { | ||
experiment_id: experimentId, | ||
cell_metadata_file_id: cellLevelMetaKey, | ||
}; | ||
|
||
let uploadUrlParams; | ||
await sqlClient.get().transaction(async (trx) => { | ||
await new CellLevelMeta(trx).create(newCellLevelMetaFile); | ||
await new CellLevelMetaToExperiment(trx).create(cellLevelMetaToExperimentMap); | ||
uploadUrlParams = await getFileUploadUrls(cellLevelMetaKey, {}, size, bucketName); | ||
uploadUrlParams = { ...uploadUrlParams, fileId: cellLevelMetaKey }; | ||
}); | ||
|
||
res.json({ data: uploadUrlParams }); | ||
}; | ||
|
||
|
||
const updateCellLevelMetadata = async (req, res) => { | ||
const { params: { experimentId }, body } = req; | ||
const snakeCasedKeysToPatch = _.mapKeys(body, (_value, key) => _.snakeCase(key)); | ||
const { cellMetadataFileId } = await new CellLevelMetaToExperiment().find({ experiment_id: experimentId }).first(); | ||
await new CellLevelMeta().updateById(cellMetadataFileId, snakeCasedKeysToPatch); | ||
res.json(OK()); | ||
}; | ||
module.exports = { | ||
uploadCellLevelMetadata, | ||
updateCellLevelMetadata, | ||
}; |
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,30 @@ | ||
const { completeMultipartUpload } = require('../helpers/s3/signedUrl'); | ||
|
||
const bucketNames = require('../../config/bucketNames'); | ||
const getLogger = require('../../utils/getLogger'); | ||
const { OK, NotFoundError } = require('../../utils/responses'); | ||
|
||
const logger = getLogger(); | ||
const completeMultipartUploads = async (req, res) => { | ||
const { | ||
fileId, uploadId, parts, type, | ||
} = req.body; | ||
let bucketName; | ||
if (type === 'sample') { | ||
bucketName = bucketNames.SAMPLE_FILES; | ||
} else if (type === 'cellLevel') { | ||
bucketName = bucketNames.CELL_METADATA; | ||
} else { | ||
throw new NotFoundError('Invalid bucket specified'); | ||
} | ||
logger.log(`completing multipart upload for file ${fileId}`); | ||
|
||
await completeMultipartUpload(fileId, parts, uploadId, bucketName); | ||
|
||
logger.log(`completed multipart upload for file ${fileId}`); | ||
res.json(OK()); | ||
}; | ||
|
||
module.exports = { | ||
completeMultipartUploads, | ||
}; |
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,32 @@ | ||
const BasicModel = require('./BasicModel'); | ||
const sqlClient = require('../../sql/sqlClient'); | ||
const tableNames = require('./tableNames'); | ||
|
||
const fields = [ | ||
'id', | ||
'name', | ||
'upload_status', | ||
'created_at', | ||
]; | ||
|
||
class CellLevelMeta extends BasicModel { | ||
constructor(sql = sqlClient.get()) { | ||
super(sql, tableNames.CELL_LEVEL, fields); | ||
} | ||
|
||
async getMetadataByExperimentIds(experimentIds) { | ||
const result = await this.sql | ||
.select([...fields, `${tableNames.CELL_LEVEL_TO_EXPERIMENT_MAP}.experiment_id`]) | ||
.from(tableNames.CELL_LEVEL_TO_EXPERIMENT_MAP) | ||
.leftJoin( | ||
tableNames.CELL_LEVEL, | ||
`${tableNames.CELL_LEVEL_TO_EXPERIMENT_MAP}.cell_metadata_file_id`, | ||
`${tableNames.CELL_LEVEL}.id`, | ||
) | ||
.whereIn(`${tableNames.CELL_LEVEL_TO_EXPERIMENT_MAP}.experiment_id`, experimentIds); | ||
|
||
return result; | ||
} | ||
} | ||
|
||
module.exports = CellLevelMeta; |
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,16 @@ | ||
const BasicModel = require('./BasicModel'); | ||
const sqlClient = require('../../sql/sqlClient'); | ||
const tableNames = require('./tableNames'); | ||
|
||
const fields = [ | ||
'experiment_id', | ||
'cell_metadata_file_id', | ||
]; | ||
|
||
class CellLevelMetaToExperiment extends BasicModel { | ||
constructor(sql = sqlClient.get()) { | ||
super(sql, tableNames.CELL_LEVEL_TO_EXPERIMENT_MAP, fields); | ||
} | ||
} | ||
|
||
module.exports = CellLevelMetaToExperiment; |
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,10 @@ | ||
const BasicModel = require('./BasicModel')(); | ||
|
||
const stub = { | ||
getMetadataByExperimentIds: () => ([]), | ||
...BasicModel, | ||
}; | ||
|
||
const CellLevelMeta = jest.fn().mockImplementation(() => stub); | ||
|
||
module.exports = CellLevelMeta; |
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,16 @@ | ||
const { | ||
uploadCellLevelMetadata, updateCellLevelMetadata, | ||
} = require('../controllers/cellLevelMetaController'); | ||
|
||
const { expressAuthorizationMiddleware } = require('../middlewares/authMiddlewares'); | ||
|
||
module.exports = { | ||
'cellLevel#uploadCellLevelMetadata': [ | ||
expressAuthorizationMiddleware, | ||
(req, res, next) => uploadCellLevelMetadata(req, res).catch(next), | ||
], | ||
'cellLevel#updateCellLevelMetadata': [ | ||
expressAuthorizationMiddleware, | ||
(req, res, next) => updateCellLevelMetadata(req, res).catch(next), | ||
], | ||
}; |
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,7 @@ | ||
const { completeMultipartUploads } = require('../controllers/s3Upload'); | ||
|
||
module.exports = { | ||
's3Upload#completeMultipartUpload': [ | ||
(req, res, next) => completeMultipartUploads(req, res).catch(next), | ||
], | ||
}; |
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
Oops, something went wrong.