Skip to content

Commit

Permalink
Merge pull request #301 from bcgsc/release/v7.20.0
Browse files Browse the repository at this point in the history
Release/v7.20.0
  • Loading branch information
Nithriel authored Feb 13, 2024
2 parents b96c08b + 83862c4 commit bdb0825
Show file tree
Hide file tree
Showing 14 changed files with 367 additions and 82 deletions.
16 changes: 10 additions & 6 deletions app/middleware/acl.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,16 @@ module.exports = async (req, res, next) => {
if (req.report) {
// check if user is bound to report depending on report type
let boundUser;
if (req.report.biofxAssigned) {
boundUser = req.report.biofxAssigned.ident === req.user.ident;
} else {
boundUser = req.report.users.some((reportUser) => {
return reportUser.user.ident === req.user.ident;
}) || req.report.createdBy?.ident === req.user.ident;
try {
if (req.report.biofxAssigned) {
boundUser = req.report.biofxAssigned.ident === req.user.ident;
} else {
boundUser = req.report.users.some((reportUser) => {
return reportUser.user.ident === req.user.ident;
}) || req.report.createdBy?.ident === req.user.ident;
}
} catch {
logger.error('Error while retrieving bound user');
}

// If the user doesn't have access to the project this report
Expand Down
4 changes: 0 additions & 4 deletions app/models/reports/kbMatches.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ module.exports = (sequelize, Sq) => {
sample: {
type: Sq.TEXT,
},
inferred: {
type: Sq.BOOLEAN,
defaultValue: false,
},
evidenceLevel: {
name: 'evidenceLevel',
field: 'evidence_level',
Expand Down
16 changes: 2 additions & 14 deletions app/models/reports/mutationBurden.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ module.exports = (sequelize, Sq) => {
},
},
role: {
type: Sq.ENUM(['primary', 'secondary', 'tertiary', 'quaternary']),
allowNull: false,
type: Sq.ENUM(['primary', 'secondary', 'tertiary', 'quaternary', null]),
defaultValue: null,
},
codingSnvCount: {
name: 'codingSnvCount',
Expand Down Expand Up @@ -115,18 +115,6 @@ module.exports = (sequelize, Sq) => {
}, {
...DEFAULT_REPORT_OPTIONS,
tableName: 'reports_mutation_burden',
indexes: [
...DEFAULT_REPORT_OPTIONS.indexes,
{
unique: true,
fields: ['report_id', 'role'],
where: {
deleted_at: {
[Sq.Op.eq]: null,
},
},
},
],
scopes: {
public: {
attributes: {
Expand Down
30 changes: 29 additions & 1 deletion app/routes/report/immuneCellTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ const cache = require('../../cache');

const schemaGenerator = require('../../schemas/schemaGenerator');
const validateAgainstSchema = require('../../libs/validateAgainstSchema');
const {REPORT_UPDATE_BASE_URI} = require('../../constants');
const {REPORT_UPDATE_BASE_URI, REPORT_CREATE_BASE_URI} = require('../../constants');
const {REPORT_EXCLUDE} = require('../../schemas/exclude');

// Generate schema's
const createSchema = schemaGenerator(db.models.immuneCellTypes, {
baseUri: REPORT_CREATE_BASE_URI, exclude: REPORT_EXCLUDE,
});
const updateSchema = schemaGenerator(db.models.immuneCellTypes, {
baseUri: REPORT_UPDATE_BASE_URI, nothingRequired: true,
});
Expand Down Expand Up @@ -105,6 +109,30 @@ router.route('/')
error: {message: 'Unable to retrieve immune cell types'},
});
}
})
.post(async (req, res) => {
try {
// validate against the model
validateAgainstSchema(createSchema, req.body);
} catch (error) {
const message = `There was an error validating the Immune Cell Type create request ${error}`;
logger.error(message);
return res.status(HTTP_STATUS.BAD_REQUEST).json({error: {message}});
}

try {
// Add new Immune Cell Type to report
const result = await db.models.immuneCellTypes.create({
...req.body,
reportId: req.report.id,
});
return res.status(HTTP_STATUS.CREATED).json(result.view('public'));
} catch (error) {
logger.error(`Unable to create new Immune Cell Type ${error}`);
return res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).json({
error: {message: 'Unable to create new Immune Cell Type'},
});
}
});

module.exports = router;
2 changes: 1 addition & 1 deletion app/routes/report/tmburMutationBurden.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ router.use('/', async (req, res, next) => {
});
}

if (!result) {
if (!result && req.method !== 'POST') {
logger.error(`Unable to find Tmbur Mutation Burden for report ${req.report.ident}`);
return res.status(HTTP_STATUS.NOT_FOUND).json({
error: {message: `Unable to find Tmbur Mutation Burden for report ${req.report.ident}`},
Expand Down
Loading

0 comments on commit bdb0825

Please sign in to comment.