mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-01-12 22:27:09 +08:00
change to mongoose schema
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,5 +1,6 @@
|
||||
/node_modules
|
||||
/coverage-reporter.html
|
||||
/npm-debug.log
|
||||
|
||||
/.vagrant
|
||||
/package.box
|
||||
|
||||
@@ -21,6 +21,8 @@ app.libs =
|
||||
redisStore: require 'connect-redis'
|
||||
expressSession: require 'express-session'
|
||||
|
||||
ObjectId: (require 'mongoose').Schema.Types.ObjectId
|
||||
|
||||
{cookieParser, crypto, bodyParser, depd, express, fs, harp, middlewareInjector, mongoose} = exports.libs
|
||||
{morgan, nodemailer, path, redis, redisStore, expressSession} = exports.libs
|
||||
|
||||
|
||||
@@ -5,28 +5,34 @@ _ = require 'underscore'
|
||||
|
||||
Token = mongoose.Schema
|
||||
type:
|
||||
required: true
|
||||
type: String
|
||||
enum: ['full_access']
|
||||
|
||||
token:
|
||||
required: true
|
||||
type: String
|
||||
|
||||
created_at:
|
||||
type: Date
|
||||
default: Date.now
|
||||
|
||||
update_at:
|
||||
type: Date
|
||||
default: Date.now
|
||||
|
||||
payload:
|
||||
type: Object
|
||||
default: {}
|
||||
|
||||
Account = mongoose.Schema
|
||||
username:
|
||||
type: String
|
||||
required: true
|
||||
type: String
|
||||
|
||||
email:
|
||||
type: String
|
||||
required: true
|
||||
type: String
|
||||
|
||||
password:
|
||||
type: String
|
||||
|
||||
@@ -1,23 +1,26 @@
|
||||
{ObjectID} = require 'mongodb'
|
||||
_ = require 'underscore'
|
||||
{_, ObjectId, mongoose} = app.libs
|
||||
|
||||
module.exports = exports = app.db.collection 'balance_log'
|
||||
BalanceLog = mongoose.Schema
|
||||
account_id:
|
||||
required: true
|
||||
type: ObjectId
|
||||
ref: 'Account'
|
||||
|
||||
type:
|
||||
required: true
|
||||
type: String
|
||||
enum: ['deposit']
|
||||
|
||||
amount:
|
||||
required: true
|
||||
type: Number
|
||||
|
||||
created_at:
|
||||
type: Date
|
||||
default: Date.now
|
||||
|
||||
sample =
|
||||
account_id: new ObjectID()
|
||||
type: 'deposit'
|
||||
amount: 10
|
||||
created_at: new Date()
|
||||
payload:
|
||||
type: 'taobao'
|
||||
order_id: '560097131641814'
|
||||
type: Object
|
||||
default: {}
|
||||
|
||||
exports.create = (account, type, amount, payload, callback) ->
|
||||
exports.insert
|
||||
account_id: account._id
|
||||
type: type
|
||||
amount: amount
|
||||
payload: payload
|
||||
created_at: new Date()
|
||||
, (err, result) ->
|
||||
callback _.first result
|
||||
module.exports = mongoose.model 'BalanceLog', BalanceLog
|
||||
|
||||
@@ -1,25 +1,40 @@
|
||||
{ObjectID} = require 'mongodb'
|
||||
_ = require 'underscore'
|
||||
{_, ObjectId, mongoose} = app.libs
|
||||
|
||||
module.exports = exports = app.db.collection 'coupon_codes'
|
||||
CouponCode = mongoose.Schema
|
||||
code:
|
||||
required: true
|
||||
type: String
|
||||
|
||||
mAccount = require './account'
|
||||
expired:
|
||||
type: Date
|
||||
default: null
|
||||
|
||||
utils = require '../utils'
|
||||
available_times:
|
||||
type: Number
|
||||
default: null
|
||||
|
||||
type:
|
||||
required: true
|
||||
type: String
|
||||
enum: ['amount']
|
||||
|
||||
sample =
|
||||
code: 'PmlFH2hpziDmyqPX'
|
||||
expired: new Date()
|
||||
available_times: 2
|
||||
type: 'amount'
|
||||
meta:
|
||||
amount: 10
|
||||
category: '2014.9.20'
|
||||
type: Object
|
||||
default: {}
|
||||
|
||||
apply_log: [
|
||||
account_id: new ObjectID()
|
||||
created_at: new Date()
|
||||
account_id:
|
||||
required: true
|
||||
type: ObjectId
|
||||
ref: 'Account'
|
||||
|
||||
created_at:
|
||||
type: Date
|
||||
default: Date.now
|
||||
]
|
||||
|
||||
module.exports = mongoose.model 'CouponCode', CouponCode
|
||||
|
||||
exports.type_meta =
|
||||
amount:
|
||||
restrict: (account, coupon_code, callback) ->
|
||||
|
||||
@@ -1,17 +1,36 @@
|
||||
{ObjectID} = require 'mongodb'
|
||||
async = require 'async'
|
||||
_ = require 'underscore'
|
||||
{_, ObjectId, mongoose} = app.libs
|
||||
|
||||
module.exports = exports = app.db.collection 'notifications'
|
||||
|
||||
sample =
|
||||
account_id: ObjectID()
|
||||
group_name: 'root'
|
||||
created_at: Date()
|
||||
level: 'notice/event/log'
|
||||
type: 'payment_success'
|
||||
meta:
|
||||
amount: 10
|
||||
Notification = mongoose.Schema
|
||||
account_id:
|
||||
type: ObjectId
|
||||
ref: 'Account'
|
||||
default: null
|
||||
|
||||
group_name:
|
||||
type: String
|
||||
default: null
|
||||
|
||||
type:
|
||||
required: true
|
||||
type: String
|
||||
enum: ['payment_success']
|
||||
|
||||
level:
|
||||
required: true
|
||||
type: String
|
||||
enum: ['notice', 'event', 'log']
|
||||
|
||||
created_at:
|
||||
type: Date
|
||||
default: Date.now
|
||||
|
||||
payload:
|
||||
type: Object
|
||||
default: {}
|
||||
|
||||
module.exports = mongoose.model 'Notification', Notification
|
||||
|
||||
exports.createNotice = (account, group_name, type, level, meta, callback) ->
|
||||
exports.insert
|
||||
|
||||
@@ -1,19 +1,30 @@
|
||||
{ObjectID} = require 'mongodb'
|
||||
_ = require 'underscore'
|
||||
{_, ObjectId, mongoose} = app.libs
|
||||
|
||||
module.exports = exports = app.db.collection 'security_log'
|
||||
SecurityLog = mongoose.Schema
|
||||
account_id:
|
||||
required: true
|
||||
type: ObjectId
|
||||
ref: 'Account'
|
||||
|
||||
type:
|
||||
required: true
|
||||
type: String
|
||||
enum: ['update_password', 'update_setting', 'update_email']
|
||||
|
||||
created_at:
|
||||
type: Date
|
||||
default: Date.now
|
||||
|
||||
payload:
|
||||
type: Object
|
||||
default: {}
|
||||
|
||||
sample =
|
||||
account_id: new ObjectID()
|
||||
type: 'update_password/update_setting/update_email'
|
||||
created_at: new Date()
|
||||
payload: {}
|
||||
token:
|
||||
token: 'b535a6cec7b73a60c53673f434686e04972ccafddb2a5477f066f30eded55a9b'
|
||||
created_at: new Date()
|
||||
attribute:
|
||||
ip: '123.184.237.163'
|
||||
ua: 'Mozilla/5.0 (Intel Mac OS X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.102'
|
||||
required: true
|
||||
type: ObjectId
|
||||
ref: 'Token'
|
||||
|
||||
module.exports = mongoose.model 'SecurityLog', SecurityLog
|
||||
|
||||
exports.create = (account, type, token, payload, callback) ->
|
||||
matched_token = _.findWhere account.tokens,
|
||||
|
||||
@@ -1,35 +1,71 @@
|
||||
{ObjectID} = require 'mongodb'
|
||||
{markdown} = require 'markdown'
|
||||
_ = require 'underscore'
|
||||
{_, ObjectId, mongoose} = app.libs
|
||||
|
||||
module.exports = exports = app.db.collection 'tickets'
|
||||
|
||||
mAccount = require './account'
|
||||
Reply = mongoose.Schema
|
||||
_id:
|
||||
type: ObjectId
|
||||
|
||||
sample =
|
||||
account_id: ObjectID()
|
||||
created_at: Date()
|
||||
updated_at: Date()
|
||||
title: 'Ticket Title'
|
||||
content: 'Ticket Content(Markdown)'
|
||||
content_html: 'Ticket Conetnt(HTML)'
|
||||
status: 'open/pending/finish/closed'
|
||||
account_id:
|
||||
required: true
|
||||
type: ObjectId
|
||||
ref: 'Account'
|
||||
|
||||
options: {}
|
||||
created_at:
|
||||
type: Date
|
||||
default: Date.now
|
||||
|
||||
content:
|
||||
type: String
|
||||
|
||||
content_html:
|
||||
type: String
|
||||
|
||||
option:
|
||||
type: Object
|
||||
default: {}
|
||||
|
||||
Ticket = mongoose.Schema
|
||||
account_id:
|
||||
required: true
|
||||
type: ObjectId
|
||||
ref: 'Account'
|
||||
|
||||
created_at:
|
||||
type: Date
|
||||
default: Date.now
|
||||
|
||||
updated_at:
|
||||
type: Date
|
||||
default: Date.now
|
||||
|
||||
title:
|
||||
type: String
|
||||
|
||||
content:
|
||||
type: String
|
||||
|
||||
content_html:
|
||||
type: String
|
||||
|
||||
status:
|
||||
type: String
|
||||
enum: ['open', 'pending', 'finish', 'closed']
|
||||
|
||||
option:
|
||||
type: Object
|
||||
default: {}
|
||||
|
||||
members: [
|
||||
ObjectID()
|
||||
ObjectId
|
||||
]
|
||||
|
||||
replies: [
|
||||
_id: ObjectID()
|
||||
account_id: ObjectID()
|
||||
created_at: Date()
|
||||
content: 'Reply Content(Markdown)'
|
||||
content_html: 'Reply Conetnt(HTML)'
|
||||
options: {}
|
||||
Reply
|
||||
]
|
||||
|
||||
module.exports = mongoose.model 'Ticket', Ticket
|
||||
|
||||
exports.createTicket = (account, title, content, members, status, options, callback) ->
|
||||
exports.insert
|
||||
account_id: account._id
|
||||
|
||||
Reference in New Issue
Block a user