This commit is contained in:
Yûki VACHOT 2021-10-29 11:22:24 +02:00
parent 4dfd8cd516
commit 5a64568824
22 changed files with 702 additions and 194 deletions

View file

@ -0,0 +1,12 @@
const dbConfig = require("../config/mongodb.config");
const mongoose = require("mongoose");
mongoose.Promise = global.Promise;
const db = {};
db.mongoose = mongoose;
db.url = dbConfig.url;
db.tutorials = require("./tutorial.model")(mongoose);
db.users = require("./user.model")(mongoose);
module.exports = db;

View file

@ -0,0 +1,17 @@
module.exports = mongoose => {
let schema = mongoose.Schema({
title: String,
description: String,
published: Boolean
},
{ timestamps: true }
);
schema.method("toJSON", function() {
const { __v, _id, ...object } = this.toObject();
object.id = _id;
return object;
});
return mongoose.model("tutorial", schema);
};

View file

@ -0,0 +1,18 @@
module.exports = mongoose => {
let schema = mongoose.Schema({
login: String,
hashPass: String, // WARNING: We don't want to send back the hashPass
mail: String,
role: Object
},
{ timestamps: true }
);
schema.method("toJSON", function() {
const { __v, _id, ...object } = this.toObject();
object.id = _id;
return object;
});
return User = mongoose.model("user", schema);
};