new version Visualizzazione Service
This commit is contained in:
@@ -15,7 +15,10 @@ mongoose.plugin(schema => {
|
||||
|
||||
const MyBachecaSchema = new Schema({
|
||||
_id: {
|
||||
type: Number,
|
||||
type: String,
|
||||
default: function () {
|
||||
return new ObjectID().toString();
|
||||
},
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
@@ -88,17 +91,6 @@ const MyBachecaSchema = new Schema({
|
||||
|
||||
MyBachecaSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
const myrec = await MyBacheca.findOne().limit(1).sort({ _id: -1 });
|
||||
if (!!myrec) {
|
||||
if (myrec._doc._id === 0)
|
||||
this._id = 1;
|
||||
else
|
||||
this._id = myrec._doc._id + 1;
|
||||
|
||||
} else {
|
||||
this._id = 1;
|
||||
}
|
||||
|
||||
this.date_created = new Date();
|
||||
}
|
||||
|
||||
@@ -171,6 +163,8 @@ MyBachecaSchema.statics.executeQueryTable = function (idapp, params, user) {
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
'profile.username_telegram': 1,
|
||||
reported: 1,
|
||||
date_report: 1,
|
||||
username_who_report: 1,
|
||||
@@ -186,13 +180,21 @@ MyBachecaSchema.statics.executeQueryTable = function (idapp, params, user) {
|
||||
MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
const MyBacheca = this;
|
||||
|
||||
let myparsid = {
|
||||
$or: [
|
||||
{
|
||||
'_id': parseInt(idGood)
|
||||
},
|
||||
{
|
||||
'_id': idGood,
|
||||
}]
|
||||
};
|
||||
|
||||
const query = [
|
||||
{
|
||||
'$match': {
|
||||
'$and': [
|
||||
{
|
||||
'_id': parseInt(id),
|
||||
},
|
||||
myparsid,
|
||||
],
|
||||
},
|
||||
},
|
||||
@@ -268,6 +270,7 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
@@ -326,6 +329,7 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
@@ -384,6 +388,7 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
@@ -442,6 +447,7 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
@@ -500,6 +506,7 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -15,7 +15,7 @@ mongoose.plugin(schema => {
|
||||
|
||||
const MyGoodSchema = new Schema({
|
||||
_id: {
|
||||
type: Number,
|
||||
type: String,
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
@@ -151,6 +151,7 @@ MyGoodSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
MyGood: 1,
|
||||
idStatusGood: 1,
|
||||
idContribType: 1,
|
||||
'profile.username_telegram': 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
numLevel: 1,
|
||||
@@ -172,6 +173,7 @@ MyGoodSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
@@ -185,13 +187,21 @@ MyGoodSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
MyGoodSchema.statics.getMyRecById = function (idapp, idGood) {
|
||||
const MyGood = this;
|
||||
|
||||
let myparsid = {
|
||||
$or: [
|
||||
{
|
||||
'_id': parseInt(idGood)
|
||||
},
|
||||
{
|
||||
'_id': idGood,
|
||||
}]
|
||||
};
|
||||
|
||||
const query = [
|
||||
{
|
||||
'$match': {
|
||||
'$and': [
|
||||
{
|
||||
'_id': parseInt(idGood),
|
||||
},
|
||||
myparsid,
|
||||
],
|
||||
},
|
||||
},
|
||||
@@ -266,6 +276,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
@@ -323,6 +334,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
@@ -381,6 +393,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
@@ -438,6 +451,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
@@ -495,6 +509,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -15,7 +15,7 @@ mongoose.plugin(schema => {
|
||||
|
||||
const MyGroupSchema = new Schema({
|
||||
_id: {
|
||||
type: Number,
|
||||
type: String,
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
|
||||
@@ -15,7 +15,7 @@ mongoose.plugin(schema => {
|
||||
|
||||
const MyHospSchema = new Schema({
|
||||
_id: {
|
||||
type: Number,
|
||||
type: String,
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
@@ -172,6 +172,7 @@ MyHospSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
'mycities': 1,
|
||||
reported: 1,
|
||||
},
|
||||
@@ -186,13 +187,27 @@ MyHospSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
const MyHosp = this;
|
||||
|
||||
let myparsid = {
|
||||
$or: [
|
||||
{
|
||||
'_id': parseInt(idGood)
|
||||
},
|
||||
{
|
||||
'_id': idGood,
|
||||
}]
|
||||
};
|
||||
|
||||
if (tools.isNumber(id)) {
|
||||
myparsid = {'_id': parseInt(id)};
|
||||
} else {
|
||||
myparsid = {'_id': id};
|
||||
}
|
||||
|
||||
const query = [
|
||||
{
|
||||
'$match': {
|
||||
'$and': [
|
||||
{
|
||||
'_id': parseInt(id),
|
||||
},
|
||||
myparsid,
|
||||
],
|
||||
},
|
||||
},
|
||||
@@ -263,6 +278,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
@@ -316,6 +332,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
@@ -369,6 +386,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
@@ -422,6 +440,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
@@ -457,6 +476,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
preferences: 1,
|
||||
photos: 1,
|
||||
idContribType: 1,
|
||||
'profile.username_telegram': 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
note: 1,
|
||||
@@ -475,6 +495,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -15,7 +15,10 @@ mongoose.plugin(schema => {
|
||||
|
||||
const MySkillSchema = new Schema({
|
||||
_id: {
|
||||
type: Number,
|
||||
type: String,
|
||||
default: function () {
|
||||
return new ObjectID().toString();
|
||||
},
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
@@ -92,17 +95,6 @@ const MySkillSchema = new Schema({
|
||||
|
||||
MySkillSchema.pre('save', async function(next) {
|
||||
if (this.isNew) {
|
||||
const myrec = await MySkill.findOne().limit(1).sort({_id: -1});
|
||||
if (!!myrec) {
|
||||
if (myrec._doc._id === 0)
|
||||
this._id = 1;
|
||||
else
|
||||
this._id = myrec._doc._id + 1;
|
||||
|
||||
} else {
|
||||
this._id = 1;
|
||||
}
|
||||
|
||||
this.date_created = new Date();
|
||||
}
|
||||
|
||||
@@ -153,6 +145,7 @@ MySkillSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
myskill: 1,
|
||||
idStatusSkill: 1,
|
||||
idContribType: 1,
|
||||
'profile.username_telegram': 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
numLevel: 1,
|
||||
@@ -173,6 +166,7 @@ MySkillSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
@@ -186,13 +180,19 @@ MySkillSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
const MySkill = this;
|
||||
|
||||
let myparskill = {};
|
||||
|
||||
if (tools.isNumber(idSkill)) {
|
||||
myparskill = {'_id': parseInt(idSkill)};
|
||||
} else {
|
||||
myparskill = {'_id': idSkill};
|
||||
}
|
||||
|
||||
const query = [
|
||||
{
|
||||
'$match': {
|
||||
'$and': [
|
||||
{
|
||||
'_id': parseInt(idSkill),
|
||||
},
|
||||
myparskill,
|
||||
],
|
||||
},
|
||||
},
|
||||
@@ -266,6 +266,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
@@ -322,6 +323,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
@@ -378,6 +380,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
@@ -436,6 +439,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
@@ -492,6 +496,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -449,7 +449,21 @@ const UserSchema = new mongoose.Schema({
|
||||
},
|
||||
noFoto: {
|
||||
type: Boolean,
|
||||
}
|
||||
},
|
||||
bookmark: [
|
||||
{
|
||||
_id: false,
|
||||
id: { type: String },
|
||||
tab: { type: Number },
|
||||
},
|
||||
],
|
||||
favorite: [
|
||||
{
|
||||
_id: false,
|
||||
id: { type: String },
|
||||
tab: { type: Number },
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1882,6 +1896,33 @@ UserSchema.statics.removeReqFriend = async function (
|
||||
{ $pull: { 'profile.req_friends': { username: { $in: [usernameDest] } } } });
|
||||
};
|
||||
|
||||
// Rimuovo il Favorite
|
||||
UserSchema.statics.removeFavorite = async function (
|
||||
idapp, id, tab) {
|
||||
return await User.updateOne({ idapp, username },
|
||||
{ $pull: { 'profile.favorite': { id: { $in: [id] }, tab } } });
|
||||
};
|
||||
|
||||
// Aggiungo il Favorite
|
||||
UserSchema.statics.addFavorite = async function (
|
||||
idapp, username, id, tab) {
|
||||
return await User.updateOne({ idapp, username },
|
||||
{ $push: { 'profile.favorite': { id, tab } } });
|
||||
};
|
||||
// Rimuovo il Bookmark
|
||||
UserSchema.statics.removeBookmark = async function (
|
||||
idapp, id, tab) {
|
||||
return await User.updateOne({ idapp, username },
|
||||
{ $pull: { 'profile.bookmark': { id: { $in: [id] }, tab } } });
|
||||
};
|
||||
|
||||
// Aggiungo il Bookmark
|
||||
UserSchema.statics.addBookmark = async function (
|
||||
idapp, username, id, tab) {
|
||||
return await User.updateOne({ idapp, username },
|
||||
{ $push: { 'profile.bookmark': { id, tab } } });
|
||||
};
|
||||
|
||||
UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, usernameDest, cmd, value, disablenotif) {
|
||||
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
|
||||
@@ -1436,4 +1436,43 @@ router.post('/mgt', authenticate, async (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.post('/cmd', authenticate, async (req, res) => {
|
||||
|
||||
const mydata = req.body.mydata;
|
||||
const idapp = req.body.idapp;
|
||||
const cmd = req.body.cmd;
|
||||
const id = req.body.id;
|
||||
const tab = req.body.tab;
|
||||
const value = req.body.value;
|
||||
|
||||
try {
|
||||
const username = req.user.username;
|
||||
|
||||
let ris = null;
|
||||
|
||||
if (cmd === shared_consts.CMD_USER.SET_FAVORITE) {
|
||||
if (value)
|
||||
ris = await User.addFavorite(idapp, username, id, tab);
|
||||
else
|
||||
ris = await User.removeFavorite(idapp, username, id, tab);
|
||||
} else if (cmd === shared_consts.CMD_USER.SET_BOOKMARK) {
|
||||
if (value)
|
||||
ris = await User.addBookmark(idapp, username, id, tab);
|
||||
else
|
||||
ris = await User.removeBookmark(idapp, username, id, tab);
|
||||
}
|
||||
|
||||
let state = (value && ris && ris.ok === 1) ? 1 : ((!value && ris && ris.ok === 1) ? -1 : 0);
|
||||
|
||||
return res.send({ state });
|
||||
|
||||
} catch (e) {
|
||||
res.status(400).send();
|
||||
res.send({ code: server_constants.RIS_CODE_ERR, msg: e });
|
||||
|
||||
console.log(e.message);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -134,6 +134,13 @@ module.exports = {
|
||||
TABLES_MYGOODS: 'mygoods',
|
||||
TABLES_MYEVENTS: 'myevents',
|
||||
|
||||
MYTABS: ['none', 'myskills', 'mybachecas', 'myhosps', 'mygoods', 'myevents'],
|
||||
|
||||
CMD_USER: {
|
||||
SET_FAVORITE: 1,
|
||||
SET_BOOKMARK: 2,
|
||||
},
|
||||
|
||||
TABLES_ENABLE_GETREC_BYID: ['mybachecas', 'myhosps', 'myskills', 'mygoods'],
|
||||
|
||||
TABLES_USER_INCLUDE_MY: ['mygroups', 'circuits'],
|
||||
@@ -173,11 +180,11 @@ module.exports = {
|
||||
'subskills',
|
||||
'cities',
|
||||
'provinces',
|
||||
'myskills',
|
||||
'mybachecas',
|
||||
'myhosps',
|
||||
'mygoods',
|
||||
'mygroups'
|
||||
// 'myskills',
|
||||
// 'mybachecas',
|
||||
// 'myhosps',
|
||||
// 'mygoods',
|
||||
// 'mygroups'
|
||||
],
|
||||
TABLES_USER_ID: ['mygroups', 'myskills', 'mybachecas', 'myhosps', 'mygoods'],
|
||||
TABLES_CREATEDBY: ['mygroups', 'circuits'],
|
||||
|
||||
Reference in New Issue
Block a user