412 blocked content #428
|
@ -1,22 +1,20 @@
|
|||
const db = require('../../../../models');
|
||||
|
||||
const { returnPaginatedChannelClaims } = require('./channelPagination.js');
|
||||
const NO_CHANNEL = 'NO_CHANNEL';
|
||||
|
||||
const getChannelClaims = (channelName, channelClaimId, page) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let longChannelClaimId;
|
||||
// 1. get the long channel Id (make sure channel exists)
|
||||
db.Certificate.getLongChannelId(channelName, channelClaimId)
|
||||
.then(longChannelClaimId => {
|
||||
if (!longChannelClaimId) {
|
||||
return [null, null, null];
|
||||
}
|
||||
// 2. get the short ID and all claims for that channel
|
||||
return Promise.all([longChannelClaimId, db.Claim.getAllChannelClaims(longChannelClaimId)]);
|
||||
db.Certificate
|
||||
.getLongChannelId(channelName, channelClaimId)
|
||||
.then(result => {
|
||||
longChannelClaimId = result;
|
||||
return db
|
||||
.Claim
|
||||
.getAllChannelClaims(longChannelClaimId);
|
||||
})
|
||||
.then(([longChannelClaimId, channelClaimsArray]) => {
|
||||
if (!longChannelClaimId) {
|
||||
return resolve(NO_CHANNEL);
|
||||
}
|
||||
.then(channelClaimsArray => {
|
||||
// 3. format the data for the view, including pagination
|
||||
let paginatedChannelViewData = returnPaginatedChannelClaims(channelName, longChannelClaimId, channelClaimsArray, page);
|
||||
// 4. return all the channel information and contents
|
||||
|
|
|
@ -16,12 +16,15 @@ const channelClaims = ({ ip, originalUrl, body, params }, res) => {
|
|||
const page = params.page;
|
||||
getChannelClaims(channelName, channelClaimId, page)
|
||||
.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});
|
||||
})
|
||||
.catch(error => {
|
||||
if (error === NO_CHANNEL) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: 'No matching channel was found',
|
||||
});
|
||||
}
|
||||
handleErrorResponse(originalUrl, ip, error, res);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,22 +1,18 @@
|
|||
good catch. I updated so any specific errors will get thrown (like 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.
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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 NO_CHANNEL = 'NO_CHANNEL';
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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) => {
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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) => {
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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) => {
|
||||
let longChannelClaimId;
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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)
|
||||
db.Certificate.getLongChannelId(channelName, channelClaimId)
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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 => {
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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) {
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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];
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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.
|
||||
}
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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)]);
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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.
|
||||
db.Certificate
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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.
|
||||
.getLongChannelId(channelName, channelClaimId)
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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(fullClaimId => {
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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.
|
||||
longChannelClaimId = fullClaimId;
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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.
|
||||
.Certificate
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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.
|
||||
.getShortChannelIdFromLongChannelId(fullClaimId, channelName);
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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]) => {
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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) {
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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);
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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.
|
||||
}
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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(shortChannelClaimId => {
|
||||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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({
|
||||
channelName,
|
||||
longChannelClaimId,
|
||||
|
|
|||
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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.
You could just return an empty array, unless you specifically need You could just return an empty array, unless you specifically need `xxx[3] === null`
good catch. I updated so any specific errors will get thrown (like 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.
|
|
@ -14,14 +14,20 @@ const channelData = ({ ip, originalUrl, body, params }, res) => {
|
|||
const channelName = params.channelName;
|
||||
let channelClaimId = params.channelClaimId;
|
||||
if (channelClaimId === 'none') channelClaimId = null;
|
||||
getChannelData(channelName, channelClaimId, 0)
|
||||
getChannelData(channelName, channelClaimId)
|
||||
.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 => {
|
||||
if (error === NO_CHANNEL) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: 'No matching channel was found',
|
||||
});
|
||||
}
|
||||
handleErrorResponse(originalUrl, ip, error, res);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -120,7 +120,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
|
|||
.then(result => {
|
||||
switch (result.length) {
|
||||
case 0:
|
||||
throw new Error('No channel(s) found with that channel name');
|
||||
return reject(NO_CHANNEL);
|
||||
default:
|
||||
return resolve(returnShortId(result, longChannelId));
|
||||
}
|
||||
|
|
You could just return an empty array, unless you specifically need
xxx[3] === null