Skip to content

Commit

Permalink
Updating backend for public go links (performed cleanup as well as setup
Browse files Browse the repository at this point in the history
a new migration for the table information)
  • Loading branch information
Scott authored and saf6260 committed Mar 16, 2019
1 parent 510f77f commit c68b574
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
8 changes: 0 additions & 8 deletions db/migrations/20150809163538-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ export function up(queryInterface, Sequelize) {
type: Sequelize.STRING,
allowNull: false,
},
goDescription: {
type: Sequelize.STRING,
allowNull: false,
},
publicGO: {
type: Sequelize.STRING,
allowNull: false,
},
createdAt: Sequelize.DATE,
updatedAt: Sequelize.DATE,
});
Expand Down
16 changes: 16 additions & 0 deletions db/migrations/20190223151710-add-columns-to-links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export function up(queryInterface, Sequelize) {
return queryInterface.addColumn('links', 'description', {
type: Sequelize.STRING,
allowNull: true,
})
.then(() => queryInterface.addColumn('links', 'public', {
type: Sequelize.BOOLEAN,
allowNull: false,
defaultValue: false,
}));
}

export function down(queryInterface) {
return queryInterface.removeColumn('links', 'description')
.then(() => queryInterface.removeColumn('links', 'public'));
}
19 changes: 7 additions & 12 deletions models/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,24 @@ export default sequelize.define('links', {
},
},
},
goDescription: {
description: {
type: DataTypes.STRING,
allowNull: false,
validate: {
notEmpty: true
}
allowNull: true,
},
publicGO: {
type: DataTypes.STRING,
public: {
type: DataTypes.BOOLEAN,
allowNull: false,
validate: {
notEmpty: true
},
},
}, {
scopes: {
onlyPublic() {
return { where: { public: true } };
},
paginate,
orderBy(field, direction) {
return sorting(field, direction, [
'shortLink',
'longLink',
'goDescription',
'publicGO',
'createdAt',
'updatedAt',
]);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"pg": "^4.4.1",
"pg-hstore": "^2.3.2",
"sequelize": "^3.19.0",
"sqlite3": "^3.0.10",
"sqlite3": "^3.1.13",
"umzug": "^1.6.0"
},
"devDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions routes/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const router = Router(); // eslint-disable-line new-cap
router
.route('/')
.get(paginate, sorting, (req, res, next) => {
const scopes = scopify(req.query);
const scopes = scopify(req.query, 'onlyPublic');
Link.scope(scopes)
.findAndCountAll({
order: '"createdAt" DESC',
Expand All @@ -27,9 +27,9 @@ router
Link.create({
shortLink: req.body.shortLink.toLocaleLowerCase(),
longLink: req.body.longLink,
goDescription: req.body.goDescription,
publicGO: req.body.publicGO,
}, { fields: ['shortLink', 'longLink', 'goDescription', 'publicGO'] })
description: req.body.description,
public: req.body.public,
}, { fields: ['shortLink', 'longLink', 'description', 'public'] })
.then(link => res.status(201).send(link))
.catch((err) => {
err.status = 422;
Expand Down Expand Up @@ -73,7 +73,7 @@ router
.then((link) => {
if (link) {
return link.updateAttributes(req.body, {
fields: ['shortLink', 'longLink', 'goDescription', 'publicGO'],
fields: ['shortLink', 'longLink', 'description', 'public'],
});
}
return Promise.reject({ message: 'Link not found', status: 404 });
Expand Down

0 comments on commit c68b574

Please sign in to comment.