- Pagina MySkills personale

This commit is contained in:
paoloar77
2022-01-26 01:31:22 +01:00
parent 6b8e4af737
commit 842a041fe5
9 changed files with 473 additions and 21 deletions

View File

@@ -118,8 +118,7 @@ CitySchema.statics.executeQueryPickup = async function(idapp, params) {
let filterfind = {comune: {$regex: '^' + strfind, $options: 'i'}}; let filterfind = {comune: {$regex: '^' + strfind, $options: 'i'}};
const ris = await City.find(filterfind, {comune: 1, prov: 1, reg: 1}).lean().limit(10); let ris = await City.find(filterfind, {comune: 1, prov: 1, reg: 1}).lean().limit(10);
return [...risexact, ...ris]; return [...risexact, ...ris];

View File

@@ -35,9 +35,6 @@ const MySkillSchema = new Schema({
{ {
type: Number, type: Number,
}], }],
idSector: {
type: Number,
},
idContribType: [ idContribType: [
{ {
type: String, type: String,
@@ -98,6 +95,7 @@ MySkillSchema.pre('save', async function(next) {
}); });
MySkillSchema.statics.findAllIdApp = async function(idapp) { MySkillSchema.statics.findAllIdApp = async function(idapp) {
const MySkill = this;
const query = [ const query = [
{$match: {idapp}}, {$match: {idapp}},
@@ -154,6 +152,284 @@ MySkillSchema.statics.executeQueryTable = function(idapp, params) {
return tools.executeQueryTable(this, 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); const MySkill = mongoose.model('MySkill', MySkillSchema);
module.exports = {MySkill}; module.exports = {MySkill};

View File

@@ -225,6 +225,12 @@ const UserSchema = new mongoose.Schema({
username_telegram: { username_telegram: {
type: String, type: String,
}, },
firstname_telegram: {
type: String,
},
lastname_telegram: {
type: String,
},
website: { website: {
type: String, type: String,
}, },
@@ -1660,6 +1666,24 @@ UserSchema.statics.SetTelegramIdSuccess = async function(idapp, id, teleg_id) {
}; };
UserSchema.statics.setUsernameTelegram = async function(idapp, id, username_telegram, firstname_telegram, lastname_telegram) {
const User = this;
const fields_to_update = {
'profile.username_telegram': username_telegram,
'profile.firstname_telegram': firstname_telegram,
'profile.lastname_telegram': lastname_telegram,
};
return User.findOneAndUpdate({
idapp,
_id: id,
}, {$set: fields_to_update}, {new: false}).then((record) => {
return record;
});
};
UserSchema.statics.getLangByIndOrder = async function(idapp, ind_order) { UserSchema.statics.getLangByIndOrder = async function(idapp, ind_order) {
const User = this; const User = this;

View File

@@ -0,0 +1,96 @@
const {ObjectID} = require('mongodb');
module.exports = {
list: [
{
"_id" : ObjectID("615a353c002c8298f4495be7"),
"idapp" : "1",
"__v" : 0,
"label" : "Dono"
},
{
"_id" : ObjectID("61bc466567de9a1f54b25494"),
"idapp" : "1",
"__v" : 0,
"label" : "Offerta Libera"
},
{
"_id" : ObjectID("61bc454867de9a1f54b25462"),
"idapp" : "1",
"__v" : 0,
"label" : "Baratto"
},
{
"_id" : ObjectID("61bc482667de9a1f54b2549b"),
"idapp" : "1",
"__v" : 0,
"label" : "Euro"
},
{
"_id" : ObjectID("61bc482667de9a1f54b2549b"),
"idapp" : "1",
"__v" : 0,
"label" : "Scambio di Beni"
},
{
"_id" : ObjectID("61bc482667de9a1f54b2549c"),
"idapp" : "1",
"__v" : 0,
"label" : "Scambio di Lavoro"
},
{
"_id" : ObjectID("61cae7da4c7b5931a5f367c9"),
"idapp" : "1",
"__v" : 0,
"label" : "Sardex"
},
{
"_id" : ObjectID("615a353c002c8298f4495bf7"),
"idapp" : "12",
"__v" : 0,
"label" : "Dono"
},
{
"_id" : ObjectID("61bc466567de9a1f54b254f4"),
"idapp" : "12",
"__v" : 0,
"label" : "Offerta Libera"
},
{
"_id" : ObjectID("61bc454867de9a1f54b254f2"),
"idapp" : "12",
"__v" : 0,
"label" : "Baratto"
},
{
"_id" : ObjectID("61bc482667de9a1f54b254fb"),
"idapp" : "12",
"__v" : 0,
"label" : "Euro"
},
{
"_id" : ObjectID("61bc482667de9a1f54b25411"),
"idapp" : "12",
"__v" : 0,
"label" : "Scambio di Beni"
},
{
"_id" : ObjectID("61bc482667de9a1f54b25412"),
"idapp" : "12",
"__v" : 0,
"label" : "Scambio di Lavoro"
},
{
"_id" : ObjectID("61cae7da4c7b5931a5f36712"),
"idapp" : "12",
"__v" : 0,
"label" : "Sardex"
},
]
}

View File

@@ -25,28 +25,34 @@ module.exports = {
}, },
popolaTabelleNuove() { popolaTabelleNuove() {
const abilita = false;
let ris = null; let ris = null;
// Sectors if (abilita) {
const { Sector } = require('../models/sector'); // Sectors
this.insertIntoDb('sectors', Sector) const { Sector } = require('../models/sector');
this.insertIntoDb('sectors', Sector)
// Skills (Competenze) // Skills (Competenze)
const { Skill } = require('../models/skill'); const { Skill } = require('../models/skill');
this.insertIntoDb('skills', Skill) this.insertIntoDb('skills', Skill)
// SubSectors // SubSectors
const { SubSkill } = require('../models/subskill'); const { SubSkill } = require('../models/subskill');
this.insertIntoDb('subskills', SubSkill) this.insertIntoDb('subskills', SubSkill)
// Cities // Cities
const { City } = require('../models/city'); const {City} = require('../models/city');
ris = this.insertIntoDb('cities', City) this.insertIntoDb('cities', City)
// Province // Province
const { Province } = require('../models/province'); const { Province } = require('../models/province');
ris = this.insertIntoDb('provinces', Province) this.insertIntoDb('provinces', Province)
// Contribtypes
const { Contribtype } = require('../models/contribtype');
this.insertIntoDb('contribtypes', Contribtype)
}
}, },

View File

@@ -1662,7 +1662,7 @@ function uploadFile(req, res, version) {
}) })
})(); })();
// res.end(); res.end();
// return res.send({filename: newname }); // return res.send({filename: newname });
}); });

