From 2227ede6e9145358e51aa94d41f23342b40b945d Mon Sep 17 00:00:00 2001 From: Jessop Breth Date: Sun, 25 Nov 2018 23:54:23 -0500 Subject: [PATCH] fixes blank tiles due to unsupported content --- server/chainquery/bundle.js | 34 +++++++++++++++---- server/chainquery/queries/claimQueries.js | 34 +++++++++++++++---- .../api/channel/claims/getChannelClaims.js | 10 ++++-- 3 files changed, 62 insertions(+), 16 deletions(-) diff --git a/server/chainquery/bundle.js b/server/chainquery/bundle.js index e97ae49a..60aca215 100644 --- a/server/chainquery/bundle.js +++ b/server/chainquery/bundle.js @@ -869,15 +869,35 @@ var claimQueries = (db, table, sequelize) => ({ }); }, - getAllChannelClaims: async (channelClaimId, bidState) => { + getAllChannelClaims: async (channelClaimId, params) => { logger$1.debug(`claim.getAllChannelClaims for ${channelClaimId}`); - const whereClause = bidState || { - [sequelize.Op.or]: [ - { bid_state: 'Controlling' }, - { bid_state: 'Active' }, - { bid_state: 'Accepted' }, - ], + + const defaultWhereClauses = { + bid_state: + { [sequelize.Op.or]: ['Controlling', 'Active', 'Accepted'] } }; + + const addWhereClauses = (whereClauses, params) => { + /* + input params = { col: ['Val', 'Val']} + output = { col: { Op.or : [ { Op.eq: 'Value'},...]}, col2:...} + */ + const cols = Object.keys(params); + for (let colKey in cols){ + let col = Object.keys(params)[colKey]; + + whereClauses[col] = {}; + whereClauses[col][sequelize.Op.or] = []; + for (let itemKey in params[col] ){ + let itemsArr = params[col]; + whereClauses[col][sequelize.Op.or].push({ [sequelize.Op.eq]: itemsArr[itemKey] }); + } + } + return whereClauses; + }; + + const whereClause = addWhereClauses(defaultWhereClauses, params); + const selectWhere = { ...whereClause, publisher_id: channelClaimId, diff --git a/server/chainquery/queries/claimQueries.js b/server/chainquery/queries/claimQueries.js index 185959ae..8cba61c2 100644 --- a/server/chainquery/queries/claimQueries.js +++ b/server/chainquery/queries/claimQueries.js @@ -68,15 +68,35 @@ export default (db, table, sequelize) => ({ }); }, - getAllChannelClaims: async (channelClaimId, bidState) => { + getAllChannelClaims: async (channelClaimId, params) => { logger.debug(`claim.getAllChannelClaims for ${channelClaimId}`); - const whereClause = bidState || { - [sequelize.Op.or]: [ - { bid_state: 'Controlling' }, - { bid_state: 'Active' }, - { bid_state: 'Accepted' }, - ], + + const defaultWhereClauses = { + bid_state: + { [sequelize.Op.or]: ['Controlling', 'Active', 'Accepted'] } }; + + const addWhereClauses = (whereClauses, params) => { + /* + input params = { col: ['Val', 'Val']} + output = { col: { Op.or : [ { Op.eq: 'Value'},...]}, col2:...} + */ + const cols = Object.keys(params) + for (let colKey in cols){ + let col = Object.keys(params)[colKey] + + whereClauses[col] = {} + whereClauses[col][sequelize.Op.or] = [] + for (let itemKey in params[col] ){ + let itemsArr = params[col] + whereClauses[col][sequelize.Op.or].push({ [sequelize.Op.eq]: itemsArr[itemKey] }) + } + } + return whereClauses; + } + + const whereClause = addWhereClauses(defaultWhereClauses, params); + const selectWhere = { ...whereClause, publisher_id: channelClaimId, diff --git a/server/controllers/api/channel/claims/getChannelClaims.js b/server/controllers/api/channel/claims/getChannelClaims.js index 90a9c2c7..61c2c639 100644 --- a/server/controllers/api/channel/claims/getChannelClaims.js +++ b/server/controllers/api/channel/claims/getChannelClaims.js @@ -5,10 +5,16 @@ const { returnPaginatedChannelClaims } = require('./channelPagination.js'); const getChannelClaims = async (channelName, channelShortId, page) => { const channelId = await chainquery.claim.queries.getLongClaimId(channelName, channelShortId); - + const params = { content_type: [ + 'image/jpeg', + 'image/jpg', + 'image/png', + 'image/gif', + 'video/mp4', + ] }; let channelClaims; if (channelId) { - channelClaims = await chainquery.claim.queries.getAllChannelClaims(channelId); + channelClaims = await chainquery.claim.queries.getAllChannelClaims(channelId, params); } const processingChannelClaims = channelClaims ? channelClaims.map((claim) => getClaimData(claim)) : []; -- 2.45.2