本文整理匯總了TypeScript中mongoose.Mongoose.model方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Mongoose.model方法的具體用法?TypeScript Mongoose.model怎麽用?TypeScript Mongoose.model使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mongoose.Mongoose
的用法示例。
在下文中一共展示了Mongoose.model方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: configureTaskModel
export function configureTaskModel(mongoose: Mongoose) {
var taskSchema = new Schema({
title: String,
description: String,
assigned_to: {type: String, ref: 'User'}
});
taskSchema.method('replaceAttributes', function(attributes) {
this.title = attributes.title;
this.description = attributes.description;
this.assigned_to = MongooseUtils.id(attributes.assigned_to);
});
taskSchema.method('updateAttributes', function(attributes) {
if(attributes.title) {
this.title = attributes.title;
}
if(attributes.description) {
this.description = attributes.description;
}
if(attributes.assigned_to) {
this.assigned_to = attributes.assigned_to;
}
});
taskSchema.plugin(timestampsPlugin);
taskSchema.plugin(promisifyPlugin);
TaskModel = mongoose.model<ITaskDocument>('Task', taskSchema);
}
示例2: configureSprintModel
export function configureSprintModel(mongoose: Mongoose) {
var sprintSchema = new Schema({
from_date: Date,
to_date: Date,
project: {type: String, ref: 'Project'}
});
sprintSchema.method('replaceAttributes', function(attributes) {
this.from_date = attributes.from_date;
this.to_date = attributes.to_date;
this.project = MongooseUtils.id(attributes.project);
});
sprintSchema.method('updateAttributes', function(attributes) {
if(attributes.from_date) {
this.from_date = attributes.from_date;
}
if(attributes.to_date) {
this.to_date = attributes.to_date;
}
if(attributes.project) {
this.project = MongooseUtils.id(attributes.project);
}
});
sprintSchema.plugin(timestampsPlugin);
sprintSchema.plugin(promisifyPlugin);
SprintModel = mongoose.model<ISprintDocument>('Sprint', sprintSchema);
}
示例3: configureProjectModel
export function configureProjectModel(mongoose: Mongoose) {
var projectSchema = new Schema({
title: String,
description: String
});
projectSchema.method('replaceAttributes', function(attributes) {
this.title = attributes.title;
this.description = attributes.description;
});
projectSchema.method('updateAttributes', function(attributes) {
if(attributes.title) {
this.title = attributes.title;
}
if(attributes.description) {
this.description = attributes.description;
}
});
projectSchema.plugin(timestampsPlugin);
projectSchema.plugin(promisifyPlugin);
ProjectModel = mongoose.model<IProjectDocument>('Project', projectSchema);
}
示例4: configureStoryModel
export function configureStoryModel(mongoose: Mongoose) {
var storySchema = new Schema({
title: String,
description: String
});
storySchema.method('replaceAttributes', function(attributes) {
this.title = attributes.title;
this.description = attributes.description;
});
storySchema.method('updateAttributes', function(attributes) {
if(attributes.title) {
this.title = attributes.title;
}
if(attributes.description) {
this.description = attributes.description;
}
});
storySchema.plugin(timestampsPlugin);
storySchema.plugin(promisifyPlugin);
StoryModel = mongoose.model<IStoryDocument>('Story', storySchema);
}
示例5: configureStoryModel
export function configureStoryModel(mongoose: Mongoose) {
var storySchema = new Schema({
title: String,
description: String,
project: {type: String, ref: 'Project'},
sprint: {type: String, ref: 'Sprint'}
});
storySchema.method('replaceAttributes', function(attributes) {
this.title = attributes.title;
this.description = attributes.description;
this.project = MongooseUtils.id(attributes.project);
this.sprint = MongooseUtils.id(attributes.sprint);
});
storySchema.method('updateAttributes', function(attributes) {
if(attributes.title) {
this.title = attributes.title;
}
if(attributes.description) {
this.description = attributes.description;
}
});
storySchema.plugin(timestampsPlugin);
storySchema.plugin(promisifyPlugin);
StoryModel = mongoose.model<IStoryDocument>('Story', storySchema);
}
示例6: configureUserModel
export function configureUserModel(mongoose: Mongoose) {
var userSchema = new Schema({
firstName: String,
lastName: String,
email: String,
hashedPassword: String,
type: Number
});
userSchema.plugin(timestampsPlugin);
userSchema.plugin(promisifyPlugin);
userSchema.method('replaceAttributes', function(attributes) {
throw new Error("Not implemented");
});
userSchema.method('updateAttributes', function(attributes) {
throw new Error("Not implemented");
});
userSchema.method('hashPassword', function(password) {
this.hashedPassword = md5(password);
});
userSchema.method('checkPassword', function(password) {
return this.hashedPassword === md5(password);
});
const md5 = (password) => crypto.createHash('md5').update('"'+password+'"').digest('hex');
UserModel = mongoose.model<IUserDocument>('User', userSchema);
}
示例7: configureCategoryModel
export function configureCategoryModel(mongoose: Mongoose) {
let categoryImageSchema = {
src: String,
width: Number,
height: Number,
kind: {type: String, enum: ['cover', 'main']},
};
let categorySchema = new Schema({
title: String,
slug: String,
status: String,
description: String,
images: [categoryImageSchema]
});
categorySchema.method('replaceAttributes', function(attributes) {
this.title = attributes.title;
this.slug = attributes.slug;
this.status = attributes.status;
this.description = attributes.description;
this.images = attributes.images;
});
categorySchema.method('updateAttributes', function(attributes) {
if(attributes.title) {
this.title = attributes.title;
}
if(attributes.slug) {
this.slug = attributes.slug;
}
if(attributes.status) {
this.status = attributes.status;
}
if(attributes.description) {
this.description = attributes.description;
}
if(attributes.cover_image) {
this.cover_image = this.cover_image.concat(attributes.cover_image);
}
});
categorySchema.plugin(timestampsPlugin);
categorySchema.plugin(promisifyPlugin);
CategoryModel = mongoose.model<ICategoryDocument>('Category', categorySchema);
}
示例8: configureShopModel
export function configureShopModel(mongoose: Mongoose) {
let addressSchema = {
address: String,
address2: String,
city:String,
state: String,
country: String,
country_code: String,
zip: String
};
let shopSchema = new Schema({
name: String,
published: Boolean,
config: {
address: addressSchema,
currency_code: String
},
creator_id: {type: Schema.Types.ObjectId, ref: 'User', required: true}
});
shopSchema.method('replaceAttributes', function(attributes) {
this.published = attributes.published;
this.config = attributes.config;
});
shopSchema.method('updateAttributes', function(attributes) {
if(attributes.published) {
this.published = attributes.published;
}
if(attributes.config) {
this.config = attributes.config;
}
});
shopSchema.method('setCreator', function(creator) {
this.creator_id = getDocumentId(creator);
});
shopSchema.plugin(timestampsPlugin);
shopSchema.plugin(promisifyPlugin);
ShopModel = mongoose.model<IShopDocument>('Shop', shopSchema);
}
示例9: configureCartModel
export function configureCartModel(mongoose: Mongoose) {
let priceSchema = {
value: Number,
currency: String
};
let cartItemSchema = {
variant_id: {type: Schema.Types.ObjectId},
product_id: {type: Schema.Types.ObjectId, ref: 'Product'},
quantity: Number
};
let totalsSchema = {
pre_discount: {
with_tax: priceSchema,
without_tax: priceSchema
},
post_discount: {
with_tax: priceSchema,
without_tax: priceSchema
}
}
let cartSchema = new Schema({
items: [cartItemSchema],
totals: totalsSchema,
total_items: Number,
total_unique_items: Number,
shop_id: {type: Schema.Types.ObjectId, ref: 'Shop', required: true},
user_id: {type: Schema.Types.ObjectId, ref: 'User', required: true}
});
cartSchema.method('replaceAttributes', function(attributes) {
this.items = attributes.items;
this.totals = attributes.totals;
this.total_items = attributes.total_items;
this.total_unique_items = attributes.total_unique_items;
this.shop_id = getDocumentId(attributes.shop_id);
this.user_id = getDocumentId(attributes.user_id);
});
cartSchema.method('updateAttributes', function(attributes) {
if(attributes.items) {
this.items = attributes.items;
}
if(attributes.totals) {
this.totals = attributes.totals;
}
if(attributes.total_items) {
this.total_items = attributes.total_items;
}
if(attributes.total_unique_items) {
this.total_unique_items = attributes.total_unique_items;
}
if(attributes.shop_id) {
this.shop_id = getDocumentId(attributes.shop_id);
}
});
cartSchema.plugin(timestampsPlugin);
cartSchema.plugin(promisifyPlugin);
CartModel = mongoose.model<ICartDocument>('Cart', cartSchema);
}
示例10: configureUserModel
//.........這裏部分代碼省略.........
'google' : google,
'twitter' : twitter,
'local' : local
};
});
// Return authenticated user info
userSchema.virtual('auth').get(function() {
let local = {
email: this.local.email,
fname: this.local.fname,
lname: this.local.lname
};
let facebook = {
id : this.facebook.id,
email : this.facebook.email,
display_name : this.facebook.display_name,
token : this.facebook.token
};
let twitter = {
id : this.twitter.id,
username : this.twitter.username,
display_name : this.twitter.display_name,
token : this.twitter.token
};
let google = {
id : this.google.id,
email : this.google.email,
display_name : this.google.display_name,
token : this.google.token
};
return {
'_id' : this._id,
'display_name' : this.display_name,
'username' : this.username,
'roles' : this.roles,
'images' : this.images,
'shipping_address': this.shipping_address,
'online_at' : this.online_at,
'created_date' : this.created_date,
'updated_date' : this.updated_date,
'facebook' : facebook,
'google' : google,
'twitter' : twitter,
'local' : local
};
});
// Public profile information
userSchema.virtual('profile').get(function() {
var local = {
email: this.local.email,
fname: this.local.fname,
lname: this.local.lname
};
var facebook = {
id : this.facebook.id,
email : this.facebook.email,
display_name : this.facebook.display_name
};
var twitter = {
id : this.twitter.id,
username : this.twitter.username,
display_name : this.twitter.display_name
};
var google = {
id : this.google.id,
email : this.google.email,
display_name : this.google.display_name
};
return {
'_id' : this._id,
'display_name' : this.display_name,
'username' : this.username,
'images' : this.images,
'online_at' : this.online_at,
'facebook' : facebook,
'google' : google,
'twitter' : twitter,
'local' : local
};
});
userSchema.plugin(timestampsPlugin);
userSchema.plugin(promisifyPlugin);
userSchema.plugin(uniqueValidator);
UserModel = mongoose.model<IUserDocument>('User', userSchema);
}