Implémentation SkydiverId API
This commit is contained in:
+17
-2
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user