added votes
This commit is contained in:
parent
10091f28ff
commit
8db4e1ef54
32
db/index.js
32
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
|
Article.hasMany(Vote)
|
||||||
require('./models');
|
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
|
||||||
|
13
db/models/votes.js
Normal file
13
db/models/votes.js
Normal file
@ -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;
|
Loading…
Reference in New Issue
Block a user