From 7bcec8bcf29b8c050e79e752423dbd99f96d4db6 Mon Sep 17 00:00:00 2001 From: Is Isilon Date: Fri, 22 Jan 2016 17:18:04 +0800 Subject: [PATCH] Updated versions --- db/seed/initial_tasks.js | 2 +- package.json | 57 ++++++++++---------- server.js | 110 ++++++++++++++++++++------------------- 3 files changed, 87 insertions(+), 82 deletions(-) diff --git a/db/seed/initial_tasks.js b/db/seed/initial_tasks.js index cb740c0..8090b48 100644 --- a/db/seed/initial_tasks.js +++ b/db/seed/initial_tasks.js @@ -2,7 +2,7 @@ var config = require('config'), orm = require('../../orm').configure(config.get('database')), Tasks = require('../../db/models/task').instance(orm); -Tasks.destroy().success(function() { +Tasks.destroy({where: {}}).then(function() { Tasks.bulkCreate([ {content: 'Welcome to HackFlowy!', isCompleted: false}, {content: 'An open-source WorkFlowy clone', isCompleted: false}, diff --git a/package.json b/package.json index 42e1830..fa63dd2 100644 --- a/package.json +++ b/package.json @@ -1,30 +1,31 @@ { - "name": "hackflowy", - "version": "0.0.1", - "description": "A simple WorkFlowy clone", - "dependencies": { - "express": "~3.1.0", - "path": "~0.4.9", - "pg": "~3.4.1", - "sequelize": "~1.7.9", - "socket.io": "~1.0.6", - "config": "~1.0.2" - }, - "devDependencies": { - "sqlite3": "~2.1.0" - }, - "engines": { - "node": "0.10.x", - "npm": "3.3.5" - }, - "scripts": { - "start": "node server.js", - "db:migrate": "./node_modules/sequelize/bin/sequelize -m --config config/database.json", - "db:seed": "node db/seed/initial_tasks.js", - "postinstall": "npm run db:migrate && npm run db:seed" - }, - "repository": { - "type": "git", - "url": "git://github.com/abhshkdz/HackFlowy.git" - } + "name": "hackflowy", + "version": "0.0.2", + "description": "A simple WorkFlowy clone", + "dependencies": { + "config": "~1.19.0", + "express": "<4.0.0", + "path": "~0.12.7", + "pg": "~3.4.1", + "sequelize": "~3.17.3", + "sequelize-cli": "^2.3.1", + "socket.io": "~1.4.4" + }, + "devDependencies": { + "sqlite3": "~3.1.1" + }, + "engines": { + "node": "5.4.x", + "npm": "3.3.11" + }, + "scripts": { + "start": "node server.js", + "db:migrate": "./node_modules/.bin/sequelize -m --config config/database.json", + "db:seed": "node db/seed/initial_tasks.js", + "postinstall": "npm run db:migrate && npm run db:seed" + }, + "repository": { + "type": "git", + "url": "git://github.com/abhshkdz/HackFlowy.git" + } } diff --git a/server.js b/server.js index 9e406fa..6a2f9d7 100644 --- a/server.js +++ b/server.js @@ -1,64 +1,68 @@ var application_root = __dirname, - express = require('express'), - app = express(), - path = require('path'), - config = require('config'), - orm = require('./orm').configure(config.get('database')), - Tasks = require('./db/models/task').instance(orm), - server = require('http').createServer(app), - io = require('socket.io').listen(server); + express = require('express'), + app = express(), + path = require('path'), + config = require('config'), + orm = require('./orm').configure(config.get('database')), + Tasks = require('./db/models/task').instance(orm), + server = require('http').createServer(app), + socket = require('socket.io') -app.configure(function() { - app.use(express.bodyParser()); - app.use(express.methodOverride()); - app.use(app.router); - app.use(express.static( path.join( application_root, 'public'))); - app.use(express.errorHandler({dumpExceptions: true, showStack: true})); -}); + +app.use(express.bodyParser()); +app.use(express.methodOverride()); +app.use(app.router); +app.use(express.static(path.join(application_root, 'public'))); +app.use(express.errorHandler({ + dumpExceptions: true, + showStack: true +})); var port = process.env.PORT || config.get('port'); -server.listen(port, function() { - console.log( 'Express server listening on port %d in %s mode', port, app.settings.env ); +server.listen(port, function () { + console.log('Express server listening on port %d in %s mode', port, app.settings.env); }); +var io = socket.listen(server); -app.get('/tasks', function(req,res){ - Tasks.all().success(function(tasks){ - res.send(tasks); - }); -}); - -app.post('/tasks', function(req,res){ - Tasks.create({ - content: req.body.content, - parent: parseInt(req.body.parent) || 0, - isCompleted: false - }).success(function(task){ - res.send(task); - }); -}); - -app.put('/tasks/:id', function(req,res){ - console.log(req.body.isCompleted); - Tasks.find(req.params.id).success(function(task){ - task.content = req.body.content; - task.parent = parseInt(req.body.parent) || 0, - task.isCompleted = req.body.isCompleted == 1; - task.save().success(function(task){ - res.send(task); - }) - }); -}); - -app.delete('/tasks/:id', function(req,res){ - Tasks.find(req.params.id).success(function(task){ - task.destroy().success(function(){ - res.send(''); +app.get('/tasks', function (req, res) { + Tasks.all().then(function (tasks) { + res.send(tasks); + }); +}); + +app.post('/tasks', function (req, res) { + Tasks.create({ + content: req.body.content, + parent: parseInt(req.body.parent) || 0, + isCompleted: false + }).then(function (task) { + res.send(task); + }); +}); + +app.put('/tasks/:id', function (req, res) { + console.log(req.body.isCompleted); + Tasks.findById(req.params.id).then(function (task) { + task.content = req.body.content; + task.parent = parseInt(req.body.parent) || 0, + task.isCompleted = req.body.isCompleted == 1; + task.save().then(function (task) { + res.send(task); + }) + }); +}); + +app.delete('/tasks/:id', function (req, res) { + Tasks.findById(req.params.id).then(function (task) { + task.destroy().then(function () { + res.send(''); + }); }); - }) }); io.sockets.on('connection', function (socket) { - socket.on('task', function (data) { - socket.broadcast.emit('task', data); - }); + socket.on('task', function (data) { + console.log(data); + socket.broadcast.emit('task', data); + }); });