$addToSet: { following: to } } ).exec(function (err) { if (err) return callback(err); callback(null, null); }); }; // authenticate input against database OrderSchema.statics.unFollow = function (from, to, callback) { Order.update( { _id: from, }, { $inc: { followingCount: -1 }, $pull: { following: to } } ).exec(function (err) { if (err) return callback(err); callback(null, null); }); }; export const Order = model('Order', OrderSchema);
zip: String, website: String, latitude: Number, longitude: Number } }, date: Date, category: String, content: String } ], books: [ { id: Number, isbn10: Number, isbn13: Number, title: String, category: String } ] } // userSchema.method['comparePassword'] = function(candidatePassword: String, cb: Function) { // bcrypt.compare(candidatePassword, this.password, function(err: Error, isMatch: Boolean) { // if (err) return cb(err); // cb(null, isMatch); // }); // }; export let User: mongoose.Model<IUser> = mongoose.model<IUser>('User', userSchema);
import * as mongoose from 'mongoose'; export interface IBlogModel extends app.i.IBlog, mongoose.Document{} let blogSchema = new mongoose.Schema({ title: { type: String, required: true }, datePosted: { type: Number }, body: { type: String, required: true }, imageURL: { type: String, default: 'http://1.bp.blogspot.com/-Bsv5jXiALOk/UdXLHs5jwaI/AAAAAAAAIU0/JuhiK3PvL10/s541/kune-kune-piglets-stacked.jpg' }, tags: String }); export let Blog = mongoose.model<IBlogModel>('Blog', blogSchema);
var mongoose = require('mongoose'); var ThingSchema = new mongoose.Schema({ userid: { type: String, required: true }, expireAt: { type: Date, required: true, default: function() { // 60 seconds from now return new Date(new Date().valueOf() + 7260000); } } }); // Expire at the time indicated by the expireAt field ThingSchema.index({ expireAt: 1 }, { expireAfterSeconds : 0 }); export = mongoose.model('Recovery', ThingSchema);
PlatformSchema.pre('save', function(next: Function): void { let user = this // generate a salt then run callback if (user.isNew) { bcrypt .genSalt(10, (err: Error, salt: string) => { if (err) { return next(err) } // encrypt password with salt bcrypt.hash(user.password, salt, null, (err, hash) => { if (err) { return next(err) } // overwrite plain text password with encrypted password user.password = hash next() }) }) } else { UTIL.setUpdateTime(user, ['username', 'password', 'nickname', 'name', 'gender', 'mobile', 'email', 'pid', 'avatar', 'background', 'locale', 'city', 'country']) user.wasNew = user.isNew next() } }) export { IPlatform } export default model<IPlatform>('Platform', PlatformSchema)
import { Schema, model } from 'mongoose'; const JobSchema = new Schema({ companyName: {type: String, required: true}, fantasyName: {type: String, required: true}, cnpj: {type: String, required: true}, showCompanyName: Boolean, opportunityName: {type: String, required: true}, opportunityDecription: {type: String, required: true}, howToSubscribe: {type: String, required: true}, contact: { email: {type: String, required: true}, name: {type: String, required: true}, phone: {type: String, required: true} }, salaryRange: {type: String, required: true}, opportunityType: {type: String, required: true}, contractType: {type: String, required: true}, city: {type: String, required: true}, state: {type: String, required: true} }); export const Job = model('Job', JobSchema);
before((done) => { User = mongoose.model("User"); user = new User(); done(); })
import * as mongoose from 'mongoose'; export interface ICommentModel extends app.i.IComment, mongoose.Document{} let commentSchema = new mongoose.Schema({ message: {type: String, required: true}, datePosted: Number, user: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true }, event: {type: mongoose.Schema.Types.ObjectId, ref: 'Event', required: true} }); export let Comment = mongoose.model<ICommentModel>('Comment', commentSchema);
import * as mongoose from 'mongoose'; export interface ITodoModel extends ITodo, mongoose.Document { } let todoSchema = new mongoose.Schema({ task: String, status: String, }); export let Todo = mongoose.model('Todo', todoSchema);
let user: IUser = users[0]; user.compare(password, (bcryptErr, isAuth) => { if (bcryptErr) { cb(bcryptErr); return; } if (isAuth) { // remove the password from the fetched object delete user.password; cb(undefined, user); return; } else { cb(undefined, undefined); } }); } else { cb(undefined, undefined); } }); }); userSchema.method('compare', function (password: string, cb: {(err: Error, isValid: boolean): void}): void { console.log('compare'); bcrypt.compare(password, this.password, cb); }); export const User: Model<IUser> = mongoose.model<IUser>('User', userSchema); } export = User;