2022-09-14 11:32:04 +02:00
|
|
|
const mongoose = require('mongoose').set('debug', false);
|
2021-10-08 00:38:35 +02:00
|
|
|
const Schema = mongoose.Schema;
|
|
|
|
|
|
|
|
|
|
mongoose.Promise = global.Promise;
|
|
|
|
|
mongoose.level = 'F';
|
|
|
|
|
|
|
|
|
|
const tools = require('../tools/general');
|
|
|
|
|
|
2023-04-07 02:45:21 +02:00
|
|
|
const shared_consts = require('../tools/shared_nodejs');
|
|
|
|
|
|
2021-10-08 00:38:35 +02:00
|
|
|
const {ObjectID} = require('mongodb');
|
|
|
|
|
|
|
|
|
|
// Resolving error Unknown modifier: $pushAll
|
|
|
|
|
mongoose.plugin(schema => {
|
|
|
|
|
schema.options.usePushEach = true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const MySkillSchema = new Schema({
|
|
|
|
|
_id: {
|
2023-04-04 15:26:56 +02:00
|
|
|
type: String,
|
|
|
|
|
default: function () {
|
|
|
|
|
return new ObjectID().toString();
|
|
|
|
|
},
|
2021-10-08 00:38:35 +02:00
|
|
|
},
|
|
|
|
|
idapp: {
|
|
|
|
|
type: String,
|
|
|
|
|
required: true,
|
|
|
|
|
},
|
2021-10-28 00:38:10 +02:00
|
|
|
userId: {type: Schema.Types.ObjectId, ref: 'User'},
|
2022-01-28 00:57:39 +01:00
|
|
|
idSector: {
|
|
|
|
|
type: Number,
|
|
|
|
|
},
|
2021-10-08 00:38:35 +02:00
|
|
|
idSkill: {
|
|
|
|
|
type: Number,
|
2021-12-02 10:13:27 +01:00
|
|
|
default: 0,
|
2021-10-08 00:38:35 +02:00
|
|
|
},
|
2022-02-21 13:12:27 +01:00
|
|
|
/*idSubSkill: [
|
2021-12-31 01:44:28 +01:00
|
|
|
{
|
|
|
|
|
type: Number,
|
|
|
|
|
default: 0,
|
|
|
|
|
}],
|
2022-02-21 13:12:27 +01:00
|
|
|
|
|
|
|
|
*/
|
2021-10-28 00:38:10 +02:00
|
|
|
idStatusSkill: [
|
|
|
|
|
{
|
|
|
|
|
type: Number,
|
|
|
|
|
}],
|
2021-12-21 01:27:45 +01:00
|
|
|
idContribType: [
|
|
|
|
|
{
|
|
|
|
|
type: String,
|
|
|
|
|
}],
|
2021-10-28 00:38:10 +02:00
|
|
|
idCity: [
|
|
|
|
|
{
|
|
|
|
|
type: Number,
|
|
|
|
|
}],
|
2022-06-16 20:34:42 +02:00
|
|
|
pub_to_share: {
|
2022-09-19 14:37:57 +02:00
|
|
|
type: Number, // PUB_TO_SHARE_ALL, PUB_TO_SHARE_ONLY_TABLE_FOLLOW
|
2022-06-16 20:34:42 +02:00
|
|
|
},
|
2021-10-08 00:38:35 +02:00
|
|
|
numLevel: {
|
|
|
|
|
type: Number,
|
2021-12-02 10:13:27 +01:00
|
|
|
default: 0,
|
2021-10-08 00:38:35 +02:00
|
|
|
},
|
2022-02-12 02:20:07 +01:00
|
|
|
adType: {
|
|
|
|
|
type: Number,
|
|
|
|
|
},
|
2021-10-28 00:38:10 +02:00
|
|
|
photos: [
|
|
|
|
|
{
|
|
|
|
|
imagefile: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
alt: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
description: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
}],
|
2021-10-08 00:38:35 +02:00
|
|
|
note: {
|
|
|
|
|
type: String,
|
2022-02-05 23:28:15 +01:00
|
|
|
default: '',
|
2021-10-08 00:38:35 +02:00
|
|
|
},
|
2022-01-28 00:57:39 +01:00
|
|
|
descr: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
2022-02-17 17:43:45 +01:00
|
|
|
//**ADDFIELD_MYSKILL
|
2022-02-17 00:45:10 +01:00
|
|
|
website: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
2021-10-08 00:38:35 +02:00
|
|
|
date_created: {
|
|
|
|
|
type: Date,
|
|
|
|
|
},
|
|
|
|
|
date_updated: {
|
|
|
|
|
type: Date,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2023-09-27 18:38:57 +02:00
|
|
|
MySkillSchema.index({ 'idapp': 1 });
|
|
|
|
|
|
|
|
|
|
|
2021-10-28 00:38:10 +02:00
|
|
|
MySkillSchema.pre('save', async function(next) {
|
2021-10-08 00:38:35 +02:00
|
|
|
if (this.isNew) {
|
2023-04-07 02:45:21 +02:00
|
|
|
if (!this.date_created)
|
|
|
|
|
this.date_created = new Date();
|
2021-10-08 00:38:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
|
2021-12-23 14:13:40 +01:00
|
|
|
MySkillSchema.statics.findAllIdApp = async function(idapp) {
|
2022-01-26 01:31:22 +01:00
|
|
|
const MySkill = this;
|
2021-10-08 00:38:35 +02:00
|
|
|
|
|
|
|
|
const query = [
|
2021-10-28 00:38:10 +02:00
|
|
|
{$match: {idapp}},
|
2021-10-08 00:38:35 +02:00
|
|
|
{$sort: {descr: 1}},
|
|
|
|
|
];
|
|
|
|
|
|
2022-09-11 11:45:33 +02:00
|
|
|
return await MySkill.aggregate(query).then((arrrec) => {
|
2021-10-08 00:38:35 +02:00
|
|
|
return arrrec;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MySkillSchema.statics.getFieldsForSearch = function() {
|
2022-02-12 02:20:07 +01:00
|
|
|
return [];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MySkillSchema.statics.getFieldsLastForSearch = function() {
|
2022-01-23 23:25:34 +01:00
|
|
|
return [
|
2022-02-12 02:20:07 +01:00
|
|
|
{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},
|
2022-01-23 23:25:34 +01:00
|
|
|
];
|
2021-10-08 00:38:35 +02:00
|
|
|
};
|
|
|
|
|
|
2022-06-16 20:34:42 +02:00
|
|
|
MySkillSchema.statics.executeQueryTable = function(idapp, params, user) {
|
2021-10-08 00:38:35 +02:00
|
|
|
params.fieldsearch = this.getFieldsForSearch();
|
2022-02-12 02:20:07 +01:00
|
|
|
params.fieldsearch_last = this.getFieldsLastForSearch();
|
2021-12-11 00:25:54 +01:00
|
|
|
|
|
|
|
|
const otherparams = {
|
2021-12-21 01:27:45 +01:00
|
|
|
lookup1: {
|
|
|
|
|
lk_tab: 'users',
|
|
|
|
|
lk_LF: 'userId',
|
|
|
|
|
lk_FF: '_id',
|
|
|
|
|
lk_as: 'user',
|
|
|
|
|
af_objId_tab: 'myId',
|
2023-04-07 02:45:21 +02:00
|
|
|
lk_proj: this.getProject(),
|
2021-12-11 00:25:54 +01:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2022-01-23 23:25:34 +01:00
|
|
|
params = {...params, ...otherparams};
|
2021-12-11 00:25:54 +01:00
|
|
|
|
2022-06-16 20:34:42 +02:00
|
|
|
return tools.executeQueryTable(this, idapp, params, user);
|
2021-10-08 00:38:35 +02:00
|
|
|
};
|
|
|
|
|
|
2022-03-06 00:48:33 +01:00
|
|
|
MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
2022-01-26 01:31:22 +01:00
|
|
|
const MySkill = this;
|
|
|
|
|
|
2023-04-07 02:45:21 +02:00
|
|
|
let query = [
|
2022-01-26 01:31:22 +01:00
|
|
|
{
|
2022-02-12 02:20:07 +01:00
|
|
|
'$match': {
|
2023-04-17 00:11:36 +02:00
|
|
|
'_id': idSkill, idapp
|
2022-02-12 02:20:07 +01:00
|
|
|
},
|
2022-01-26 01:31:22 +01:00
|
|
|
},
|
|
|
|
|
{
|
2022-02-12 02:20:07 +01:00
|
|
|
'$sort': {
|
|
|
|
|
'desc': 1,
|
|
|
|
|
},
|
2022-01-26 01:31:22 +01:00
|
|
|
},
|
|
|
|
|
{
|
2022-02-12 02:20:07 +01:00
|
|
|
'$addFields': {
|
|
|
|
|
'myId1': {
|
|
|
|
|
'$toObjectId': '$userId',
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-01-26 01:31:22 +01:00
|
|
|
},
|
|
|
|
|
{
|
2022-02-12 02:20:07 +01:00
|
|
|
'$lookup': {
|
|
|
|
|
'from': 'users',
|
|
|
|
|
'localField': 'myId1',
|
|
|
|
|
'foreignField': '_id',
|
|
|
|
|
'as': 'user',
|
|
|
|
|
},
|
2022-01-26 01:31:22 +01:00
|
|
|
},
|
|
|
|
|
{
|
2022-02-12 02:20:07 +01:00
|
|
|
'$replaceRoot': {
|
|
|
|
|
'newRoot': {
|
|
|
|
|
'$mergeObjects': [
|
2022-01-26 01:31:22 +01:00
|
|
|
{
|
2022-02-12 02:20:07 +01:00
|
|
|
'$arrayElemAt': [
|
|
|
|
|
'$user',
|
|
|
|
|
0,
|
|
|
|
|
],
|
2022-01-26 01:31:22 +01:00
|
|
|
},
|
2022-02-12 02:20:07 +01:00
|
|
|
'$$ROOT',
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-01-26 01:31:22 +01:00
|
|
|
},
|
|
|
|
|
{
|
2023-04-07 02:45:21 +02:00
|
|
|
$project: this.getProject(),
|
2022-01-26 01:31:22 +01:00
|
|
|
},
|
|
|
|
|
{
|
2022-02-12 02:20:07 +01:00
|
|
|
'$lookup': {
|
|
|
|
|
'from': 'skills',
|
|
|
|
|
'localField': 'idSkill',
|
|
|
|
|
'foreignField': '_id',
|
|
|
|
|
'as': 'recSkill',
|
|
|
|
|
},
|
2022-01-26 01:31:22 +01:00
|
|
|
},
|
|
|
|
|
{
|
2022-02-12 02:20:07 +01:00
|
|
|
'$replaceRoot': {
|
|
|
|
|
'newRoot': {
|
|
|
|
|
'$mergeObjects': [
|
2022-01-26 01:31:22 +01:00
|
|
|
{
|
2022-02-12 02:20:07 +01:00
|
|
|
'$arrayElemAt': [
|
|
|
|
|
'$recSkill',
|
|
|
|
|
0,
|
|
|
|
|
],
|
2022-01-26 01:31:22 +01:00
|
|
|
},
|
2022-02-12 02:20:07 +01:00
|
|
|
'$$ROOT',
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-01-26 01:31:22 +01:00
|
|
|
},
|
|
|
|
|
{
|
2023-04-07 02:45:21 +02:00
|
|
|
$project: this.getProject(),
|
2022-01-26 01:31:22 +01:00
|
|
|
},
|
|
|
|
|
{
|
2022-02-12 02:20:07 +01:00
|
|
|
'$lookup': {
|
|
|
|
|
'from': 'sectors',
|
2022-08-15 15:10:27 +02:00
|
|
|
'localField': 'idSector',
|
2022-02-12 02:20:07 +01:00
|
|
|
'foreignField': '_id',
|
|
|
|
|
'as': 'sector',
|
|
|
|
|
},
|
2022-01-26 01:31:22 +01:00
|
|
|
},
|
|
|
|
|
{
|
2022-02-12 02:20:07 +01:00
|
|
|
'$replaceRoot': {
|
|
|
|
|
'newRoot': {
|
|
|
|
|
'$mergeObjects': [
|
2022-01-26 01:31:22 +01:00
|
|
|
{
|
2022-02-12 02:20:07 +01:00
|
|
|
'$arrayElemAt': [
|
|
|
|
|
'$sector',
|
|
|
|
|
0,
|
|
|
|
|
],
|
2022-01-26 01:31:22 +01:00
|
|
|
},
|
2022-02-12 02:20:07 +01:00
|
|
|
'$$ROOT',
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-01-26 01:31:22 +01:00
|
|
|
},
|
|
|
|
|
{
|
2023-04-07 02:45:21 +02:00
|
|
|
$project: this.getProject(),
|
2022-01-26 01:31:22 +01:00
|
|
|
},
|
2022-02-21 13:12:27 +01:00
|
|
|
/*{
|
2022-02-12 02:20:07 +01:00
|
|
|
'$lookup': {
|
|
|
|
|
'from': 'subskills',
|
|
|
|
|
'localField': 'idSubSkill',
|
|
|
|
|
'foreignField': '_id',
|
|
|
|
|
'as': 'myskill',
|
|
|
|
|
},
|
2022-01-26 01:31:22 +01:00
|
|
|
},
|
2022-02-21 13:12:27 +01:00
|
|
|
|
|
|
|
|
*/
|
2022-01-26 01:31:22 +01:00
|
|
|
{
|
2022-02-12 02:20:07 +01:00
|
|
|
'$replaceRoot': {
|
|
|
|
|
'newRoot': {
|
|
|
|
|
'$mergeObjects': [
|
2022-01-26 01:31:22 +01:00
|
|
|
{
|
2022-02-12 02:20:07 +01:00
|
|
|
'$arrayElemAt': [
|
|
|
|
|
'$myskill',
|
|
|
|
|
0,
|
|
|
|
|
],
|
2022-01-26 01:31:22 +01:00
|
|
|
},
|
2022-02-12 02:20:07 +01:00
|
|
|
'$$ROOT',
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-01-26 01:31:22 +01:00
|
|
|
},
|
|
|
|
|
{
|
2023-04-07 02:45:21 +02:00
|
|
|
$project: this.getProject(),
|
2022-01-26 01:31:22 +01:00
|
|
|
},
|
|
|
|
|
{
|
2022-02-12 02:20:07 +01:00
|
|
|
'$lookup': {
|
|
|
|
|
'from': 'cities',
|
|
|
|
|
'localField': 'idCity',
|
|
|
|
|
'foreignField': '_id',
|
|
|
|
|
'as': 'mycities',
|
|
|
|
|
},
|
2022-01-26 01:31:22 +01:00
|
|
|
},
|
|
|
|
|
{
|
2022-02-12 02:20:07 +01:00
|
|
|
'$replaceRoot': {
|
|
|
|
|
'newRoot': {
|
|
|
|
|
'$mergeObjects': [
|
2022-01-26 01:31:22 +01:00
|
|
|
{
|
2022-02-12 02:20:07 +01:00
|
|
|
'$arrayElemAt': [
|
|
|
|
|
'$mycities',
|
|
|
|
|
0,
|
|
|
|
|
],
|
2022-01-26 01:31:22 +01:00
|
|
|
},
|
2022-02-12 02:20:07 +01:00
|
|
|
'$$ROOT',
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-01-26 01:31:22 +01:00
|
|
|
},
|
2023-04-07 02:45:21 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
let numtab = tools.getNumTabByTable(shared_consts.TABLES_MYSKILLS);
|
|
|
|
|
|
|
|
|
|
const objadd = tools.addNumFavoriteAndBookmarkToQuery(idapp, numtab);
|
|
|
|
|
query = [...query, ...objadd.query];
|
|
|
|
|
|
2023-04-17 00:11:36 +02:00
|
|
|
const toadd = {
|
|
|
|
|
$project: this.getProject(objadd.proj),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
query = [...query, {...toadd}];
|
2022-01-26 01:31:22 +01:00
|
|
|
|
|
|
|
|
return MySkill.aggregate(query).then((rec) => {
|
|
|
|
|
return rec ? rec[0] : null;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-07 02:45:21 +02:00
|
|
|
MySkillSchema.statics.getProject = function (proj_add2) {
|
|
|
|
|
let proj = {
|
|
|
|
|
recSkill: 1,
|
|
|
|
|
sector: 1,
|
|
|
|
|
idSector: 1,
|
|
|
|
|
idSkill: 1,
|
|
|
|
|
idStatusSkill: 1,
|
|
|
|
|
website: 1,
|
|
|
|
|
'numLevel': 1,
|
|
|
|
|
//**ADDFIELD_MYSKILL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const proj_add = shared_consts.getProjectForAll(proj_add2)
|
|
|
|
|
|
|
|
|
|
return Object.assign({}, proj, proj_add);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-16 09:40:16 +01:00
|
|
|
MySkillSchema.statics.getCompleteRecord = function(idapp, id) {
|
|
|
|
|
const MySkill = this;
|
|
|
|
|
|
2022-03-06 00:48:33 +01:00
|
|
|
return MySkill.getMyRecById(idapp, id);
|
2022-02-16 09:40:16 +01:00
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2021-10-08 00:38:35 +02:00
|
|
|
const MySkill = mongoose.model('MySkill', MySkillSchema);
|
|
|
|
|
|
|
|
|
|
module.exports = {MySkill};
|