View File

@@ -0,0 +1,45 @@
const shared_consts = require('../tools/shared_nodejs');
const express = require('express');
const router = express.Router();
const tools = require('../tools/general');
var server_constants = require('../tools/server_constants');
var {authenticate, auth_default} = require('../middleware/authenticate');
var mongoose = require('mongoose').set('debug', false);
const Subscription = mongoose.model('subscribers');
const _ = require('lodash');
const { MySkill } = require('../models/myskill');
var { User } = require('../models/user');
const {ObjectID} = require('mongodb');
//GET orders
router.post('/page', authenticate, function(req, res, next) {
let idSkill = req.body.idSkill;
let idapp = req.body.idapp;
return MySkill.getMySkillByIdkill(idapp, idSkill).then((ris) => {
if (ris) {
res.send(ris);
/*
const userId = ris.userId;
return User.getUsernameById(idapp, userId).then((username) =>
{
res.send({...ris, username});
});
*/
} else {
res.status(400).send(e);
}
});
});
module.exports = router;

View File

@@ -102,6 +102,7 @@ myLoad().then(ris => {
const products_router = require('./router/products_router'); const products_router = require('./router/products_router');
const cart_router = require('./router/cart_router'); const cart_router = require('./router/cart_router');
const orders_router = require('./router/orders_router'); const orders_router = require('./router/orders_router');
const myskills_router = require('./router/myskills_router');
const { MyEvent } = require('./models/myevent'); const { MyEvent } = require('./models/myevent');
@@ -154,6 +155,7 @@ myLoad().then(ris => {
app.use('/products', products_router); app.use('/products', products_router);
app.use('/cart', cart_router); app.use('/cart', cart_router);
app.use('/orders', orders_router); app.use('/orders', orders_router);
app.use('/myskills', myskills_router);
// catch 404 and forward to error handler // catch 404 and forward to error handler
// app.use(function (req, res, next) { // app.use(function (req, res, next) {

View File

@@ -2343,7 +2343,11 @@ class Telegram {
if (code.length < 7) { if (code.length < 7) {
if (rec) { if (rec) {
if (code === telegcode) { if (code === telegcode) {
try {
await User.setUsernameTelegram(this.idapp, user._id, msg.from.username || '', msg.from.first_name || '', msg.from.last_name || '');
} catch (e) {}
// let ris = await this.getUser(msg, rec, false); // let ris = await this.getUser(msg, rec, false);
rec.status = Status.VERIFIED; rec.status = Status.VERIFIED;
await User.SetTelegramIdSuccess(this.idapp, user._id, await User.SetTelegramIdSuccess(this.idapp, user._id,
msg.from.id).then((recuser) => { msg.from.id).then((recuser) => {