From 158a0d468d00fae555369053d4af1d219f4b0368 Mon Sep 17 00:00:00 2001 From: Keith Kelleher Date: Wed, 10 Mar 2021 00:42:34 -0500 Subject: [PATCH] support data downloads --- src/models/DataModelList.ts | 5 +++++ src/models/config.ts | 2 +- src/models/databaseTable.ts | 9 ++++++--- src/resolvers.js | 17 +++++++++++++---- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/models/DataModelList.ts b/src/models/DataModelList.ts index f405a03..43aa248 100644 --- a/src/models/DataModelList.ts +++ b/src/models/DataModelList.ts @@ -210,6 +210,11 @@ export abstract class DataModelList { if (additionalWhereClause) { query.andWhere(this.database.raw(additionalWhereClause)); } + innerJoins[i].columns.forEach(col => { + if(col.where_clause){ + query.andWhere(that.database.raw(col.where_clause)); + } + }); } } this.addModelSpecificFiltering(query, true); diff --git a/src/models/config.ts b/src/models/config.ts index 1ae09fd..31fa66a 100644 --- a/src/models/config.ts +++ b/src/models/config.ts @@ -204,7 +204,7 @@ export class QueryDefinition { } const newTable = new SqlTable(reqData.table, {}, links, reqData.subQuery); - newTable.columns.push(new SqlColumns(reqData.data, reqData.alias, reqData.group_method)); + newTable.columns.push(new SqlColumns(reqData.data, reqData.alias, reqData.group_method, reqData.where_clause)); this.tables.push(newTable); } diff --git a/src/models/databaseTable.ts b/src/models/databaseTable.ts index 67ff219..d526690 100644 --- a/src/models/databaseTable.ts +++ b/src/models/databaseTable.ts @@ -59,7 +59,7 @@ export class DatabaseTable { /** * tables which should always be left joined to because they might not have a mapping */ - static sparseTables: string[] = ["tinx_novelty", "xref"]; + static sparseTables: string[] = ["tinx_novelty"]; /** * tables which have a data type column which describes the data the caller wants @@ -117,14 +117,17 @@ export class DatabaseTable { static requiredLinks: Map = new Map( [ - ["protein-target", ["t2tc"]], ["protein-viral_protein", ["viral_ppi", "virus"]], ["protein-virus", ["viral_ppi", "viral_protein"]], ["protein-dto", ["p2dto"]], ["protein-panther_class", ["p2pc"]], ["protein-virus", ["viral_protein", "viral_ppi"]], ["protein-viral_protein", ["virus", "viral_ppi"]], - ["protein-ncats_ligands", ["ncats_ligand_activity", "target", "t2tc"]] + + // checked + ["protein-target", ["t2tc"]], + ["protein-ncats_ligands", ["t2tc", "target", "ncats_ligand_activity"]], + ["protein-ncats_ligand_activity", ["t2tc", "target"]] ]); static getRequiredLinks(table1: string, table2: string): string[] | undefined { diff --git a/src/resolvers.js b/src/resolvers.js index a2f84f2..5b5f649 100644 --- a/src/resolvers.js +++ b/src/resolvers.js @@ -32,12 +32,21 @@ const resolvers = { Query: { download: async function (_, args, {dataSources}){ - const listObj = DataModelListFactory.getListObject(args.model, dataSources.tcrd, args); + let listQuery; + try { + const listObj = DataModelListFactory.getListObject(args.model, dataSources.tcrd, args); + listQuery = listObj.getListQuery(); + } + catch(e){ + return { + result: false, + errorDetails: e.message + } + } return { result: true, - data: args.sqlOnly ? null : listObj.getListQuery(), - sql: listObj.getListQuery().toString(), - errorDetails: dataSources.tcrd.tableInfo.facetMap + data: args.sqlOnly ? null : listQuery, + sql: listQuery.toString() }; },