Created
June 22, 2013 11:05
-
-
Save yrezgui/5840468 to your computer and use it in GitHub Desktop.
Flouss model files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MongoDB ORM package | |
var mongoose = require('mongoose'), | |
Schema = mongoose.Schema; | |
var clientSchema = Schema({ | |
firstname: { | |
type: String, | |
required: true | |
}, | |
lastname: { | |
type: String, | |
required: true | |
}, | |
email: { | |
type: String, | |
required: true, | |
unique: true | |
}, | |
password: { | |
type: String, | |
required: true | |
}, | |
photo: { | |
type: String | |
}, | |
token: { | |
type: String, | |
required: true, | |
default: '-1' | |
} | |
}); | |
// Remove confidential informations | |
clientSchema.methods.getPublic = function getPublic() { | |
obj = this.toObject(); | |
delete obj.password; | |
delete obj.token; | |
return obj; | |
}; | |
// Remove confidential informations | |
clientSchema.methods.getLogin = function getLogin() { | |
obj = this.toObject(); | |
delete obj.password; | |
return obj; | |
}; | |
// export the client model | |
module.exports = db.model('Client', clientSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MongoDB ORM package | |
var mongoose = require('mongoose'), | |
Schema = mongoose.Schema; | |
var ebookSchema = Schema({ | |
title: { | |
type: String, | |
required: true | |
}, | |
filename: { | |
type: String, | |
required: true | |
}, | |
bucket: { | |
type: String, | |
required: true | |
}, | |
icon: { | |
type: String, | |
required: true | |
}, | |
price: { | |
type: Number, | |
required: true | |
}, | |
description: { | |
type: String, | |
required: true | |
}, | |
tags: [{ | |
type: String | |
}] | |
}); | |
// export the ebook model | |
module.exports = db.model('Ebook', ebookSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MongoDB ORM package | |
var mongoose = require('mongoose'), | |
Schema = mongoose.Schema; | |
var invoiceSchema = Schema({ | |
client: { | |
type: Schema.Types.ObjectId, | |
ref: 'Client', | |
required: true | |
}, | |
ebook: { | |
type: Schema.Types.ObjectId, | |
ref: 'Ebook', | |
required: true | |
}, | |
date: { | |
type: Date, | |
required: true | |
} | |
}); | |
// export the invoice model | |
module.exports = db.model('Invoice', invoiceSchema); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment