diff --git a/controllers/serveController.js b/controllers/serveController.js index c6d9be90..e5bbcd9f 100644 --- a/controllers/serveController.js +++ b/controllers/serveController.js @@ -221,9 +221,11 @@ module.exports = { return db.resolveClaim(fileInfo.name, fileInfo.claimId); }) .then(resolveResult => { + logger.debug('resolve result >>', resolveResult); fileInfo['thumbnail'] = chooseThumbnail(resolveResult, DEFAULT_THUMBNAIL); fileInfo['title'] = resolveResult.title; fileInfo['description'] = resolveResult.description; + if (resolveResult.certificateId) { fileInfo['certificateId'] = resolveResult.certificateId }; showFile(fileInfo, res); return fileInfo; }) diff --git a/migrations/UpdateAssociationColumns.js b/migrations/UpdateAssociationColumns.js deleted file mode 100644 index 22c6def9..00000000 --- a/migrations/UpdateAssociationColumns.js +++ /dev/null @@ -1,79 +0,0 @@ -module.exports = { - up: (queryInterface, Sequelize) => { - // logic for transforming into the new state - const p1 = queryInterface.removeColumn( - 'Certificate', - 'UserId' - ); - const p2 = queryInterface.addColumn( - 'Certificate', - 'ChannelId', - { - type : Sequelize.INTEGER, - allowNull: true, - } - ); - const p3 = queryInterface.addConstraint( - 'Certificate', - ['ChannelId'], - { - type : 'FOREIGN KEY', - name : 'Certificate_ibfk_1', - references: { - table: 'Channel', - field: 'id', - }, - onUpdate: 'cascade', - onDelete: 'cascade', - } - ); - const p4 = queryInterface.changeColumn( - 'Claim', - 'FileId', - { - type : Sequelize.INTEGER, - allowNull: true, - } - ); - const p5 = queryInterface.addConstraint( - 'Claim', - ['FileId'], - { - type : 'FOREIGN KEY', - name : 'Claim_ibfk_1', - references: { - table: 'File', - field: 'id', - }, - onUpdate: 'cascade', - onDelete: 'cascade', - } - ); - const p6 = queryInterface.removeColumn( - 'File', - 'UserId' - ); - - return Promise.all([p1, p2, p3, p4, p5, p6]); - }, - down: (queryInterface, Sequelize) => { - // logic for reverting the changes - const p1 = queryInterface.addColumn( - 'Certificate', - 'UserId', - { - type : Sequelize.INTEGER, - allowNull: true, - } - ); - const p2 = queryInterface.addColumn( - 'File', - 'UserId', - { - type : Sequelize.INTEGER, - allowNull: true, - } - ); - return Promise.all([p1, p2]); - }, -}; diff --git a/migrations/UpdateUserAndChannel.js b/migrations/UpdateUserAndChannel.js index 32c22097..b9ac1da8 100644 --- a/migrations/UpdateUserAndChannel.js +++ b/migrations/UpdateUserAndChannel.js @@ -2,45 +2,21 @@ module.exports = { up: (queryInterface, Sequelize) => { // logic for transforming into the new state const p1 = queryInterface.addColumn( - 'User', - 'userName', - { - type : Sequelize.STRING, - allowNull: true, - } - ); - const p2 = queryInterface.removeColumn( - 'User', - 'channelName' - ); - const p3 = queryInterface.removeColumn( - 'User', - 'channelClaimId' - ); - return Promise.all([p1, p2, p3]); - }, - down: (queryInterface, Sequelize) => { - // logic for reverting the changes - const p1 = queryInterface.removeColumn( - 'User', - 'userName' - ); - const p2 = queryInterface.addColumn( - 'User', + 'Claim', 'channelName', { type : Sequelize.STRING, allowNull: true, } ); - const p3 = queryInterface.addColumn( - 'User', - 'channelClaimId', - { - type : Sequelize.STRING, - allowNull: true, - } + return Promise.all([p1]); + }, + down: (queryInterface, Sequelize) => { + // logic for reverting the changes + const p1 = queryInterface.removeColumn( + 'Claim', + 'channelName' ); - return Promise.all([p1, p2, p3]); + return Promise.all([p1]); }, }; diff --git a/models/index.js b/models/index.js index 687b4a2a..79cf7e3b 100644 --- a/models/index.js +++ b/models/index.js @@ -235,7 +235,7 @@ db['getAllFreeClaims'] = (name) => { db['resolveClaim'] = (name, claimId) => { return new Promise((resolve, reject) => { db - .sequelize.query(`SELECT name, claimId, outpoint, height, address, title, description, thumbnail FROM Claim WHERE name = '${name}' AND claimId = '${claimId}'`, { type: db.sequelize.QueryTypes.SELECT }) + .sequelize.query(`SELECT name, claimId, outpoint, height, address, title, description, thumbnail, certificateId FROM Claim WHERE name = '${name}' AND claimId = '${claimId}'`, { type: db.sequelize.QueryTypes.SELECT }) .then(result => { switch (result.length) { case 0: