- Pagina MySkills personale
This commit is contained in:
@@ -118,8 +118,7 @@ CitySchema.statics.executeQueryPickup = async function(idapp, params) {
|
||||
|
||||
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];
|
||||
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -225,6 +225,12 @@ const UserSchema = new mongoose.Schema({
|
||||
username_telegram: {
|
||||
type: String,
|
||||
},
|
||||
firstname_telegram: {
|
||||
type: String,
|
||||
},
|
||||
lastname_telegram: {
|
||||
type: String,
|
||||
},
|
||||
website: {
|
||||
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) {
|
||||
const User = this;
|
||||
|
||||
|
||||
96
src/server/populate/contribtypes.js
Normal file
96
src/server/populate/contribtypes.js
Normal 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"
|
||||
},
|
||||
]
|
||||
}
|
||||
@@ -25,8 +25,10 @@ module.exports = {
|
||||
},
|
||||
|
||||
popolaTabelleNuove() {
|
||||
const abilita = false;
|
||||
|
||||
let ris = null;
|
||||
if (abilita) {
|
||||
// Sectors
|
||||
const { Sector } = require('../models/sector');
|
||||
this.insertIntoDb('sectors', Sector)
|
||||
@@ -40,13 +42,17 @@ module.exports = {
|
||||
this.insertIntoDb('subskills', SubSkill)
|
||||
|
||||
// Cities
|
||||
const { City } = require('../models/city');
|
||||
ris = this.insertIntoDb('cities', City)
|
||||
const {City} = require('../models/city');
|
||||
this.insertIntoDb('cities', City)
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
@@ -1662,7 +1662,7 @@ function uploadFile(req, res, version) {
|
||||
})
|
||||
|
||||
})();
|
||||
// res.end();
|
||||
res.end();
|
||||
// return res.send({filename: newname });
|
||||
|
||||
});
|
||||
|
||||
45
src/server/router/myskills_router.js
Executable file
45
src/server/router/myskills_router.js
Executable 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;
|
||||
@@ -102,6 +102,7 @@ myLoad().then(ris => {
|
||||
const products_router = require('./router/products_router');
|
||||
const cart_router = require('./router/cart_router');
|
||||
const orders_router = require('./router/orders_router');
|
||||
const myskills_router = require('./router/myskills_router');
|
||||
|
||||
const { MyEvent } = require('./models/myevent');
|
||||
|
||||
@@ -154,6 +155,7 @@ myLoad().then(ris => {
|
||||
app.use('/products', products_router);
|
||||
app.use('/cart', cart_router);
|
||||
app.use('/orders', orders_router);
|
||||
app.use('/myskills', myskills_router);
|
||||
|
||||
// catch 404 and forward to error handler
|
||||
// app.use(function (req, res, next) {
|
||||
|
||||
@@ -2343,7 +2343,11 @@ class Telegram {
|
||||
if (code.length < 7) {
|
||||
if (rec) {
|
||||
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);
|
||||
|
||||
rec.status = Status.VERIFIED;
|
||||
await User.SetTelegramIdSuccess(this.idapp, user._id,
|
||||
msg.from.id).then((recuser) => {
|
||||
|
||||
Reference in New Issue
Block a user