Files
freeplanet_serverside/server/models/project.js
Paolo Arena 7c3684813a Added begin_development and begin_test
Added status (changed completed field)
fixed internet status connection.
2019-04-02 00:27:59 +02:00

150 lines
2.3 KiB
JavaScript

var mongoose = require('mongoose');
const _ = require('lodash');
const tools = require('../tools/general');
mongoose.Promise = global.Promise;
mongoose.level = "F";
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
mongoose.set('debug', process.env.DEBUG);
var ProjectSchema = new mongoose.Schema({
userId: {
type: String,
},
pos: {
type: Number,
},
descr: {
type: String,
},
longdescr: {
type: String,
},
hoursplanned: {
type: Number,
},
hoursworked: {
type: Number,
},
id_parent: {
type: String,
},
priority: {
type: Number,
},
status: {
type: Number,
default: 0
},
created_at: {
type: Date
},
modify_at: {
type: Date
},
completed_at: {
type: Date
},
expiring_at: {
type: Date,
},
enableExpiring: {
type: Boolean,
default: false
},
id_prev: {
type: String,
},
progressCalc: {
type: Number,
},
modified: {
type: Boolean,
},
live_url: {
type: String,
},
test_url: {
type: String,
},
begin_development: {
type: Date,
},
begin_test: {
type: Date,
},
});
ProjectSchema.methods.toJSON = function () {
var Project = this;
var projObject = Project.toObject();
// console.log(projObject);
return _.pick(projObject, tools.allfieldProjectWithId());
};
ProjectSchema.statics.findByUserIdAndCat = function (userId, category) {
var Project = this;
return Project.find({
'userId': userId,
'category': category,
});
};
ProjectSchema.statics.findAllByUserId = function (userId) {
var Project = this;
return Project.find({
'userId': userId,
}).then(ris => {
return ris
})
};
ProjectSchema.statics.getArrCategoryInTable = function (userId) {
var Project = this;
return Project.find({ 'userId': userId }).distinct("category")
.then(arrcategory => {
return arrcategory
})
};
ProjectSchema.statics.getAllProjects = async function (userId) {
var Project = this;
let obj = [];
obj.arrproj = await Project.findAllByUserId(userId);
return obj;
};
ProjectSchema.pre('save', function (next) {
// var Project = this;
// console.log('Project.expiring_at', Project.expiring_at);
next();
});
var Project = mongoose.model('Projects', ProjectSchema);
module.exports = { Project };