Skip to content

Commit

Permalink
Merge pull request #180 from bcgsc/release/v7.7.0
Browse files Browse the repository at this point in the history
v7.7.0
  • Loading branch information
Nithriel authored Aug 11, 2022
2 parents 61a4a9a + ab39f98 commit a6e477f
Show file tree
Hide file tree
Showing 10 changed files with 357 additions and 9 deletions.
6 changes: 6 additions & 0 deletions app/models/germlineSmallMutation/variants.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ module.exports = (sequelize, Sq) => {
type: Sq.TEXT,
allowNull: true,
},
previouslyReported: {
name: 'previously_reported',
field: 'previously_reported',
type: Sq.TEXT,
allowNull: true,
},
}, {
...DEFAULT_OPTIONS,
tableName: 'germline_small_mutations_variant',
Expand Down
10 changes: 9 additions & 1 deletion app/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,14 +474,22 @@ template.hasMany(analysisReports, {
// Template Appendix
const templateAppendix = require('./template/templateAppendix')(sequelize, Sq);

template.hasOne(templateAppendix, {
template.hasMany(templateAppendix, {
as: 'appendix', foreignKey: 'templateId', targetKey: 'id', onDelete: 'CASCADE', constraints: true,
});

templateAppendix.belongsTo(template, {
as: 'template', foreignKey: 'templateId', targetKey: 'id', onDelete: 'CASCADE', constraints: true,
});

project.hasMany(templateAppendix, {
as: 'appendix', foreignKey: 'projectId', targetKey: 'id', onDelete: 'CASCADE', constraints: true,
});

templateAppendix.belongsTo(project, {
as: 'project', foreignKey: 'projectId', targetKey: 'id', onDelete: 'CASCADE', constraints: true,
});

// Germline Small Mutations
require('./germlineSmallMutation')(sequelize, Sq);

Expand Down
13 changes: 12 additions & 1 deletion app/models/template/templateAppendix.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ module.exports = (sequelize, Sq) => {
key: 'id',
},
},
projectId: {
name: 'projectId',
field: 'project_id',
type: Sq.INTEGER,
unique: false,
allowNull: true,
references: {
model: 'projects',
key: 'id',
},
},
text: {
type: Sq.TEXT,
},
Expand All @@ -30,7 +41,7 @@ module.exports = (sequelize, Sq) => {
// set instance methods
templateAppendix.prototype.view = function (scope) {
if (scope === 'public') {
const {id, templateId, deletedAt, updatedBy, ...publicView} = this.dataValues;
const {id, projectId, templateId, deletedAt, updatedBy, ...publicView} = this.dataValues;
return publicView;
}
return this;
Expand Down
28 changes: 26 additions & 2 deletions app/routes/report/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,33 @@ const IMAGES_CONFIG = [
format: 'PNG',
},
{
pattern: 'expression.spearman\\.(tcga|gtex|cser|hartwig|pediatric)',
pattern: 'expression.spearman.tcga',
width: 1100,
height: 1360,
height: 3000,
format: 'PNG',
},
{
pattern: 'expression.spearman.gtex',
width: 1100,
height: 4050,
format: 'PNG',
},
{
pattern: 'expression.spearman.cser',
width: 1100,
height: 1125,
format: 'PNG',
},
{
pattern: 'expression.spearman.hartwig',
width: 1100,
height: 1500,
format: 'PNG',
},
{
pattern: 'expression.spearman.pediatric',
width: 1100,
height: 2775,
format: 'PNG',
},
{
Expand Down
41 changes: 40 additions & 1 deletion app/routes/template/templateAppendix.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const HTTP_STATUS = require('http-status-codes');
const express = require('express');
const {Op} = require('sequelize');

const router = express.Router({mergeParams: true});

Expand All @@ -22,8 +23,33 @@ const updateSchema = schemaGenerator(db.models.templateAppendix, {
// Add middleware to get template appendix
router.use('/', async (req, res, next) => {
try {
if (req.body.projectId) {
req.project = await db.models.project.findOne({
where:
{ident: req.body.projectId},
});
} else {
req.project = null;
}

let projectId;
if (req.project) {
req.body.projectId = req.project.id;
projectId = req.project.id;
} else {
projectId = null;
}

req.templateAppendix = await db.models.templateAppendix.findOne({
where: {templateId: req.template.id},
where:
{
[Op.and]: [
{templateId: req.template.id},
{projectId},
],
},
include:
[{model: db.models.project.scope('public'), as: 'project'}],
});
} catch (error) {
logger.error(`Unable to get template appendix ${error}`);
Expand All @@ -32,6 +58,19 @@ router.use('/', async (req, res, next) => {
});
}

// Convert Project ID to ident in GET endpoint
if (req.project && req.templateAppendix && req.method === 'GET') {
req.templateAppendix.projectId = req.project.ident;
}

// Throw an error if Project ident is provided but not existent
if (!req.project && req.body.projectId) {
logger.error(`Invalid project ID for template appendix: ${req.body.projectId}`);
return res.status(HTTP_STATUS.NOT_FOUND).json({
error: {message: `Invalid project ID for template appendix: ${req.body.projectId}`},
});
}

// Throw an error for a POST when a template appendix already exists
if (req.templateAppendix && req.method === 'POST') {
logger.error(`Template appendix already exists for ${req.template.name}`);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const GERMLINE_SMALL_VARIANTS_TABLE = 'germline_small_mutations_variant';

module.exports = {
up: async (queryInterface, Sq) => {
return queryInterface.sequelize.transaction(async (transaction) => {
return Promise.all([
queryInterface.addColumn(GERMLINE_SMALL_VARIANTS_TABLE, 'previously_reported', Sq.TEXT, {transaction}),
]);
});
},

down: async () => {
throw new Error('Not Implemented!');
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const TEMPLATES_TABLE = 'templates_appendix';

module.exports = {
up: (queryInterface, Sq) => {
return queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.addColumn(TEMPLATES_TABLE, 'project_id', {
name: 'projectId',
field: 'project_id',
type: Sq.INTEGER,
unique: false,
allowNull: true,
references: {
model: 'projects',
key: 'id',
},
}, {transaction});
await queryInterface.sequelize.query(
'DROP INDEX templates_appendix_template_id_index;',
{transaction},
);
});
},

down: () => {
throw new Error('Not Implemented!');
},
};
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "ipr-api",
"version": "7.6.0",
"version": "7.7.0",
"description": "Integrated Pipeline Reports API",
"main": "bin/server.js",
"scripts": {
Expand Down
Loading

0 comments on commit a6e477f

Please sign in to comment.