Skip to content

Commit c68b574

Browse files
Scottsaf6260
authored andcommitted
Updating backend for public go links (performed cleanup as well as setup
a new migration for the table information)
1 parent 510f77f commit c68b574

File tree

5 files changed

+29
-26
lines changed

5 files changed

+29
-26
lines changed

db/migrations/20150809163538-links.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ export function up(queryInterface, Sequelize) {
99
type: Sequelize.STRING,
1010
allowNull: false,
1111
},
12-
goDescription: {
13-
type: Sequelize.STRING,
14-
allowNull: false,
15-
},
16-
publicGO: {
17-
type: Sequelize.STRING,
18-
allowNull: false,
19-
},
2012
createdAt: Sequelize.DATE,
2113
updatedAt: Sequelize.DATE,
2214
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export function up(queryInterface, Sequelize) {
2+
return queryInterface.addColumn('links', 'description', {
3+
type: Sequelize.STRING,
4+
allowNull: true,
5+
})
6+
.then(() => queryInterface.addColumn('links', 'public', {
7+
type: Sequelize.BOOLEAN,
8+
allowNull: false,
9+
defaultValue: false,
10+
}));
11+
}
12+
13+
export function down(queryInterface) {
14+
return queryInterface.removeColumn('links', 'description')
15+
.then(() => queryInterface.removeColumn('links', 'public'));
16+
}

models/link.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,24 @@ export default sequelize.define('links', {
2121
},
2222
},
2323
},
24-
goDescription: {
24+
description: {
2525
type: DataTypes.STRING,
26-
allowNull: false,
27-
validate: {
28-
notEmpty: true
29-
}
26+
allowNull: true,
3027
},
31-
publicGO: {
32-
type: DataTypes.STRING,
28+
public: {
29+
type: DataTypes.BOOLEAN,
3330
allowNull: false,
34-
validate: {
35-
notEmpty: true
36-
},
3731
},
3832
}, {
3933
scopes: {
34+
onlyPublic() {
35+
return { where: { public: true } };
36+
},
4037
paginate,
4138
orderBy(field, direction) {
4239
return sorting(field, direction, [
4340
'shortLink',
4441
'longLink',
45-
'goDescription',
46-
'publicGO',
4742
'createdAt',
4843
'updatedAt',
4944
]);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"pg": "^4.4.1",
5959
"pg-hstore": "^2.3.2",
6060
"sequelize": "^3.19.0",
61-
"sqlite3": "^3.0.10",
61+
"sqlite3": "^3.1.13",
6262
"umzug": "^1.6.0"
6363
},
6464
"devDependencies": {

routes/links.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const router = Router(); // eslint-disable-line new-cap
1010
router
1111
.route('/')
1212
.get(paginate, sorting, (req, res, next) => {
13-
const scopes = scopify(req.query);
13+
const scopes = scopify(req.query, 'onlyPublic');
1414
Link.scope(scopes)
1515
.findAndCountAll({
1616
order: '"createdAt" DESC',
@@ -27,9 +27,9 @@ router
2727
Link.create({
2828
shortLink: req.body.shortLink.toLocaleLowerCase(),
2929
longLink: req.body.longLink,
30-
goDescription: req.body.goDescription,
31-
publicGO: req.body.publicGO,
32-
}, { fields: ['shortLink', 'longLink', 'goDescription', 'publicGO'] })
30+
description: req.body.description,
31+
public: req.body.public,
32+
}, { fields: ['shortLink', 'longLink', 'description', 'public'] })
3333
.then(link => res.status(201).send(link))
3434
.catch((err) => {
3535
err.status = 422;
@@ -73,7 +73,7 @@ router
7373
.then((link) => {
7474
if (link) {
7575
return link.updateAttributes(req.body, {
76-
fields: ['shortLink', 'longLink', 'goDescription', 'publicGO'],
76+
fields: ['shortLink', 'longLink', 'description', 'public'],
7777
});
7878
}
7979
return Promise.reject({ message: 'Link not found', status: 404 });

0 commit comments

Comments
 (0)