refactor database struct

This commit is contained in:
jysperm
2014-09-07 12:58:19 +08:00
parent 59e7122701
commit c26a7a0864
3 changed files with 17 additions and 19 deletions

View File

@@ -5,16 +5,16 @@ sample =
type: 'deposit'
amount: 10
created_at: new Date()
attribute:
payload:
type: 'taobao'
order_id: '560097131641814'
exports.create = (account, type, amount, attribute, callback) ->
exports.create = (account, type, amount, payload, callback) ->
exports.insert
account_id: account._id
type: type
amount: amount
attribute: attribute
payload: payload
created_at: new Date()
, (err, result) ->
callback err, result?[0]
callback err, _.first result

View File

@@ -9,7 +9,7 @@ sample =
type: 'amount'
meta:
amount: 10
log: [
apply_log: [
account_id: new ObjectID()
created_at: new Date()
]

View File

@@ -13,27 +13,25 @@ sample =
content_html: 'Ticket Conetnt(HTML)'
status: 'open/pending/finish/closed'
attribute:
payload:
public: false
members: [
ObjectID()
],
]
replys: [
replies: [
_id: ObjectID()
account_id: ObjectID()
created_at: Date()
content: 'Reply Content(Markdown)'
content_html: 'Reply Conetnt(HTML)'
attribute: {}
payload: {}
]
exports.createTicket = (account, title, content, members, status, attribute, callback) ->
membersID = []
for member in members
membersID.push member._id
exports.createTicket = (account, title, content, members, status, payload, callback) ->
members_id = _.map (members) ->
return member._id
exports.insert
account_id: account._id
@@ -44,10 +42,10 @@ exports.createTicket = (account, title, content, members, status, attribute, cal
content_html: markdown.toHTML content
status: status
members: membersID
attribute: attribute
replys: []
payload: payload
replies: []
, (err, result) ->
callback err, result?[0]
callback err, _.first result
exports.createReply = (ticket, account, content, status, callback) ->
data =
@@ -56,11 +54,11 @@ exports.createReply = (ticket, account, content, status, callback) ->
created_at: new Date()
content: content
content_html: markdown.toHTML content
attribute: {}
payload: {}
exports.update _id: ticket._id,
$push:
replys: data
replies: data
$set:
status: status
updated_at: new Date()