---|main| Initial commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
var mongoose = require('mongoose');
|
||||
var User = mongoose.model('User');
|
||||
var slug = require('slug');
|
||||
|
||||
var AeronefSchema = new mongoose.Schema({
|
||||
slug: { type: String, lowercase: true, unique: true },
|
||||
aeronef: String,
|
||||
imat: String,
|
||||
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }
|
||||
}, {timestamps: true, toJSON: {virtuals: true}});
|
||||
|
||||
AeronefSchema.pre('validate', function (next) {
|
||||
if (!this.slug) {
|
||||
this.slugify();
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
AeronefSchema.methods.slugify = function () {
|
||||
this.slug = slug(`${this.aeronef} ${this.imat}`) + '-' + (Math.random() * Math.pow(36, 6) | 0).toString(36);
|
||||
};
|
||||
|
||||
AeronefSchema.methods.toJSONFor = function(user){
|
||||
return {
|
||||
slug: this.slug,
|
||||
aeronef: this.aeronef,
|
||||
imat: this.imat,
|
||||
createdAt: this.createdAt,
|
||||
updatedAt: this.updatedAt,
|
||||
author: this.author.toProfileJSONFor(user)
|
||||
};
|
||||
};
|
||||
|
||||
mongoose.model('Aeronef', AeronefSchema);
|
||||
@@ -0,0 +1,51 @@
|
||||
var mongoose = require('mongoose');
|
||||
var uniqueValidator = require('mongoose-unique-validator');
|
||||
var slug = require('slug');
|
||||
|
||||
var ApplicationSchema = new mongoose.Schema({
|
||||
apikey: String,
|
||||
maskedkey: String,
|
||||
slug: { type: String, lowercase: true, unique: true },
|
||||
title: String,
|
||||
description: String,
|
||||
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }
|
||||
}, { timestamps: true, toJSON: { virtuals: true } });
|
||||
|
||||
ApplicationSchema.plugin(uniqueValidator, { message: 'is already taken' });
|
||||
|
||||
ApplicationSchema.pre('validate', function (next) {
|
||||
if (!this.slug) {
|
||||
this.slugify();
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
ApplicationSchema.methods.slugify = function () {
|
||||
this.slug = slug(this.title) + '-' + (Math.random() * Math.pow(36, 6) | 0).toString(36);
|
||||
};
|
||||
|
||||
ApplicationSchema.methods.toJSONFor = function (user) {
|
||||
return {
|
||||
maskedkey: this.maskedkey,
|
||||
slug: this.slug,
|
||||
title: this.title,
|
||||
description: this.description,
|
||||
createdAt: this.createdAt,
|
||||
updatedAt: this.updatedAt,
|
||||
author: this.author.toProfileJSONFor(user)
|
||||
};
|
||||
};
|
||||
|
||||
ApplicationSchema.methods.toAuthJSON = function () {
|
||||
return {
|
||||
maskedkey: this.maskedkey,
|
||||
slug: this.slug,
|
||||
title: this.title,
|
||||
description: this.description,
|
||||
createdAt: this.createdAt,
|
||||
updatedAt: this.updatedAt,
|
||||
author: this.author.toJSONFor()
|
||||
};
|
||||
};
|
||||
|
||||
mongoose.model('Application', ApplicationSchema);
|
||||
@@ -0,0 +1,34 @@
|
||||
var mongoose = require('mongoose');
|
||||
var User = mongoose.model('User');
|
||||
var slug = require('slug');
|
||||
|
||||
var CanopySchema = new mongoose.Schema({
|
||||
slug: { type: String, lowercase: true, unique: true },
|
||||
voile: String,
|
||||
taille: Number,
|
||||
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }
|
||||
}, {timestamps: true, toJSON: {virtuals: true}});
|
||||
|
||||
CanopySchema.pre('validate', function (next) {
|
||||
if (!this.slug) {
|
||||
this.slugify();
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
CanopySchema.methods.slugify = function () {
|
||||
this.slug = slug(`${this.voile} ${this.taille}`) + '-' + (Math.random() * Math.pow(36, 6) | 0).toString(36);
|
||||
};
|
||||
|
||||
CanopySchema.methods.toJSONFor = function(user){
|
||||
return {
|
||||
slug: this.slug,
|
||||
voile: this.voile,
|
||||
taille: this.taille,
|
||||
createdAt: this.createdAt,
|
||||
updatedAt: this.updatedAt,
|
||||
author: this.author.toProfileJSONFor(user)
|
||||
};
|
||||
};
|
||||
|
||||
mongoose.model('Canopy', CanopySchema);
|
||||
@@ -0,0 +1,20 @@
|
||||
var mongoose = require('mongoose');
|
||||
var uniqueValidator = require('mongoose-unique-validator');
|
||||
|
||||
var CurrencySchema = new mongoose.Schema({
|
||||
ordering: Number,
|
||||
code: { type: String, upercase: true, unique: true },
|
||||
title: String
|
||||
}, {timestamps: true, toJSON: {virtuals: true}});
|
||||
|
||||
CurrencySchema.plugin(uniqueValidator, { message: 'is already taken' });
|
||||
|
||||
CurrencySchema.methods.toJSONFor = function(){
|
||||
return {
|
||||
ordering: this.ordering,
|
||||
code: this.code,
|
||||
title: this.title
|
||||
};
|
||||
};
|
||||
|
||||
mongoose.model('Currency', CurrencySchema, 'currencies');
|
||||
@@ -0,0 +1,34 @@
|
||||
var mongoose = require('mongoose');
|
||||
var User = mongoose.model('User');
|
||||
var slug = require('slug');
|
||||
|
||||
var DropzoneSchema = new mongoose.Schema({
|
||||
slug: { type: String, lowercase: true, unique: true },
|
||||
lieu: String,
|
||||
oaci: String,
|
||||
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }
|
||||
}, {timestamps: true, toJSON: {virtuals: true}});
|
||||
|
||||
DropzoneSchema.pre('validate', function (next) {
|
||||
if (!this.slug) {
|
||||
this.slugify();
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
DropzoneSchema.methods.slugify = function () {
|
||||
this.slug = slug(`${this.lieu} ${this.oaci}`) + '-' + (Math.random() * Math.pow(36, 6) | 0).toString(36);
|
||||
};
|
||||
|
||||
DropzoneSchema.methods.toJSONFor = function(user){
|
||||
return {
|
||||
slug: this.slug,
|
||||
lieu: this.lieu,
|
||||
oaci: this.oaci,
|
||||
createdAt: this.createdAt,
|
||||
updatedAt: this.updatedAt,
|
||||
author: this.author.toProfileJSONFor(user)
|
||||
};
|
||||
};
|
||||
|
||||
mongoose.model('Dropzone', DropzoneSchema);
|
||||
@@ -0,0 +1,69 @@
|
||||
var mongoose = require('mongoose');
|
||||
var User = mongoose.model('User');
|
||||
var uniqueValidator = require('mongoose-unique-validator');
|
||||
var slug = require('slug');
|
||||
|
||||
var JumpSchema = new mongoose.Schema({
|
||||
slug: { type: String, lowercase: true, unique: true },
|
||||
date: { type: Date, default: Date.now },
|
||||
numero: { type: Number, unique: true },
|
||||
lieu: String,
|
||||
oaci: String,
|
||||
aeronef: String,
|
||||
imat: String,
|
||||
hauteur: Number,
|
||||
voile: String,
|
||||
taille: Number,
|
||||
categorie: String,
|
||||
module: String,
|
||||
participants: Number,
|
||||
sautants: [String],
|
||||
programme: String,
|
||||
accessoires: String,
|
||||
zone: String,
|
||||
dossier: String,
|
||||
video: String,
|
||||
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }
|
||||
}, {timestamps: true, toJSON: {virtuals: true}});
|
||||
|
||||
JumpSchema.plugin(uniqueValidator, { message: 'is already taken' });
|
||||
|
||||
JumpSchema.pre('validate', function (next) {
|
||||
if (!this.slug) {
|
||||
this.slugify();
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
JumpSchema.methods.slugify = function () {
|
||||
this.slug = slug(`${this.numero} ${this.lieu}`) + '-' + (Math.random() * Math.pow(36, 6) | 0).toString(36);
|
||||
};
|
||||
|
||||
JumpSchema.methods.toJSONFor = function(user){
|
||||
return {
|
||||
slug: this.slug,
|
||||
date: this.date,
|
||||
numero: this.numero,
|
||||
lieu: this.lieu,
|
||||
oaci: this.oaci,
|
||||
aeronef: this.aeronef,
|
||||
imat: this.imat,
|
||||
hauteur: this.hauteur,
|
||||
voile: this.voile,
|
||||
taille: this.taille,
|
||||
categorie: this.categorie,
|
||||
module: this.module,
|
||||
participants: this.participants,
|
||||
sautants: this.sautants,
|
||||
programme: this.programme,
|
||||
accessoires: this.accessoires,
|
||||
zone: this.zone,
|
||||
dossier: this.dossier,
|
||||
video: this.video,
|
||||
createdAt: this.createdAt,
|
||||
updatedAt: this.updatedAt,
|
||||
author: this.author.toProfileJSONFor(user)
|
||||
};
|
||||
};
|
||||
|
||||
mongoose.model('Jump', JumpSchema);
|
||||
@@ -0,0 +1,24 @@
|
||||
var mongoose = require('mongoose');
|
||||
var uniqueValidator = require('mongoose-unique-validator');
|
||||
|
||||
var MetalSchema = new mongoose.Schema({
|
||||
ordering: Number,
|
||||
code: { type: String, upercase: true, unique: true },
|
||||
title: String,
|
||||
color: String,
|
||||
image: String
|
||||
}, {timestamps: true, toJSON: {virtuals: true}});
|
||||
|
||||
MetalSchema.plugin(uniqueValidator, { message: 'is already taken' });
|
||||
|
||||
MetalSchema.methods.toJSONFor = function(){
|
||||
return {
|
||||
ordering: this.ordering,
|
||||
code: this.code,
|
||||
title: this.title,
|
||||
color: this.color,
|
||||
image: this.image
|
||||
};
|
||||
};
|
||||
|
||||
mongoose.model('Metal', MetalSchema);
|
||||
@@ -0,0 +1,87 @@
|
||||
var mongoose = require('mongoose');
|
||||
var uniqueValidator = require('mongoose-unique-validator');
|
||||
|
||||
var PriceSchema = new mongoose.Schema({
|
||||
timestamp: { type: Number, default: 0 },
|
||||
metal: { type: String, upercase: true, default: 'ØØØ' },
|
||||
currency: { type: String, upercase: true, default: 'ØØØ' },
|
||||
exchange: { type: String, upercase: true, default: '' },
|
||||
symbol: { type: String, upercase: true, default: '' },
|
||||
prev_close_price: { type: Number, default: 0 },
|
||||
open_price: { type: Number, default: 0 },
|
||||
low_price: { type: Number, default: 0 },
|
||||
high_price: { type: Number, default: 0 },
|
||||
open_time: { type: Number, default: 0 },
|
||||
price: { type: Number, default: 0 },
|
||||
ch: { type: Number, default: 0 },
|
||||
chp: { type: Number, default: 0 },
|
||||
ask: { type: Number, default: 0 },
|
||||
bid: { type: Number, default: 0 },
|
||||
price_gram_24k: { type: Number, default: 0 },
|
||||
price_gram_22k: { type: Number, default: 0 },
|
||||
price_gram_21k: { type: Number, default: 0 },
|
||||
price_gram_20k: { type: Number, default: 0 },
|
||||
price_gram_18k: { type: Number, default: 0 },
|
||||
price_gram_16k: { type: Number, default: 0 },
|
||||
price_gram_14k: { type: Number, default: 0 },
|
||||
price_gram_10k: { type: Number, default: 0 }
|
||||
}, { timestamps: true, toJSON: { virtuals: true } });
|
||||
|
||||
PriceSchema.plugin(uniqueValidator, { message: 'is already taken' });
|
||||
|
||||
PriceSchema.methods.toJSONFor = function () {
|
||||
/*
|
||||
let a = {
|
||||
timestamp: 1689944788,
|
||||
metal: "XAU",
|
||||
currency: "EUR",
|
||||
exchange: "FOREXCOM",
|
||||
symbol: "FOREXCOM:XAUEUR",
|
||||
prev_close_price: 0.00,
|
||||
open_price: 0.00,
|
||||
low_price: 0.00,
|
||||
high_price: 0.00,
|
||||
open_time: 1689897600,
|
||||
price: 0.00,
|
||||
ch: 0.00,
|
||||
chp: 0.00,
|
||||
ask: 0.00,
|
||||
bid: 0.00,
|
||||
price_gram_24k: 0.00,
|
||||
price_gram_22k: 0.00,
|
||||
price_gram_21k: 0.00,
|
||||
price_gram_20k: 0.00,
|
||||
price_gram_18k: 0.00,
|
||||
price_gram_16k: 0.00,
|
||||
price_gram_14k: 0.00,
|
||||
price_gram_10k: 0.00
|
||||
};
|
||||
*/
|
||||
return {
|
||||
timestamp: this.timestamp,
|
||||
metal: this.metal,
|
||||
currency: this.currency,
|
||||
exchange: this.exchange,
|
||||
symbol: this.symbol,
|
||||
prev_close_price: this.prev_close_price,
|
||||
open_price: this.open_price,
|
||||
low_price: this.low_price,
|
||||
high_price: this.high_price,
|
||||
open_time: this.open_time,
|
||||
price: this.price,
|
||||
ch: this.ch,
|
||||
chp: this.chp,
|
||||
ask: this.ask,
|
||||
bid: this.bid,
|
||||
price_gram_24k: this.price_gram_24k,
|
||||
price_gram_22k: this.price_gram_22k,
|
||||
price_gram_21k: this.price_gram_21k,
|
||||
price_gram_20k: this.price_gram_20k,
|
||||
price_gram_18k: this.price_gram_18k,
|
||||
price_gram_16k: this.price_gram_16k,
|
||||
price_gram_14k: this.price_gram_14k,
|
||||
price_gram_10k: this.price_gram_10k
|
||||
};
|
||||
};
|
||||
|
||||
mongoose.model('Price', PriceSchema);
|
||||
@@ -0,0 +1,58 @@
|
||||
var mongoose = require('mongoose');
|
||||
var uniqueValidator = require('mongoose-unique-validator');
|
||||
var slug = require('slug');
|
||||
var User = mongoose.model('User');
|
||||
|
||||
var ProductSchema = new mongoose.Schema({
|
||||
ordering: Number,
|
||||
title: String,
|
||||
slug: { type: String, lowercase: true, unique: true },
|
||||
prime_achat: Number,
|
||||
prime_vente: Number,
|
||||
metal: { type: mongoose.Schema.Types.ObjectId, ref: 'Metal' },
|
||||
poids: Number,
|
||||
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
|
||||
favoritesCount: { type: Number, default: 0 }
|
||||
}, {timestamps: true, toJSON: {virtuals: true}});
|
||||
|
||||
ProductSchema.plugin(uniqueValidator, { message: 'is already taken' });
|
||||
|
||||
ProductSchema.pre('validate', function (next) {
|
||||
if (!this.slug) {
|
||||
this.slugify();
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
ProductSchema.methods.slugify = function () {
|
||||
this.slug = slug(this.title) + '-' + (Math.random() * Math.pow(36, 6) | 0).toString(36);
|
||||
};
|
||||
|
||||
ProductSchema.methods.updateFavoriteCount = function () {
|
||||
var product = this;
|
||||
|
||||
return User.count({ favorites: { $in: [product._id] } }).then(function (count) {
|
||||
product.favoritesCount = count;
|
||||
|
||||
return product.save();
|
||||
});
|
||||
};
|
||||
|
||||
ProductSchema.methods.toJSONFor = function(user){
|
||||
return {
|
||||
ordering: this.ordering,
|
||||
title: this.title,
|
||||
slug: this.slug,
|
||||
prime_achat: this.prime_achat,
|
||||
prime_vente: this.prime_vente,
|
||||
metal: this.metal.toJSONFor(),
|
||||
poids: this.poids,
|
||||
createdAt: this.createdAt,
|
||||
updatedAt: this.updatedAt,
|
||||
favorited: user ? user.isFavorite(this._id) : false,
|
||||
favoritesCount: this.favoritesCount,
|
||||
author: this.author.toProfileJSONFor(user)
|
||||
};
|
||||
};
|
||||
|
||||
mongoose.model('Product', ProductSchema);
|
||||
@@ -0,0 +1,128 @@
|
||||
var mongoose = require('mongoose');
|
||||
var uniqueValidator = require('mongoose-unique-validator');
|
||||
var crypto = require('crypto');
|
||||
var jwt = require('jsonwebtoken');
|
||||
var secret = require('../../config').secret;
|
||||
|
||||
var UserSchema = new mongoose.Schema({
|
||||
email: { type: String, lowercase: true, unique: true, required: [true, "can't be blank"], match: [/\S+@\S+\.\S+/, 'is invalid'], index: true },
|
||||
username: { type: String, lowercase: true, unique: true, required: [true, "can't be blank"], match: [/^[a-zA-Z0-9_]+$/, 'is invalid'], index: true },
|
||||
role: String,
|
||||
firstname: { type: String, required: [true, "can't be blank"] },
|
||||
lastname: { type: String, required: [true, "can't be blank"] },
|
||||
phone: { type: String, required: [true, "can't be blank"] },
|
||||
licence: Number,
|
||||
image: String,
|
||||
bg_image: String,
|
||||
favorites: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Product' }],
|
||||
following: [{ type: mongoose.Schema.Types.ObjectId, ref: 'User' }],
|
||||
hash: String,
|
||||
salt: String
|
||||
}, { timestamps: true, toJSON: { virtuals: true } });
|
||||
|
||||
UserSchema.plugin(uniqueValidator, { message: 'is already taken.' });
|
||||
|
||||
UserSchema.methods.validPassword = function (password) {
|
||||
var hash = crypto.pbkdf2Sync(password, this.salt, 10000, 512, 'sha512').toString('hex');
|
||||
return this.hash === hash;
|
||||
};
|
||||
|
||||
UserSchema.methods.setPassword = function (password) {
|
||||
this.salt = crypto.randomBytes(16).toString('hex');
|
||||
this.hash = crypto.pbkdf2Sync(password, this.salt, 10000, 512, 'sha512').toString('hex');
|
||||
};
|
||||
|
||||
UserSchema.methods.generateJWT = function () {
|
||||
var today = new Date();
|
||||
var exp = new Date(today);
|
||||
exp.setDate(today.getDate() + 60);
|
||||
|
||||
return jwt.sign({
|
||||
id: this._id,
|
||||
username: this.username,
|
||||
exp: parseInt(exp.getTime() / 1000)
|
||||
}, secret, { algorithm: 'HS256' });
|
||||
};
|
||||
|
||||
UserSchema.methods.toAuthJSON = function () {
|
||||
return {
|
||||
email: this.email,
|
||||
role: this.role,
|
||||
token: this.generateJWT(),
|
||||
firstname: this.firstname,
|
||||
lastname: this.lastname,
|
||||
phone: this.phone,
|
||||
licence: this.licence,
|
||||
username: this.username,
|
||||
image: this.image || '/assets/images/users/user.jpg',
|
||||
bg_image: this.bg_image || '/assets/images/users/bg_user.jpg'
|
||||
};
|
||||
};
|
||||
|
||||
UserSchema.methods.toJSONFor = function () {
|
||||
return {
|
||||
email: this.email,
|
||||
role: this.role,
|
||||
firstname: this.firstname,
|
||||
lastname: this.lastname,
|
||||
phone: this.phone,
|
||||
licence: this.licence,
|
||||
username: this.username,
|
||||
image: this.image || '/assets/images/users/user.jpg',
|
||||
bg_image: this.bg_image || '/assets/images/users/bg_user.jpg'
|
||||
};
|
||||
};
|
||||
|
||||
UserSchema.methods.toProfileJSONFor = function (user) {
|
||||
return {
|
||||
email: this.email,
|
||||
firstname: this.firstname,
|
||||
lastname: this.lastname,
|
||||
phone: this.phone,
|
||||
licence: this.licence,
|
||||
username: this.username,
|
||||
image: this.image || '/assets/images/users/user.jpg',
|
||||
bg_image: this.bg_image || '/assets/images/users/bg_user.jpg',
|
||||
following: user ? user.isFollowing(this._id) : false
|
||||
};
|
||||
};
|
||||
|
||||
UserSchema.methods.favorite = function (id) {
|
||||
if (this.favorites.indexOf(id) === -1) {
|
||||
this.favorites.push(id);
|
||||
}
|
||||
|
||||
return this.save();
|
||||
};
|
||||
|
||||
UserSchema.methods.unfavorite = function (id) {
|
||||
this.favorites.remove(id);
|
||||
return this.save();
|
||||
};
|
||||
|
||||
UserSchema.methods.isFavorite = function (id) {
|
||||
return this.favorites.some(function (favoriteId) {
|
||||
return favoriteId.toString() === id.toString();
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.methods.follow = function (id) {
|
||||
if (this.following.indexOf(id) === -1) {
|
||||
this.following.push(id);
|
||||
}
|
||||
|
||||
return this.save();
|
||||
};
|
||||
|
||||
UserSchema.methods.unfollow = function (id) {
|
||||
this.following.remove(id);
|
||||
return this.save();
|
||||
};
|
||||
|
||||
UserSchema.methods.isFollowing = function (id) {
|
||||
return this.following.some(function (followId) {
|
||||
return followId.toString() === id.toString();
|
||||
});
|
||||
};
|
||||
|
||||
mongoose.model('User', UserSchema);
|
||||
Reference in New Issue
Block a user