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
+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)