From c26a7a08642e6044e4957f17afaee2d3cb7fa698 Mon Sep 17 00:00:00 2001 From: jysperm Date: Sun, 7 Sep 2014 12:58:19 +0800 Subject: [PATCH] refactor database struct --- core/model/balance_log.coffee | 8 ++++---- core/model/coupon_code.coffee | 2 +- core/model/ticket.coffee | 26 ++++++++++++-------------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/core/model/balance_log.coffee b/core/model/balance_log.coffee index 7be9529..9518433 100644 --- a/core/model/balance_log.coffee +++ b/core/model/balance_log.coffee @@ -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 diff --git a/core/model/coupon_code.coffee b/core/model/coupon_code.coffee index e747f0f..52feffc 100644 --- a/core/model/coupon_code.coffee +++ b/core/model/coupon_code.coffee @@ -9,7 +9,7 @@ sample = type: 'amount' meta: amount: 10 - log: [ + apply_log: [ account_id: new ObjectID() created_at: new Date() ] diff --git a/core/model/ticket.coffee b/core/model/ticket.coffee index 7f2efdf..62feba2 100644 --- a/core/model/ticket.coffee +++ b/core/model/ticket.coffee @@ -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()