412 blocked content #428

Merged
bones7242 merged 13 commits from 412-blocked_content into master 2018-05-01 01:07:59 +02:00
5 changed files with 38 additions and 35 deletions
Showing only changes of commit 69ebce3efd - Show all commits

View file

@ -1,22 +1,20 @@
const db = require('../../../../models'); const db = require('../../../../models');
const { returnPaginatedChannelClaims } = require('./channelPagination.js'); const { returnPaginatedChannelClaims } = require('./channelPagination.js');
const NO_CHANNEL = 'NO_CHANNEL';
const getChannelClaims = (channelName, channelClaimId, page) => { const getChannelClaims = (channelName, channelClaimId, page) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let longChannelClaimId;
// 1. get the long channel Id (make sure channel exists) // 1. get the long channel Id (make sure channel exists)
db.Certificate.getLongChannelId(channelName, channelClaimId) db.Certificate
.then(longChannelClaimId => { .getLongChannelId(channelName, channelClaimId)
if (!longChannelClaimId) { .then(result => {
return [null, null, null]; longChannelClaimId = result;
} return db
// 2. get the short ID and all claims for that channel .Claim
return Promise.all([longChannelClaimId, db.Claim.getAllChannelClaims(longChannelClaimId)]); .getAllChannelClaims(longChannelClaimId);
}) })
.then(([longChannelClaimId, channelClaimsArray]) => { .then(channelClaimsArray => {
if (!longChannelClaimId) {
return resolve(NO_CHANNEL);
}
// 3. format the data for the view, including pagination // 3. format the data for the view, including pagination
let paginatedChannelViewData = returnPaginatedChannelClaims(channelName, longChannelClaimId, channelClaimsArray, page); let paginatedChannelViewData = returnPaginatedChannelClaims(channelName, longChannelClaimId, channelClaimsArray, page);
// 4. return all the channel information and contents // 4. return all the channel information and contents

View file

@ -16,12 +16,15 @@ const channelClaims = ({ ip, originalUrl, body, params }, res) => {
const page = params.page; const page = params.page;
getChannelClaims(channelName, channelClaimId, page) getChannelClaims(channelName, channelClaimId, page)
.then(data => { .then(data => {
if (data === NO_CHANNEL) {
return res.status(404).json({success: false, message: 'No matching channel was found'});
}
res.status(200).json({success: true, data}); res.status(200).json({success: true, data});
}) })
.catch(error => { .catch(error => {
if (error === NO_CHANNEL) {
return res.status(404).json({
success: false,
message: 'No matching channel was found',
});
}
handleErrorResponse(originalUrl, ip, error, res); handleErrorResponse(originalUrl, ip, error, res);
}); });
}; };

View file

@ -1,22 +1,18 @@
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
const db = require('../../../../models'); const db = require('../../../../models');
const NO_CHANNEL = 'NO_CHANNEL';
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
const getChannelData = (channelName, channelClaimId, page) => { const getChannelData = (channelName, channelClaimId) => {
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let longChannelClaimId;
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
// 1. get the long channel Id (make sure channel exists) // 1. get the long channel Id (make sure channel exists)
db.Certificate.getLongChannelId(channelName, channelClaimId) db.Certificate
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
.then(longChannelClaimId => { .getLongChannelId(channelName, channelClaimId)
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
if (!longChannelClaimId) { .then(fullClaimId => {
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
return [null, null, null]; longChannelClaimId = fullClaimId;
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
} return db
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
// 2. get the short ID and all claims for that channel .Certificate
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
return Promise.all([longChannelClaimId, db.Certificate.getShortChannelIdFromLongChannelId(longChannelClaimId, channelName)]); .getShortChannelIdFromLongChannelId(fullClaimId, channelName);
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
}) })
.then(([longChannelClaimId, shortChannelClaimId]) => { .then(shortChannelClaimId => {
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
if (!longChannelClaimId) {
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
return resolve(NO_CHANNEL);
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
}
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
// 3. return all the channel information
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
resolve({ resolve({
channelName, channelName,
longChannelClaimId, longChannelClaimId,

neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.
neb-b commented 2018-04-30 05:11:42 +02:00 (Migrated from github.com)
Review

You could just return an empty array, unless you specifically need xxx[3] === null

You could just return an empty array, unless you specifically need `xxx[3] === null`
bones7242 commented 2018-05-01 01:07:45 +02:00 (Migrated from github.com)
Review

good catch. I updated so any specific errors will get thrown (like NO_CHANNEL), like I did with the claims controllers. That streamlines this chain a lot better.

good catch. I updated so any specific errors will get thrown (like `NO_CHANNEL`), like I did with the claims controllers. That streamlines this chain a lot better.

View file

@ -14,14 +14,20 @@ const channelData = ({ ip, originalUrl, body, params }, res) => {
const channelName = params.channelName; const channelName = params.channelName;
let channelClaimId = params.channelClaimId; let channelClaimId = params.channelClaimId;
if (channelClaimId === 'none') channelClaimId = null; if (channelClaimId === 'none') channelClaimId = null;
getChannelData(channelName, channelClaimId, 0) getChannelData(channelName, channelClaimId)
.then(data => { .then(data => {
if (data === NO_CHANNEL) { res.status(200).json({
return res.status(404).json({success: false, message: 'No matching channel was found'}); success: true,
} data
res.status(200).json({success: true, data}); });
}) })
.catch(error => { .catch(error => {
if (error === NO_CHANNEL) {
return res.status(404).json({
success: false,
message: 'No matching channel was found',
});
}
handleErrorResponse(originalUrl, ip, error, res); handleErrorResponse(originalUrl, ip, error, res);
}); });
}; };

View file

@ -120,7 +120,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
.then(result => { .then(result => {
switch (result.length) { switch (result.length) {
case 0: case 0:
throw new Error('No channel(s) found with that channel name'); return reject(NO_CHANNEL);
default: default:
return resolve(returnShortId(result, longChannelId)); return resolve(returnShortId(result, longChannelId));
} }