From 8db4e1ef541fddc1661a1314cd6cd358fda1d91b Mon Sep 17 00:00:00 2001 From: notnull Date: Wed, 13 Feb 2019 08:08:41 -0800 Subject: [PATCH] added votes --- db/index.js | 32 ++++++++++++++++++++++++++++---- db/models/votes.js | 13 +++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 db/models/votes.js diff --git a/db/index.js b/db/index.js index eabce22..04639cb 100755 --- a/db/index.js +++ b/db/index.js @@ -1,6 +1,30 @@ -const db = require('./db'); +const db = require('./db') +const {Article, Vote, User} = require('./models'); +// sigh +// I am using Sequelize as an ORM for the database. +// It has its own syntax for defining the relations +// in the database. Something like the following: +Article.belongsTo(User) +User.hasMany(Article) -// register models -require('./models'); +Article.hasMany(Vote) +Vote.belongsTo(Article) -module.exports = db; +Vote.belongsTo(User) +User.hasMany(Vote) + +// the questions are: +// 1. how to store votes in the database? as a count on the article? this would be less accurate but ok for the beginning <- I am not a fan of this approach +// 2. what votes do we count? (anon, per ip address, cookies?) to build relations between votes we need a concept of users based identification <- yep! +// 3. also downvotes? <- so I think to start we shoudl copy what HN does agreed :) +// TODO figure out how HN implements votes (I think non-registered voters can't vote for example) +// re: users: I can implement some hacky user auth to start with... or maybe that's something we delegate to rw (totally_not_fb) +// hn voting +// regiistration required +// min karma required for downvoting (comments only?) +// so we could start writing tickets at this point ... ? makes sense +// view content: https://irc.anarchyplanet.org/git/notnull/hacker-news-cli/issues/4 +// post content: https://irc.anarchyplanet.org/git/notnull/hacker-news-cli/issues/3 +// votes: https://irc.anarchyplanet.org/git/notnull/hacker-news-cli/issues/5 + +module.exports = db diff --git a/db/models/votes.js b/db/models/votes.js new file mode 100644 index 0000000..6bb37fc --- /dev/null +++ b/db/models/votes.js @@ -0,0 +1,13 @@ +const Sequelize = require('sequelize'); +const db = require('../db'); + +// votes should be up or down, could either do 'up/'down' or 1/-1 +const Vote = db.define('votes', { + valence: { + type: Sequelize.ENUM, + allowNull: false + } + +}); + +module.exports = Vote;