Skip to content

Commit

Permalink
food 添加功能及测试完成
Browse files Browse the repository at this point in the history
  • Loading branch information
leftjs committed Jan 21, 2016
1 parent 902cad6 commit fd6202b
Show file tree
Hide file tree
Showing 26 changed files with 224 additions and 43 deletions.
2 changes: 1 addition & 1 deletion dist/bizs/commonBiz.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions dist/database/users.db
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{"name":"匿名","username":"customer","password":"91ec1f9324753048c0096d036a694f86","token":"","expiredTime":1453310980791,"is_admin":false,"is_windower":false,"_id":"Nbz2GlZ62bl7ZbBO"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"","expiredTime":1453310980803,"is_admin":false,"is_windower":true,"_id":"w7dgbO00j0nRIZn5"}
{"name":"匿名","username":"admin","password":"21232f297a57a5a743894a0e4a801fc3","token":"","expiredTime":1453310980817,"is_admin":true,"is_windower":false,"_id":"qT6cDv6c7AKBXQWH"}
{"name":"匿名","username":"admin","password":"21232f297a57a5a743894a0e4a801fc3","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6InFUNmNEdjZjN0FLQlhRV0giLCJpYXQiOjE0NTMzMTA5ODB9.N_RQlNJU2f1Xq3wnYlkhVo2jlmRjAgfTyxDTlkGvr-U","expiredTime":1453397380852,"is_admin":true,"is_windower":false,"_id":"qT6cDv6c7AKBXQWH"}
{"name":"匿名","username":"customer","password":"91ec1f9324753048c0096d036a694f86","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Ik5iejJHbFo2MmJsN1piQk8iLCJpYXQiOjE0NTMzMTA5ODB9.JloeVjVbeCUGZ548ByUEP6RJSlZLG6F0pVjyOP4LJVY","expiredTime":1453397380872,"is_admin":false,"is_windower":false,"_id":"Nbz2GlZ62bl7ZbBO"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Inc3ZGdiTzAwajBuUklabjUiLCJpYXQiOjE0NTMzMTA5ODB9.6UekluLyscBKU93G0O6NAFoNFtfQXAgIecU-cPoTWX4","expiredTime":1453397380889,"is_admin":false,"is_windower":true,"_id":"w7dgbO00j0nRIZn5"}
{"name":"张三","username":"customer","password":"91ec1f9324753048c0096d036a694f86","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Ik5iejJHbFo2MmJsN1piQk8iLCJpYXQiOjE0NTMzMTA5ODB9.JloeVjVbeCUGZ548ByUEP6RJSlZLG6F0pVjyOP4LJVY","expiredTime":1453397380872,"is_admin":false,"is_windower":false,"_id":"Nbz2GlZ62bl7ZbBO"}
{"name":"张三","username":"customer","password":"f5bb0c8de146c67b44babbf4e6584cc0","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Ik5iejJHbFo2MmJsN1piQk8iLCJpYXQiOjE0NTMzMTA5ODB9.JloeVjVbeCUGZ548ByUEP6RJSlZLG6F0pVjyOP4LJVY","expiredTime":1453397380872,"is_admin":false,"is_windower":false,"_id":"Nbz2GlZ62bl7ZbBO"}
{"name":"匿名","username":"admin","password":"21232f297a57a5a743894a0e4a801fc3","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6InFUNmNEdjZjN0FLQlhRV0giLCJpYXQiOjE0NTMzMTA5ODB9.N_RQlNJU2f1Xq3wnYlkhVo2jlmRjAgfTyxDTlkGvr-U","expiredTime":1453397380852,"is_admin":false,"is_windower":false,"_id":"qT6cDv6c7AKBXQWH"}
{"name":"匿名","username":"admin","password":"21232f297a57a5a743894a0e4a801fc3","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6InFUNmNEdjZjN0FLQlhRV0giLCJpYXQiOjE0NTMzMTA5ODB9.N_RQlNJU2f1Xq3wnYlkhVo2jlmRjAgfTyxDTlkGvr-U","expiredTime":1453397380852,"is_admin":true,"is_windower":false,"_id":"qT6cDv6c7AKBXQWH"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Inc3ZGdiTzAwajBuUklabjUiLCJpYXQiOjE0NTMzMTA5ODB9.6UekluLyscBKU93G0O6NAFoNFtfQXAgIecU-cPoTWX4","expiredTime":1453397380889,"is_admin":false,"is_windower":true,"_id":"w7dgbO00j0nRIZn5"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Inc3ZGdiTzAwajBuUklabjUiLCJpYXQiOjE0NTMzMTA5ODB9.6UekluLyscBKU93G0O6NAFoNFtfQXAgIecU-cPoTWX4","expiredTime":1453397380889,"is_admin":false,"is_windower":false,"_id":"w7dgbO00j0nRIZn5"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Inc3ZGdiTzAwajBuUklabjUiLCJpYXQiOjE0NTMzMTA5ODB9.6UekluLyscBKU93G0O6NAFoNFtfQXAgIecU-cPoTWX4","expiredTime":1453397380889,"is_admin":false,"is_windower":true,"_id":"w7dgbO00j0nRIZn5"}
{"name":"匿名","username":"customer","password":"91ec1f9324753048c0096d036a694f86","token":"","expiredTime":1453367237162,"is_admin":false,"is_windower":false,"_id":"Iyf2wz65jn3ERVsy"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"","expiredTime":1453367237177,"is_admin":false,"is_windower":true,"_id":"igYTpIqgxe1fQnPO"}
{"name":"匿名","username":"admin","password":"21232f297a57a5a743894a0e4a801fc3","token":"","expiredTime":1453367237195,"is_admin":true,"is_windower":false,"_id":"jVm2Fltx6rmKycjf"}
{"name":"匿名","username":"admin","password":"21232f297a57a5a743894a0e4a801fc3","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6ImpWbTJGbHR4NnJtS3ljamYiLCJpYXQiOjE0NTMzNjcyMzd9.eG-6YvKMoCaQo2EyExE2uE9yGMutedq_pYN2yV9uvus","expiredTime":1453453637234,"is_admin":true,"is_windower":false,"_id":"jVm2Fltx6rmKycjf"}
{"name":"匿名","username":"customer","password":"91ec1f9324753048c0096d036a694f86","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Ikl5ZjJ3ejY1am4zRVJWc3kiLCJpYXQiOjE0NTMzNjcyMzd9.v7OVvMCImeViVMAy6xr-ibKu1MfYgSKkD4UgvHQ3PTU","expiredTime":1453453637247,"is_admin":false,"is_windower":false,"_id":"Iyf2wz65jn3ERVsy"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6ImlnWVRwSXFneGUxZlFuUE8iLCJpYXQiOjE0NTMzNjcyMzd9.Ku3NbZq7cCe2AVROAJbhQ4e5n7d2olFg8dO4OM1RRaA","expiredTime":1453453637260,"is_admin":false,"is_windower":true,"_id":"igYTpIqgxe1fQnPO"}
{"name":"张三","username":"customer","password":"91ec1f9324753048c0096d036a694f86","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Ikl5ZjJ3ejY1am4zRVJWc3kiLCJpYXQiOjE0NTMzNjcyMzd9.v7OVvMCImeViVMAy6xr-ibKu1MfYgSKkD4UgvHQ3PTU","expiredTime":1453453637247,"is_admin":false,"is_windower":false,"_id":"Iyf2wz65jn3ERVsy"}
{"name":"张三","username":"customer","password":"f5bb0c8de146c67b44babbf4e6584cc0","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6Ikl5ZjJ3ejY1am4zRVJWc3kiLCJpYXQiOjE0NTMzNjcyMzd9.v7OVvMCImeViVMAy6xr-ibKu1MfYgSKkD4UgvHQ3PTU","expiredTime":1453453637247,"is_admin":false,"is_windower":false,"_id":"Iyf2wz65jn3ERVsy"}
{"name":"匿名","username":"admin","password":"21232f297a57a5a743894a0e4a801fc3","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6ImpWbTJGbHR4NnJtS3ljamYiLCJpYXQiOjE0NTMzNjcyMzd9.eG-6YvKMoCaQo2EyExE2uE9yGMutedq_pYN2yV9uvus","expiredTime":1453453637234,"is_admin":false,"is_windower":false,"_id":"jVm2Fltx6rmKycjf"}
{"name":"匿名","username":"admin","password":"21232f297a57a5a743894a0e4a801fc3","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6ImpWbTJGbHR4NnJtS3ljamYiLCJpYXQiOjE0NTMzNjcyMzd9.eG-6YvKMoCaQo2EyExE2uE9yGMutedq_pYN2yV9uvus","expiredTime":1453453637234,"is_admin":true,"is_windower":false,"_id":"jVm2Fltx6rmKycjf"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6ImlnWVRwSXFneGUxZlFuUE8iLCJpYXQiOjE0NTMzNjcyMzd9.Ku3NbZq7cCe2AVROAJbhQ4e5n7d2olFg8dO4OM1RRaA","expiredTime":1453453637260,"is_admin":false,"is_windower":true,"_id":"igYTpIqgxe1fQnPO"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6ImlnWVRwSXFneGUxZlFuUE8iLCJpYXQiOjE0NTMzNjcyMzd9.Ku3NbZq7cCe2AVROAJbhQ4e5n7d2olFg8dO4OM1RRaA","expiredTime":1453453637260,"is_admin":false,"is_windower":false,"_id":"igYTpIqgxe1fQnPO"}
{"name":"匿名","username":"windower","password":"d376867b1d99e6e188d5b658a4a51153","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6ImlnWVRwSXFneGUxZlFuUE8iLCJpYXQiOjE0NTMzNjcyMzd9.Ku3NbZq7cCe2AVROAJbhQ4e5n7d2olFg8dO4OM1RRaA","expiredTime":1453453637260,"is_admin":false,"is_windower":true,"_id":"igYTpIqgxe1fQnPO"}
6 changes: 4 additions & 2 deletions dist/libs/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions dist/libs/db.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions myplayground.coffee
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@

commonBiz = require './src/bizs/commonBiz'

_ = require 'underscore'

HashMap = require('hashmap')


oldData = {
name: '匿名'
username:'1232324'
username: '1232324'
token: ''
}

newData = {
name: '匿名aasdf'
username: 12
token:'asdfasdf'
token: 'asdfasdf'
}

array = []


_.map(array,(doc)->
console.log(doc.name)
)


result = commonBiz.concatPostData(oldData,newData,{'name'})
console.log(result)
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"cors": "^2.7.1",
"debug": "~2.2.0",
"express": "~4.13.1",
"hashmap": "^2.0.4",
"jade": "~1.11.0",
"jsonwebtoken": "^5.5.4",
"mongoose": "^4.3.4",
Expand Down
6 changes: 5 additions & 1 deletion src/bizs/commonBiz.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ authAndSetUserInfo = (req,res,next) ->
req.userInfo = user
return next()
else
return next(customError(401, '授权失败,请检查你的token'))
return next(customError(401, 'api授权失败,请检查你的token'))

)


# 拼接postdata
concatPostData = (oldData,newData,allow=undefined ) ->
postData = {}
keys = _.keys(oldData)
Expand All @@ -43,6 +45,8 @@ concatPostData = (oldData,newData,allow=undefined ) ->
)
return postData



module.exports = {
authAndSetUserInfo: authAndSetUserInfo
customError: customError
Expand Down
2 changes: 1 addition & 1 deletion src/bizs/commonBiz.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/bizs/commonBiz.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions src/bizs/foodBiz.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
db = require('./../libs/db')

config = require('./../config/config')

commonBiz = require './commonBiz'
Utils = require './../utils/Utils'

_ = require 'underscore'

# 添加食物
addFood = (req,res,next) ->
windowId = req.params['id']
token = req.headers['x-token']


db.windows.findOne({_id: windowId}, (err,window) ->
return next(err) if err
return next(commonBiz.customError(404,'没有找到该窗口')) if not window
return next(commonBiz.customError(401,'您没有权利这么做')) if window.author.id isnt Utils.idFromToken(token)

postData = {
name: req.body.name ?= '麻婆豆腐' # 食物名称
price: req.body.price ?= 2.5 # 食物价格
number: req.body.price ?= 100 # 食物余量
is_delete: false
window_id: windowId
}
db.foods.insert(postData,(err,doc) ->
return next(err) if err
return res.json({id: doc._id})

)


)


module.exports = {
addFood: addFood
}
3 changes: 2 additions & 1 deletion src/bizs/userBiz.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ register = (req,res,next) ->

db.users.insert(postData,(err,user) ->
return next(err) if err
# console.log(user)
res.send({id: user._id})
)

Expand All @@ -47,7 +48,7 @@ login = (req,res,next) ->
password = md5Util.md5(req.body.password ?= '')
db.users.findOne({username:username,password:password},(err,user) ->
return next(err) if err
return next(commonBiz.customError(400,'用户名或密码错误')) if !user
return next(commonBiz.customError(400,'用户名或密码错误')) if not user
token = jwt.sign({id: user._id},config.secret)
expiredTime = Date.now() + config.tokenExpiredTime
db.users.update({_id:user._id},{$set: {token:token,expiredTime:expiredTime}},(err,numReplaced) ->
Expand Down
Loading

0 comments on commit fd6202b

Please sign in to comment.