Skip to content

Commit

Permalink
changed cellLevel to cellLevelMeta
Browse files Browse the repository at this point in the history
Signed-off-by: stefanbabukov <[email protected]>
  • Loading branch information
StefanBabukov committed Oct 4, 2023
1 parent 000b8cb commit c586e59
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@ const { v4: uuidv4 } = require('uuid');
const _ = require('lodash');
const bucketNames = require('../../config/bucketNames');
const sqlClient = require('../../sql/sqlClient');
const CellLevel = require('../model/CellLevel');
const CellLevelToExperiment = require('../model/CellLevelToExperiment');
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 cellLevelKey = uuidv4();
const cellLevelMetaKey = uuidv4();
const bucketName = bucketNames.CELL_METADATA;
const newCellLevelFile = {
id: cellLevelKey,
const newCellLevelMetaFile = {
id: cellLevelMetaKey,
name,
upload_status: 'uploading',
};
const cellLevelToExperimentMap = {
const cellLevelMetaToExperimentMap = {
experiment_id: experimentId,
cell_metadata_file_id: cellLevelKey,
cell_metadata_file_id: cellLevelMetaKey,
};

let uploadUrlParams;
await sqlClient.get().transaction(async (trx) => {
await new CellLevel(trx).create(newCellLevelFile);
await new CellLevelToExperiment(trx).create(cellLevelToExperimentMap);
uploadUrlParams = await getFileUploadUrls(cellLevelKey, {}, size, bucketName);
uploadUrlParams = { ...uploadUrlParams, fileId: cellLevelKey };
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 });
Expand All @@ -38,8 +38,8 @@ const uploadCellLevelMetadata = async (req, res) => {
const updateCellLevelMetadata = async (req, res) => {
const { params: { experimentId }, body } = req;
const snakeCasedKeysToPatch = _.mapKeys(body, (_value, key) => _.snakeCase(key));
const { cellMetadataFileId } = await new CellLevelToExperiment().find({ experiment_id: experimentId }).first();
await new CellLevel().updateById(cellMetadataFileId, snakeCasedKeysToPatch);
const { cellMetadataFileId } = await new CellLevelMetaToExperiment().find({ experiment_id: experimentId }).first();
await new CellLevelMeta().updateById(cellMetadataFileId, snakeCasedKeysToPatch);
res.json(OK());
};
module.exports = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const fields = [
'created_at',
];

class CellLevel extends BasicModel {
class CellLevelMeta extends BasicModel {
constructor(sql = sqlClient.get()) {
super(sql, tableNames.CELL_LEVEL, fields);
}
Expand All @@ -29,4 +29,4 @@ class CellLevel extends BasicModel {
}
}

module.exports = CellLevel;
module.exports = CellLevelMeta;
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const fields = [
'cell_metadata_file_id',
];

class CellLevelToExperiment extends BasicModel {
class CellLevelMetaToExperiment extends BasicModel {
constructor(sql = sqlClient.get()) {
super(sql, tableNames.CELL_LEVEL_TO_EXPERIMENT_MAP, fields);
}
}

module.exports = CellLevelToExperiment;
module.exports = CellLevelMetaToExperiment;
8 changes: 4 additions & 4 deletions src/api.v2/model/Experiment.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { v4: uuidv4 } = require('uuid');
const BasicModel = require('./BasicModel');
const sqlClient = require('../../sql/sqlClient');
const { collapseKeyIntoArray, replaceNullsWithObject } = require('../../sql/helpers');
const CellLevel = require('./CellLevel');
const CellLevelMeta = require('./CellLevelMeta');
const { NotFoundError, BadRequestError } = require('../../utils/responses');
const tableNames = require('./tableNames');
const config = require('../../config');
Expand Down Expand Up @@ -77,11 +77,11 @@ class Experiment extends BasicModel {
this.sql,
);

const cellLevel = new CellLevel();
const cellLevelMeta = new CellLevelMeta();
const experimentIds = experiments.map((experiment) => experiment.id);
const cellLevelResults = await cellLevel.getMetadataByExperimentIds(experimentIds);
const cellLevelMetaResults = await cellLevelMeta.getMetadataByExperimentIds(experimentIds);

cellLevelResults.forEach(
cellLevelMetaResults.forEach(
(cellLevelMetaResult) => {
const experimentIndx = experiments.findIndex(
(experiment) => experiment.id === cellLevelMetaResult.experimentId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ const stub = {
...BasicModel,
};

const CellLevel = jest.fn().mockImplementation(() => stub);
const CellLevelMeta = jest.fn().mockImplementation(() => stub);

module.exports = CellLevel;
module.exports = CellLevelMeta;
2 changes: 1 addition & 1 deletion src/api.v2/routes/cellLevel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {
uploadCellLevelMetadata, updateCellLevelMetadata,
} = require('../controllers/cellLevelController');
} = require('../controllers/cellLevelMetaController');

const { expressAuthorizationMiddleware } = require('../middlewares/authMiddlewares');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-nocheck
const { mockSqlClient } = require('../mocks/getMockSqlClient')();
const CellLevel = require('../../../src/api.v2/model/CellLevel');
const CellLevel = require('../../../src/api.v2/model/CellLevelMeta');

jest.mock('../../../src/sql/sqlClient', () => ({
get: jest.fn(() => mockSqlClient),
Expand Down
2 changes: 1 addition & 1 deletion tests/api.v2/model/Experiment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jest.mock('../../../src/sql/helpers', () => ({
'{}'::jsonb
) as pipelines,}),`),
}));
jest.mock('../../../src/api.v2/model/CellLevel');
jest.mock('../../../src/api.v2/model/CellLevelMeta');
const Experiment = require('../../../src/api.v2/model/Experiment');
const constants = require('../../../src/utils/constants');
const tableNames = require('../../../src/api.v2/model/tableNames');
Expand Down

0 comments on commit c586e59

Please sign in to comment.