correzione numseen, numfav, ...: ora li ho aggiunti alle tabelle...
This commit is contained in:
@@ -6,98 +6,104 @@ mongoose.level = 'F';
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const { Reaction } = require('./reaction');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true;
|
||||
});
|
||||
|
||||
const MySkillSchema = new Schema({
|
||||
_id: {
|
||||
type: String,
|
||||
default: function () {
|
||||
return new ObjectID().toString();
|
||||
const MySkillSchema = new Schema(
|
||||
{
|
||||
...{
|
||||
_id: {
|
||||
type: String,
|
||||
default: function () {
|
||||
return new ObjectID().toString();
|
||||
},
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
userId: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||
idSector: {
|
||||
type: Number,
|
||||
},
|
||||
idSkill: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
/*idSubSkill: [
|
||||
{
|
||||
type: Number,
|
||||
default: 0,
|
||||
}],
|
||||
|
||||
*/
|
||||
idStatusSkill: [
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
idContribType: [
|
||||
{
|
||||
type: String,
|
||||
}],
|
||||
idCity: [
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
pub_to_share: {
|
||||
type: Number, // PUB_TO_SHARE_ALL, PUB_TO_SHARE_ONLY_TABLE_FOLLOW
|
||||
},
|
||||
numLevel: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
adType: {
|
||||
type: Number,
|
||||
},
|
||||
photos: [
|
||||
{
|
||||
imagefile: {
|
||||
type: String,
|
||||
},
|
||||
alt: {
|
||||
type: String,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
},
|
||||
}],
|
||||
note: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
descr: {
|
||||
type: String,
|
||||
},
|
||||
//**ADDFIELD_MYSKILL
|
||||
website: {
|
||||
type: String,
|
||||
},
|
||||
date_created: {
|
||||
type: Date,
|
||||
},
|
||||
date_updated: {
|
||||
type: Date,
|
||||
},
|
||||
},
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
userId: {type: Schema.Types.ObjectId, ref: 'User'},
|
||||
idSector: {
|
||||
type: Number,
|
||||
},
|
||||
idSkill: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
/*idSubSkill: [
|
||||
{
|
||||
type: Number,
|
||||
default: 0,
|
||||
}],
|
||||
|
||||
*/
|
||||
idStatusSkill: [
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
idContribType: [
|
||||
{
|
||||
type: String,
|
||||
}],
|
||||
idCity: [
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
pub_to_share: {
|
||||
type: Number, // PUB_TO_SHARE_ALL, PUB_TO_SHARE_ONLY_TABLE_FOLLOW
|
||||
},
|
||||
numLevel: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
adType: {
|
||||
type: Number,
|
||||
},
|
||||
photos: [
|
||||
{
|
||||
imagefile: {
|
||||
type: String,
|
||||
},
|
||||
alt: {
|
||||
type: String,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
},
|
||||
}],
|
||||
note: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
descr: {
|
||||
type: String,
|
||||
},
|
||||
//**ADDFIELD_MYSKILL
|
||||
website: {
|
||||
type: String,
|
||||
},
|
||||
date_created: {
|
||||
type: Date,
|
||||
},
|
||||
date_updated: {
|
||||
type: Date,
|
||||
},
|
||||
});
|
||||
...Reaction.getFieldsForReactions()
|
||||
});
|
||||
|
||||
MySkillSchema.index({ 'idapp': 1 });
|
||||
|
||||
|
||||
MySkillSchema.pre('save', async function(next) {
|
||||
MySkillSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
if (!this.date_created)
|
||||
this.date_created = new Date();
|
||||
@@ -106,12 +112,12 @@ MySkillSchema.pre('save', async function(next) {
|
||||
next();
|
||||
});
|
||||
|
||||
MySkillSchema.statics.findAllIdApp = async function(idapp) {
|
||||
MySkillSchema.statics.findAllIdApp = async function (idapp) {
|
||||
const MySkill = this;
|
||||
|
||||
const query = [
|
||||
{$match: {idapp}},
|
||||
{$sort: {descr: 1}},
|
||||
{ $match: { idapp } },
|
||||
{ $sort: { descr: 1 } },
|
||||
];
|
||||
|
||||
return await MySkill.aggregate(query).then((arrrec) => {
|
||||
@@ -120,20 +126,20 @@ MySkillSchema.statics.findAllIdApp = async function(idapp) {
|
||||
|
||||
};
|
||||
|
||||
MySkillSchema.statics.getFieldsForSearch = function() {
|
||||
MySkillSchema.statics.getFieldsForSearch = function () {
|
||||
return [];
|
||||
};
|
||||
|
||||
MySkillSchema.statics.getFieldsLastForSearch = function() {
|
||||
MySkillSchema.statics.getFieldsLastForSearch = function () {
|
||||
return [
|
||||
{field: 'note', type: tools.FieldType.string},
|
||||
{field: 'descr', type: tools.FieldType.string},
|
||||
{field: 'recSkill.descr', type: tools.FieldType.string},
|
||||
{field: 'myskill.descr', type: tools.FieldType.string},
|
||||
{ field: 'note', type: tools.FieldType.string },
|
||||
{ field: 'descr', type: tools.FieldType.string },
|
||||
{ field: 'recSkill.descr', type: tools.FieldType.string },
|
||||
{ field: 'myskill.descr', type: tools.FieldType.string },
|
||||
];
|
||||
};
|
||||
|
||||
MySkillSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
MySkillSchema.statics.executeQueryTable = function (idapp, params, user) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
params.fieldsearch_last = this.getFieldsLastForSearch();
|
||||
|
||||
@@ -148,12 +154,12 @@ MySkillSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
},
|
||||
};
|
||||
|
||||
params = {...params, ...otherparams};
|
||||
params = { ...params, ...otherparams };
|
||||
|
||||
return tools.executeQueryTable(this, idapp, params, user);
|
||||
};
|
||||
|
||||
MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
MySkillSchema.statics.getMyRecById = function (idapp, idSkill) {
|
||||
const MySkill = this;
|
||||
|
||||
let query = [
|
||||
@@ -314,7 +320,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
$project: this.getProject(objadd.proj),
|
||||
};
|
||||
|
||||
query = [...query, {...toadd}];
|
||||
query = [...query, { ...toadd }];
|
||||
|
||||
return MySkill.aggregate(query).then((rec) => {
|
||||
return rec ? rec[0] : null;
|
||||
@@ -336,10 +342,10 @@ MySkillSchema.statics.getProject = function (proj_add2) {
|
||||
const proj_add = shared_consts.getProjectForAll(proj_add2)
|
||||
|
||||
return Object.assign({}, proj, proj_add);
|
||||
|
||||
|
||||
}
|
||||
|
||||
MySkillSchema.statics.getCompleteRecord = function(idapp, id) {
|
||||
MySkillSchema.statics.getCompleteRecord = function (idapp, id) {
|
||||
const MySkill = this;
|
||||
|
||||
return MySkill.getMyRecById(idapp, id);
|
||||
@@ -348,4 +354,4 @@ MySkillSchema.statics.getCompleteRecord = function(idapp, id) {
|
||||
|
||||
const MySkill = mongoose.model('MySkill', MySkillSchema);
|
||||
|
||||
module.exports = {MySkill};
|
||||
module.exports = { MySkill };
|
||||
|
||||
Reference in New Issue
Block a user