mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-01-16 12:22:26 +01:00
feat(invitations): add invitation model
This commit is contained in:
57
modules/invitations/server/models/invitation.server.model.js
Normal file
57
modules/invitations/server/models/invitation.server.model.js
Normal file
@@ -0,0 +1,57 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
var mongoose = require('mongoose'),
|
||||
Schema = mongoose.Schema,
|
||||
validator = require('validator');
|
||||
|
||||
/**
|
||||
* A Validation function for local strategy email
|
||||
*/
|
||||
var validateLocalStrategyEmail = function (email) {
|
||||
return validator.isEmail(email, {require_tld: false});
|
||||
};
|
||||
|
||||
/**
|
||||
* Peer Schema
|
||||
*/
|
||||
var InvitationSchema = new Schema({
|
||||
user: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'User'
|
||||
},
|
||||
to_user: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'User'
|
||||
},
|
||||
to_email: {
|
||||
type: String,
|
||||
unique: 'email already exists',
|
||||
required: 'Please fill in a email address',
|
||||
lowercase: true,
|
||||
trim: true,
|
||||
default: '',
|
||||
validate: [validateLocalStrategyEmail, 'Please fill a valid email address']
|
||||
},
|
||||
status: {
|
||||
type: Number,
|
||||
default: 0 //0 is unregistered invitation, 1 already invite friend, 2 is already registered
|
||||
},
|
||||
token: {
|
||||
type: String
|
||||
},
|
||||
expiresat: {
|
||||
type: Date
|
||||
},
|
||||
registeredat: {
|
||||
type: Date
|
||||
},
|
||||
createdat: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
}
|
||||
});
|
||||
|
||||
mongoose.model('Invitation', InvitationSchema);
|
||||
Reference in New Issue
Block a user