Update
This commit is contained in:
parent
80b0ea401b
commit
c620e19449
23 changed files with 919 additions and 0 deletions
18
app-backend/models/ad.model.js
Normal file
18
app-backend/models/ad.model.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
module.exports = mongoose => {
|
||||
let schema = mongoose.Schema({
|
||||
images: [],
|
||||
text: String,
|
||||
subjectTarget: [],
|
||||
seen: Number
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
|
||||
return mongoose.model("ad", schema);
|
||||
};
|
||||
15
app-backend/models/history.model.js
Normal file
15
app-backend/models/history.model.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
module.exports = mongoose => {
|
||||
let schema = mongoose.Schema({
|
||||
user: Object
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
|
||||
return mongoose.model("history", schema);
|
||||
};
|
||||
18
app-backend/models/image.model.js
Normal file
18
app-backend/models/image.model.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
module.exports = mongoose => {
|
||||
let schema = mongoose.Schema({
|
||||
base64: String,
|
||||
fromUrl: String,
|
||||
description: String,
|
||||
type: Number
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
|
||||
return mongoose.model("image", schema);
|
||||
};
|
||||
20
app-backend/models/mongodb.model.js
Normal file
20
app-backend/models/mongodb.model.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
const dbConfig = require("../config/mongodb.config");
|
||||
const mongoose = require("mongoose");
|
||||
mongoose.Promise = global.Promise;
|
||||
|
||||
const db = {};
|
||||
db.mongoose = mongoose;
|
||||
|
||||
if(typeof process.env.NODE_ENV !== 'undefined' && process.env.NODE_ENV === 'production'){
|
||||
db.url = dbConfig.prodUrl;
|
||||
} else {
|
||||
db.url = dbConfig.devUrl;
|
||||
}
|
||||
|
||||
db.users = require("./user.model")(mongoose);
|
||||
db.playlists = require("./playlist.model")(mongoose);
|
||||
db.ads = require("./ad.model")(mongoose);
|
||||
db.histories = require("./history.model")(mongoose);
|
||||
|
||||
|
||||
module.exports = db;
|
||||
17
app-backend/models/playlist.model.js
Normal file
17
app-backend/models/playlist.model.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
module.exports = mongoose => {
|
||||
let schema = mongoose.Schema({
|
||||
userId: String,
|
||||
name: String,
|
||||
videos: Array
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
|
||||
return mongoose.model("playlist", schema);
|
||||
};
|
||||
16
app-backend/models/subjectTarget.model.js
Normal file
16
app-backend/models/subjectTarget.model.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
module.exports = mongoose => {
|
||||
let schema = mongoose.Schema({
|
||||
name: String,
|
||||
keywords: []
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
|
||||
return mongoose.model("subjectTarget", schema);
|
||||
};
|
||||
43
app-backend/models/user.model.js
Normal file
43
app-backend/models/user.model.js
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
const roles = require("../config/role.config");
|
||||
|
||||
module.exports = mongoose => {
|
||||
let schema = mongoose.Schema({
|
||||
login: String,
|
||||
hashPass: String, // WARNING: We don't want to send back the hashPass
|
||||
mail: String,
|
||||
role: {
|
||||
type: Object,
|
||||
default: roles.User
|
||||
},
|
||||
profilePictureUrl: {
|
||||
type: String,
|
||||
default: null
|
||||
},
|
||||
dateOfBirth: {
|
||||
type: Date,
|
||||
default: null
|
||||
},
|
||||
gender: {
|
||||
type: String,
|
||||
default: null
|
||||
},
|
||||
interests: {
|
||||
type: Array,
|
||||
default: null
|
||||
},
|
||||
active: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
|
||||
return mongoose.model("user", schema);
|
||||
};
|
||||
18
app-backend/models/video.model.js
Normal file
18
app-backend/models/video.model.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
module.exports = mongoose => {
|
||||
let schema = mongoose.Schema({
|
||||
url: String,
|
||||
title: String,
|
||||
description: String,
|
||||
views: Number
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
schema.method("toJSON", function() {
|
||||
const { __v, _id, ...object } = this.toObject();
|
||||
object.id = _id;
|
||||
return object;
|
||||
});
|
||||
|
||||
return mongoose.model("video", schema);
|
||||
};
|
||||
Reference in a new issue