- Pagina MySkills personale
This commit is contained in:
@@ -35,9 +35,6 @@ const MySkillSchema = new Schema({
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
idSector: {
|
||||
type: Number,
|
||||
},
|
||||
idContribType: [
|
||||
{
|
||||
type: String,
|
||||
@@ -98,6 +95,7 @@ MySkillSchema.pre('save', async function(next) {
|
||||
});
|
||||
|
||||
MySkillSchema.statics.findAllIdApp = async function(idapp) {
|
||||
const MySkill = this;
|
||||
|
||||
const query = [
|
||||
{$match: {idapp}},
|
||||
@@ -154,6 +152,284 @@ MySkillSchema.statics.executeQueryTable = function(idapp, params) {
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
MySkillSchema.statics.getMySkillByIdkill = function (idapp, idSkill) {
|
||||
const MySkill = this;
|
||||
|
||||
const query = [
|
||||
{
|
||||
"$match": {
|
||||
"$and": [
|
||||
{
|
||||
"_id": parseInt(idSkill)
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"$match": {
|
||||
"idapp": idapp
|
||||
}
|
||||
},
|
||||
{
|
||||
"$sort": {
|
||||
"desc": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"$addFields": {
|
||||
"myId1": {
|
||||
"$toObjectId": "$userId"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"$lookup": {
|
||||
"from": "users",
|
||||
"localField": "myId1",
|
||||
"foreignField": "_id",
|
||||
"as": "user"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$replaceRoot": {
|
||||
"newRoot": {
|
||||
"$mergeObjects": [
|
||||
{
|
||||
"$arrayElemAt": [
|
||||
"$user",
|
||||
0
|
||||
]
|
||||
},
|
||||
"$$ROOT"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": {
|
||||
"recSkill": 1,
|
||||
"sector": 1,
|
||||
"idSkill": 1,
|
||||
"idSubSkill": 1,
|
||||
"idStatusSkill": 1,
|
||||
"idContribType": 1,
|
||||
"idCity": 1,
|
||||
"numLevel": 1,
|
||||
"photos": 1,
|
||||
"note": 1,
|
||||
"subTitle": 1,
|
||||
"date_created": 1,
|
||||
"date_updated": 1,
|
||||
"userId": 1,
|
||||
"username": 1,
|
||||
"name": 1,
|
||||
"surname": 1,
|
||||
"comune": 1,
|
||||
"mycities": 1,
|
||||
"profile.img": 1,
|
||||
"profile.qualifica": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"$lookup": {
|
||||
"from": "skills",
|
||||
"localField": "idSkill",
|
||||
"foreignField": "_id",
|
||||
"as": "recSkill"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$replaceRoot": {
|
||||
"newRoot": {
|
||||
"$mergeObjects": [
|
||||
{
|
||||
"$arrayElemAt": [
|
||||
"$recSkill",
|
||||
0
|
||||
]
|
||||
},
|
||||
"$$ROOT"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": {
|
||||
"recSkill": 1,
|
||||
"sector": 1,
|
||||
"idSkill": 1,
|
||||
"idSubSkill": 1,
|
||||
"idStatusSkill": 1,
|
||||
"idContribType": 1,
|
||||
"idCity": 1,
|
||||
"numLevel": 1,
|
||||
"photos": 1,
|
||||
"note": 1,
|
||||
"subTitle": 1,
|
||||
"date_created": 1,
|
||||
"date_updated": 1,
|
||||
"userId": 1,
|
||||
"username": 1,
|
||||
"name": 1,
|
||||
"surname": 1,
|
||||
"comune": 1,
|
||||
"mycities": 1,
|
||||
"profile.img": 1,
|
||||
"profile.qualifica": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"$lookup": {
|
||||
"from": "sectors",
|
||||
"localField": "recSkill.idSector",
|
||||
"foreignField": "_id",
|
||||
"as": "sector"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$replaceRoot": {
|
||||
"newRoot": {
|
||||
"$mergeObjects": [
|
||||
{
|
||||
"$arrayElemAt": [
|
||||
"$sector",
|
||||
0
|
||||
]
|
||||
},
|
||||
"$$ROOT"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": {
|
||||
"recSkill": 1,
|
||||
"sector": 1,
|
||||
"idSkill": 1,
|
||||
"idSubSkill": 1,
|
||||
"idStatusSkill": 1,
|
||||
"idContribType": 1,
|
||||
"idCity": 1,
|
||||
"numLevel": 1,
|
||||
"photos": 1,
|
||||
"note": 1,
|
||||
"subTitle": 1,
|
||||
"date_created": 1,
|
||||
"date_updated": 1,
|
||||
"userId": 1,
|
||||
"username": 1,
|
||||
"name": 1,
|
||||
"surname": 1,
|
||||
"comune": 1,
|
||||
"mycities": 1,
|
||||
"profile.img": 1,
|
||||
"profile.qualifica": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"$lookup": {
|
||||
"from": "subskills",
|
||||
"localField": "idSubSkill",
|
||||
"foreignField": "_id",
|
||||
"as": "myskill"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$replaceRoot": {
|
||||
"newRoot": {
|
||||
"$mergeObjects": [
|
||||
{
|
||||
"$arrayElemAt": [
|
||||
"$myskill",
|
||||
0
|
||||
]
|
||||
},
|
||||
"$$ROOT"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": {
|
||||
"recSkill": 1,
|
||||
"sector": 1,
|
||||
"idSkill": 1,
|
||||
"idSubSkill": 1,
|
||||
"idStatusSkill": 1,
|
||||
"idContribType": 1,
|
||||
"idCity": 1,
|
||||
"numLevel": 1,
|
||||
"photos": 1,
|
||||
"note": 1,
|
||||
"subTitle": 1,
|
||||
"date_created": 1,
|
||||
"date_updated": 1,
|
||||
"userId": 1,
|
||||
"username": 1,
|
||||
"name": 1,
|
||||
"surname": 1,
|
||||
"comune": 1,
|
||||
"mycities": 1,
|
||||
"profile.img": 1,
|
||||
"profile.qualifica": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"$lookup": {
|
||||
"from": "cities",
|
||||
"localField": "idCity",
|
||||
"foreignField": "_id",
|
||||
"as": "mycities"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$replaceRoot": {
|
||||
"newRoot": {
|
||||
"$mergeObjects": [
|
||||
{
|
||||
"$arrayElemAt": [
|
||||
"$mycities",
|
||||
0
|
||||
]
|
||||
},
|
||||
"$$ROOT"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": {
|
||||
"recSkill": 1,
|
||||
"sector": 1,
|
||||
"idSkill": 1,
|
||||
"idSubSkill": 1,
|
||||
"idStatusSkill": 1,
|
||||
"idContribType": 1,
|
||||
"idCity": 1,
|
||||
"numLevel": 1,
|
||||
"photos": 1,
|
||||
"note": 1,
|
||||
"subTitle": 1,
|
||||
"date_created": 1,
|
||||
"date_updated": 1,
|
||||
"userId": 1,
|
||||
"username": 1,
|
||||
"name": 1,
|
||||
"surname": 1,
|
||||
"comune": 1,
|
||||
"mycities": 1,
|
||||
"profile.img": 1,
|
||||
"profile.qualifica": 1
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
return MySkill.aggregate(query).then((rec) => {
|
||||
return rec ? rec[0] : null;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
const MySkill = mongoose.model('MySkill', MySkillSchema);
|
||||
|
||||
module.exports = {MySkill};
|
||||
|
||||
Reference in New Issue
Block a user