Implémentation SkydiverId API

This commit is contained in:
Rampeur
2024-05-08 20:37:33 +02:00
parent eb64f2c411
commit a4d2b76bc5
43 changed files with 2772 additions and 1267 deletions
-1
View File
@@ -1,5 +1,4 @@
var mongoose = require('mongoose');
var User = mongoose.model('User');
var slug = require('slug');
var AeronefSchema = new mongoose.Schema({
-1
View File
@@ -1,5 +1,4 @@
var mongoose = require('mongoose');
var User = mongoose.model('User');
var slug = require('slug');
var CanopySchema = new mongoose.Schema({
-20
View File
@@ -1,20 +0,0 @@
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');
-1
View File
@@ -1,5 +1,4 @@
var mongoose = require('mongoose');
var User = mongoose.model('User');
var slug = require('slug');
var DropzoneSchema = new mongoose.Schema({
+17 -2
View File
@@ -1,5 +1,4 @@
var mongoose = require('mongoose');
var User = mongoose.model('User');
var uniqueValidator = require('mongoose-unique-validator');
var slug = require('slug');
@@ -24,6 +23,8 @@ var JumpSchema = new mongoose.Schema({
zone: String,
dossier: String,
video: String,
files: [{ type: mongoose.Schema.Types.ObjectId, ref: 'JumpFile' }],
x2data: { type: mongoose.Schema.Types.ObjectId, ref: 'X2DataLog' },
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }
}, {timestamps: true, toJSON: {virtuals: true}});
@@ -40,7 +41,19 @@ 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){
JumpSchema.methods.addFile = function (id) {
if (this.files.indexOf(id) === -1) {
this.files.push(id);
}
return this.save();
};
JumpSchema.methods.removeFile = function (id) {
this.files.remove(id);
return this.save();
};
JumpSchema.methods.toJSONFor = function(user) {
return {
slug: this.slug,
date: this.date,
@@ -62,6 +75,8 @@ JumpSchema.methods.toJSONFor = function(user){
zone: this.zone,
dossier: this.dossier,
video: this.video,
files: this.files.map(file => file ? file.toJSONForJump() : null),
x2data: this.x2data ? this.x2data.toJSONFor() : null,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
author: this.author.toProfileJSONFor(user)
+51
View File
@@ -0,0 +1,51 @@
var mongoose = require('mongoose');
var uniqueValidator = require('mongoose-unique-validator');
var slug = require('slug');
var JumpFileSchema = new mongoose.Schema({
slug: { type: String, lowercase: true, unique: true },
name: String,
path: String,
type: {
type: String,
enum : ['csv', 'image', 'kml', 'video'],
default: 'video'
},
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }
}, {timestamps: true, toJSON: {virtuals: true}});
JumpFileSchema.plugin(uniqueValidator, { message: 'is already taken' });
JumpFileSchema.pre('validate', function (next) {
if (!this.slug) {
this.slugify();
}
next();
});
JumpFileSchema.methods.slugify = function () {
this.slug = slug(`${this.type}`) + '-' + (Math.random() * Math.pow(36, 6) | 0).toString(36) + (Math.random() * Math.pow(36, 6) | 0).toString(36);
};
JumpFileSchema.methods.toJSONFor = function(user){
return {
slug: this.slug,
name: this.name,
path: this.path,
type: this.type,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
author: this.author.toProfileJSONFor(user)
};
};
JumpFileSchema.methods.toJSONForJump = function(){
return {
slug: this.slug,
name: this.name,
path: this.path,
type: this.type
};
};
mongoose.model('JumpFile', JumpFileSchema);
-24
View File
@@ -1,24 +0,0 @@
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);
-87
View File
@@ -1,87 +0,0 @@
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);
-58
View File
@@ -1,58 +0,0 @@
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);
+31 -8
View File
@@ -2,22 +2,45 @@ var mongoose = require('mongoose');
var uniqueValidator = require('mongoose-unique-validator');
var slug = require('slug');
var QCMSchema = new mongoose.Schema({
var QcmSchema = new mongoose.Schema({
name: { type: String, lowercase: true, unique: true },
slug: { type: String, lowercase: true, unique: true },
categories: [
{ type: mongoose.Schema.Types.ObjectId, ref: 'QCMCategory' }
{ type: mongoose.Schema.Types.ObjectId, ref: 'QcmCategory' }
]
}, {timestamps: true, toJSON: {virtuals: true}});
QCMSchema.plugin(uniqueValidator, { message: 'is already taken' });
QcmSchema.plugin(uniqueValidator, { message: 'is already taken' });
QCMSchema.methods.toJSONFor = function(){
QcmSchema.pre('validate', function (next) {
if (!this.slug) {
this.slugify();
}
next();
});
QcmSchema.methods.slugify = function () {
this.slug = slug(`${this.name}-`) + (Math.random() * Math.pow(36, 6) | 0).toString(36);
};
QcmSchema.methods.addCategory = function (id) {
if (this.categories.indexOf(id) === -1) {
this.categories.push(id);
}
return this.save();
};
QcmSchema.methods.removeCategory = function (id) {
this.categories.remove(id);
return this.save();
};
QcmSchema.methods.toJSONFor = function() {
return {
name: this.name,
categories: this.categories,
createdAt: this.createdAt,
updatedAt: this.updatedAt
slug: this.slug,
categories: this.categories.map(category => category.toJSONFor())
};
};
mongoose.model('QCM', QCMSchema);
mongoose.model('Qcm', QcmSchema);
-23
View File
@@ -1,23 +0,0 @@
var mongoose = require('mongoose');
var uniqueValidator = require('mongoose-unique-validator');
var slug = require('slug');
var QCMCategorySchema = new mongoose.Schema({
num: number,
name: { type: String, lowercase: true, unique: true },
questions: []
}, {timestamps: true, toJSON: {virtuals: true}});
QCMCategorySchema.plugin(uniqueValidator, { message: 'is already taken' });
QCMCategorySchema.methods.toJSONFor = function(){
return {
num: this.num,
name: this.name,
questions: this.questions,
createdAt: this.createdAt,
updatedAt: this.updatedAt
};
};
mongoose.model('QCMCategory', QCMCategorySchema);
+48
View File
@@ -0,0 +1,48 @@
var mongoose = require('mongoose');
var uniqueValidator = require('mongoose-unique-validator');
var slug = require('slug');
var QcmCategorySchema = new mongoose.Schema({
num: Number,
name: { type: String, unique: true },
slug: { type: String, lowercase: true, unique: true },
questions: [
{ type: mongoose.Schema.Types.ObjectId, ref: 'QcmQuestion' }
]
}, {timestamps: true, toJSON: {virtuals: true}});
QcmCategorySchema.plugin(uniqueValidator, { message: 'is already taken' });
QcmCategorySchema.pre('validate', function (next) {
if (!this.slug) {
this.slugify();
}
next();
});
QcmCategorySchema.methods.slugify = function () {
this.slug = slug(`${this.name}-${this.num}-`) + (Math.random() * Math.pow(36, 6) | 0).toString(36);
};
QcmCategorySchema.methods.addQuestion = function (id) {
if (this.questions.indexOf(id) === -1) {
this.questions.push(id);
}
return this.save();
};
QcmCategorySchema.methods.removeQuestion = function (id) {
this.questions.remove(id);
return this.save();
};
QcmCategorySchema.methods.toJSONFor = function() {
return {
num: this.num,
name: this.name,
slug: this.slug,
questions: this.questions.map(question => question.toJSONFor())
};
};
mongoose.model('QcmCategory', QcmCategorySchema);
+17
View File
@@ -0,0 +1,17 @@
var mongoose = require('mongoose');
var QcmChoiceSchema = new mongoose.Schema({
index: String,
libelle: String,
correct: Boolean
}, {timestamps: true, toJSON: {virtuals: true}});
QcmChoiceSchema.methods.toJSONFor = function() {
return {
index: this.index,
libelle: this.libelle,
correct: this.correct
};
};
mongoose.model('QcmChoice', QcmChoiceSchema);
+31
View File
@@ -0,0 +1,31 @@
var mongoose = require('mongoose');
var QcmQuestionSchema = new mongoose.Schema({
num: Number,
libelle: String,
choices: [
{ type: mongoose.Schema.Types.ObjectId, ref: 'QcmChoice' }
]
}, {timestamps: true, toJSON: {virtuals: true}});
QcmQuestionSchema.methods.addChoice = function (id) {
if (this.choices.indexOf(id) === -1) {
this.choices.push(id);
}
return this.save();
};
QcmQuestionSchema.methods.removeChoice = function (id) {
this.choices.remove(id);
return this.save();
};
QcmQuestionSchema.methods.toJSONFor = function() {
return {
num: this.num,
libelle: this.libelle,
choices: this.choices.map(choice => choice.toJSONFor())
};
};
mongoose.model('QcmQuestion', QcmQuestionSchema);
+3 -3
View File
@@ -24,7 +24,7 @@ var UserSchema = new mongoose.Schema({
UserSchema.plugin(uniqueValidator, { message: 'is already taken.' });
UserSchema.methods.validPassword = function (password) {
var hash = crypto.pbkdf2Sync(password, this.salt, 10000, 512, 'sha512').toString('hex');
let hash = crypto.pbkdf2Sync(password, this.salt, 10000, 512, 'sha512').toString('hex');
return this.hash === hash;
};
@@ -34,8 +34,8 @@ UserSchema.methods.setPassword = function (password) {
};
UserSchema.methods.generateJWT = function () {
var today = new Date();
var exp = new Date(today);
let today = new Date();
let exp = new Date(today);
exp.setDate(today.getDate() + 60);
return jwt.sign({
+107
View File
@@ -0,0 +1,107 @@
var mongoose = require('mongoose');
var X2DataLogSchema = new mongoose.Schema({
id: String,
name: String,
type: String,
description: String,
landingZone: String,
speed: {
freeFall: {
vertical: {
max: Number,
avg: Number
},
horizontal: {
max: Number,
avg: Number
}
},
underCanopy: {
vertical: {
max: Number,
avg: Number
},
horizontal: {
max: Number,
avg: Number
}
}
},
glideRatio: {
freeFall: {
max: Number,
avg: Number
},
underCanopy: {
max: Number,
avg: Number
}
},
duration: {
freeFall: Number,
underCanopy: Number
},
distance: {
exitFromLandingZone: Number,
totalFlying: Number,
totalHorizontal: Number
},
altitude: {
exit: Number,
deployment: Number
},
cutaway: String,
malfunctions: [
{
name: String,
type: String
}
],
date: String,
createdOn: String,
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }
}, {timestamps: true, toJSON: {virtuals: true}});
X2DataLogSchema.methods.toJSONFor = function() {
return {
id: this.id,
name: this.name,
type: this.type,
description: this.description,
landingZone: this.landingZone,
speed: this.speed,
glideRatio: this.glideRatio,
duration: this.duration,
distance: this.distance,
altitude: this.altitude,
cutaway: this.cutaway,
malfunctions: this.malfunctions,
date: this.date,
createdOn: this.createdOn
};
};
X2DataLogSchema.methods.toJSONForUser = function(user) {
return {
id: this.id,
name: this.name,
type: this.type,
description: this.description,
landingZone: this.landingZone,
speed: this.speed,
glideRatio: this.glideRatio,
duration: this.duration,
distance: this.distance,
altitude: this.altitude,
cutaway: this.cutaway,
malfunctions: this.malfunctions,
date: this.date,
createdOn: this.createdOn,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
author: this.author.toProfileJSONFor(user)
};
};
mongoose.model('X2DataLog', X2DataLogSchema);
+13
View File
@@ -0,0 +1,13 @@
exports.User = require('./User');
exports.Application = require('./Application');
exports.Aeronef = require('./Aeronef');
exports.Canopy = require('./Canopy');
exports.Dropzone = require('./Dropzone');
exports.JumpFile = require('./JumpFile');
exports.Jump = require('./Jump');
exports.Qcm = require('./Qcm');
exports.QcmCategory = require('./QcmCategory');
exports.QcmQuestion = require('./QcmQuestion');
exports.QcmChoice = require('./QcmChoice');
exports.X2DataLog = require('./X2DataLog');