- fix: resizing image uploaded
- add: mybachecas
This commit is contained in:
469
src/server/models/mybacheca.js
Executable file
469
src/server/models/mybacheca.js
Executable file
@@ -0,0 +1,469 @@
|
||||
const mongoose = require('mongoose').set('debug', false);
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = 'F';
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true;
|
||||
});
|
||||
|
||||
const MyBachecaSchema = new Schema({
|
||||
_id: {
|
||||
type: Number,
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
userId: {type: Schema.Types.ObjectId, ref: 'User'},
|
||||
idSector: {
|
||||
type: Number,
|
||||
},
|
||||
idSkill: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
idSubSkill: [
|
||||
{
|
||||
type: Number,
|
||||
default: 0,
|
||||
}],
|
||||
idStatusSkill: [
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
idContribType: [
|
||||
{
|
||||
type: String,
|
||||
}],
|
||||
idCity: [
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
numLevel: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
adType: {
|
||||
type: Number,
|
||||
},
|
||||
photos: [
|
||||
{
|
||||
imagefile: {
|
||||
type: String,
|
||||
},
|
||||
alt: {
|
||||
type: String,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
},
|
||||
}],
|
||||
note: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
descr: {
|
||||
type: String,
|
||||
},
|
||||
date_created: {
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
},
|
||||
date_updated: {
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
},
|
||||
});
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
MyBachecaSchema.statics.findAllIdApp = async function(idapp) {
|
||||
const MyBacheca = this;
|
||||
|
||||
const query = [
|
||||
{$match: {idapp}},
|
||||
{$sort: {descr: 1}},
|
||||
];
|
||||
|
||||
return MyBacheca.aggregate(query).then((arrrec) => {
|
||||
return arrrec;
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
MyBachecaSchema.statics.getFieldsForSearch = function() {
|
||||
return [];
|
||||
};
|
||||
|
||||
MyBachecaSchema.statics.getFieldsLastForSearch = function() {
|
||||
return [
|
||||
{field: 'note', type: tools.FieldType.string},
|
||||
{field: 'descr', type: tools.FieldType.string},
|
||||
{field: 'recSkill.descr', type: tools.FieldType.string},
|
||||
{field: 'MyBacheca.descr', type: tools.FieldType.string},
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
MyBachecaSchema.statics.executeQueryTable = function(idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
params.fieldsearch_last = this.getFieldsLastForSearch();
|
||||
|
||||
const otherparams = {
|
||||
lookup1: {
|
||||
lk_tab: 'users',
|
||||
lk_LF: 'userId',
|
||||
lk_FF: '_id',
|
||||
lk_as: 'user',
|
||||
af_objId_tab: 'myId',
|
||||
lk_proj: {
|
||||
idSkill: 1,
|
||||
idSubSkill: 1,
|
||||
MyBacheca: 1,
|
||||
idStatusSkill: 1,
|
||||
idContribType: 1,
|
||||
idCity: 1,
|
||||
numLevel: 1,
|
||||
adType: 1,
|
||||
photos: 1,
|
||||
note: 1,
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
userId: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
'profile.img': 1,
|
||||
'profile.qualifica': 1,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
params = {...params, ...otherparams};
|
||||
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
MyBachecaSchema.statics.getMyRecById = function(idapp, id) {
|
||||
const MyBacheca = this;
|
||||
|
||||
const query = [
|
||||
{
|
||||
'$match': {
|
||||
'$and': [
|
||||
{
|
||||
'_id': parseInt(id),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
'$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,
|
||||
'idSector': 1,
|
||||
'idSkill': 1,
|
||||
'idSubSkill': 1,
|
||||
'idStatusSkill': 1,
|
||||
'idContribType': 1,
|
||||
'idCity': 1,
|
||||
'numLevel': 1,
|
||||
adType: 1,
|
||||
'photos': 1,
|
||||
'note': 1,
|
||||
'descr': 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,
|
||||
'idSector': 1,
|
||||
'idSkill': 1,
|
||||
'idSubSkill': 1,
|
||||
'idStatusSkill': 1,
|
||||
'idContribType': 1,
|
||||
'idCity': 1,
|
||||
'numLevel': 1,
|
||||
adType: 1,
|
||||
'photos': 1,
|
||||
'note': 1,
|
||||
'descr': 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,
|
||||
'idSector': 1,
|
||||
'idSkill': 1,
|
||||
'idSubSkill': 1,
|
||||
'idStatusSkill': 1,
|
||||
'idContribType': 1,
|
||||
'idCity': 1,
|
||||
'numLevel': 1,
|
||||
adType: 1,
|
||||
'photos': 1,
|
||||
'note': 1,
|
||||
'descr': 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': 'MyBacheca',
|
||||
},
|
||||
},
|
||||
{
|
||||
'$replaceRoot': {
|
||||
'newRoot': {
|
||||
'$mergeObjects': [
|
||||
{
|
||||
'$arrayElemAt': [
|
||||
'$MyBacheca',
|
||||
0,
|
||||
],
|
||||
},
|
||||
'$$ROOT',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': {
|
||||
'recSkill': 1,
|
||||
'sector': 1,
|
||||
'idSector': 1,
|
||||
'idSkill': 1,
|
||||
'idSubSkill': 1,
|
||||
'idStatusSkill': 1,
|
||||
'idContribType': 1,
|
||||
'idCity': 1,
|
||||
'numLevel': 1,
|
||||
adType: 1,
|
||||
'photos': 1,
|
||||
'note': 1,
|
||||
'descr': 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,
|
||||
'idSector': 1,
|
||||
'idSkill': 1,
|
||||
'idSubSkill': 1,
|
||||
'idStatusSkill': 1,
|
||||
'idContribType': 1,
|
||||
'idCity': 1,
|
||||
'numLevel': 1,
|
||||
adType: 1,
|
||||
'photos': 1,
|
||||
'note': 1,
|
||||
'descr': 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 MyBacheca.aggregate(query).then((rec) => {
|
||||
return rec ? rec[0] : null;
|
||||
});
|
||||
};
|
||||
|
||||
MyBachecaSchema.statics.getCompleteRecord = function(idapp, id) {
|
||||
const MyBacheca = this;
|
||||
|
||||
return MyBacheca.getMyRecById(idapp, id);
|
||||
|
||||
};
|
||||
|
||||
|
||||
const MyBacheca = mongoose.model('MyBacheca', MyBachecaSchema);
|
||||
|
||||
module.exports = {MyBacheca};
|
||||
@@ -2558,6 +2558,7 @@ UserSchema.statics.calculateStat = async function(idapp, username) {
|
||||
const User = this;
|
||||
|
||||
const {MySkill} = require('../models/myskill');
|
||||
const {MyBacheca} = require('../models/mybacheca');
|
||||
const {MyGroup} = require('../models/mygroup');
|
||||
|
||||
const numUsersReg = await User.countDocuments(
|
||||
@@ -2570,9 +2571,11 @@ UserSchema.statics.calculateStat = async function(idapp, username) {
|
||||
|
||||
const numMySkills = await MySkill.countDocuments({idapp});
|
||||
|
||||
const numMyBachecas = await MyBacheca.countDocuments({idapp});
|
||||
|
||||
const numGroups = await MyGroup.countDocuments({idapp});
|
||||
|
||||
return {numMySkills, numUsersReg, numGroups};
|
||||
return {numMySkills, numMyBachecas, numUsersReg, numGroups};
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -129,8 +129,6 @@ module.exports = {
|
||||
let ris = null;
|
||||
try {
|
||||
|
||||
const {City} = require('../models/city');
|
||||
const {Province} = require('../models/province');
|
||||
|
||||
console.log('INIZIO - popolaTabelleNuove')
|
||||
|
||||
@@ -159,11 +157,12 @@ module.exports = {
|
||||
await this.insertIntoDb_NoDuplicate(abilita, 'statusskills', StatusSkill, 'descr')
|
||||
|
||||
// Cities
|
||||
const {City} = require('../models/city');
|
||||
await this.insertIntoDb_NoDuplicate(scrivi_citta, 'cities', City, 'comune')
|
||||
|
||||
// Province
|
||||
const {Province} = require('../models/province');
|
||||
await this.insertIntoDb_NoDuplicate(scrivi_citta, 'provinces', Province, 'descr')
|
||||
console.log('FINE - Scrivo le Città')
|
||||
|
||||
// Contribtypes
|
||||
const {Contribtype} = require('../models/contribtype');
|
||||
|
||||
@@ -11,6 +11,8 @@ const sendemail = require('../sendemail');
|
||||
|
||||
const resizer = require('node-image-resizer');
|
||||
|
||||
const sharp = require('sharp');
|
||||
|
||||
const {authenticate, authenticate_noerror} = require(
|
||||
'../middleware/authenticate');
|
||||
|
||||
@@ -90,6 +92,8 @@ const actions = require('./api/actions');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const globalTables = require('../tools/globalTables');
|
||||
|
||||
const UserCost = {
|
||||
FIELDS_REQUISITI: [
|
||||
'verified_email',
|
||||
@@ -216,124 +220,22 @@ router.post(process.env.LINK_UPDATE_PWD, (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
function getTableByTableName(tablename) {
|
||||
router.post('/testServer', (req, res) => {
|
||||
|
||||
let mytable = '';
|
||||
if (tablename === 'users')
|
||||
mytable = User;
|
||||
else if (tablename === 'mygroups')
|
||||
mytable = MyGroup;
|
||||
else if (tablename === 'tessitura')
|
||||
mytable = Tessitura;
|
||||
// else if (tablename === 'extralist')
|
||||
// mytable = ExtraList;
|
||||
else if (tablename === 'bookings')
|
||||
mytable = Booking;
|
||||
else if (tablename === 'operators')
|
||||
mytable = Operator;
|
||||
else if (tablename === 'products')
|
||||
mytable = Product;
|
||||
else if (tablename === 'storehouses')
|
||||
mytable = Storehouse;
|
||||
else if (tablename === 'departments')
|
||||
mytable = Department;
|
||||
else if (tablename === 'sharewithus')
|
||||
mytable = ShareWithUs;
|
||||
else if (tablename === 'sites')
|
||||
mytable = Site;
|
||||
else if (tablename === 'iscritticonacreis')
|
||||
mytable = IscrittiConacreis;
|
||||
else if (tablename === 'groups')
|
||||
mytable = Group;
|
||||
else if (tablename === 'todos')
|
||||
mytable = Todo;
|
||||
else if (tablename === 'hours')
|
||||
mytable = Hours;
|
||||
else if (tablename === 'orders')
|
||||
mytable = Order;
|
||||
else if (tablename === 'cashs')
|
||||
mytable = Cash;
|
||||
else if (tablename === 'cashCategorys')
|
||||
mytable = CashCategory;
|
||||
else if (tablename === 'cashSubCategorys')
|
||||
mytable = CashSubCategory;
|
||||
else if (tablename === 'producers')
|
||||
mytable = Producer;
|
||||
else if (tablename === 'carts')
|
||||
mytable = Cart;
|
||||
else if (tablename === 'orderscart')
|
||||
mytable = OrdersCart;
|
||||
else if (tablename === 'sendmsgs')
|
||||
mytable = SendMsg;
|
||||
else if (tablename === 'wheres')
|
||||
mytable = Where;
|
||||
else if (tablename === 'myevents')
|
||||
mytable = MyEvent;
|
||||
else if (tablename === 'contribtypes')
|
||||
mytable = Contribtype;
|
||||
else if (tablename === 'contribtype')
|
||||
mytable = Contribtype;
|
||||
else if (tablename === 'paymenttypes')
|
||||
mytable = PaymentType;
|
||||
else if (tablename === 'disciplines')
|
||||
mytable = Discipline;
|
||||
else if (tablename === 'newstosent')
|
||||
mytable = Newstosent;
|
||||
else if (tablename === 'gallery')
|
||||
mytable = Gallery;
|
||||
else if (tablename === 'mypage')
|
||||
mytable = MyPage;
|
||||
else if (tablename === 'mybots')
|
||||
mytable = MyBot;
|
||||
else if (tablename === 'calzoom')
|
||||
mytable = CalZoom;
|
||||
else if (tablename === 'templemail')
|
||||
mytable = TemplEmail;
|
||||
else if (tablename === 'opzemail')
|
||||
mytable = OpzEmail;
|
||||
else if (tablename === 'settings')
|
||||
mytable = Settings;
|
||||
else if (tablename === 'permissions')
|
||||
mytable = Permission;
|
||||
else if (tablename === 'mailinglist')
|
||||
mytable = MailingList;
|
||||
else if (tablename === 'msg_templates')
|
||||
mytable = MsgTemplate;
|
||||
else if (tablename === 'navepersistente')
|
||||
mytable = NavePersistente;
|
||||
// else if (tablename === 'listaingressos')
|
||||
// mytable = ListaIngresso;
|
||||
else if (tablename === 'graduatorias')
|
||||
mytable = Graduatoria;
|
||||
else if (tablename === 'skills')
|
||||
mytable = Skill;
|
||||
else if (tablename === 'subskills')
|
||||
mytable = SubSkill;
|
||||
else if (tablename === 'myskills')
|
||||
mytable = MySkill;
|
||||
else if (tablename === 'statusSkills')
|
||||
mytable = StatusSkill;
|
||||
else if (tablename === 'cities')
|
||||
mytable = City;
|
||||
else if (tablename === 'provinces')
|
||||
mytable = Province;
|
||||
else if (tablename === 'sectors')
|
||||
mytable = Sector;
|
||||
else if (tablename === 'catgrps')
|
||||
mytable = CatGrp;
|
||||
else if (tablename === 'levels')
|
||||
mytable = Level;
|
||||
else if (shared_consts.TablePickup.includes(tablename))
|
||||
mytable = Pickup;
|
||||
//else if (shared_consts.TableCities.includes(tablename))
|
||||
// mytable = City;
|
||||
try {
|
||||
const test = req.body.test;
|
||||
let ris = {test};
|
||||
|
||||
return mytable;
|
||||
}
|
||||
return res.send(ris);
|
||||
} catch (e) {
|
||||
return res.status(400).send(e);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
router.post('/settable', authenticate, (req, res) => {
|
||||
const params = req.body;
|
||||
const mytable = getTableByTableName(params.table);
|
||||
const mytable = globalTables.getTableByTableName(params.table);
|
||||
const mydata = req.body.data;
|
||||
|
||||
const fieldsvalue = {'ALL': 1};
|
||||
@@ -404,7 +306,7 @@ router.post('/settable', authenticate, (req, res) => {
|
||||
let mytablerec = new mytable(mydata);
|
||||
// console.log('mytablerec', mytablerec);
|
||||
|
||||
const mytablestrutt = getTableByTableName(params.table);
|
||||
const mytablestrutt = globalTables.getTableByTableName(params.table);
|
||||
|
||||
if (mydata['_id'] !== undefined && mydata['_id'] !== 0) {
|
||||
mytablerec.isNew = false;
|
||||
@@ -461,7 +363,7 @@ router.post('/settable', authenticate, (req, res) => {
|
||||
|
||||
router.post('/setsubrec', authenticate, (req, res) => {
|
||||
const params = req.body;
|
||||
const mytable = getTableByTableName(params.table);
|
||||
const mytable = globalTables.getTableByTableName(params.table);
|
||||
const mydata = req.body.data;
|
||||
|
||||
mydata.idapp = req.user.idapp;
|
||||
@@ -469,7 +371,7 @@ router.post('/setsubrec', authenticate, (req, res) => {
|
||||
let mytablerec = new mytable(mydata);
|
||||
// console.log('mytablerec', mytablerec);
|
||||
|
||||
const mytablestrutt = getTableByTableName(params.table);
|
||||
const mytablestrutt = globalTables.getTableByTableName(params.table);
|
||||
|
||||
const rec = mytablestrutt.createNewSubRecord(mydata.idapp, req).then(rec => {
|
||||
// tools.mylog('rec', rec);
|
||||
@@ -510,7 +412,7 @@ router.post('/setsubrec', authenticate, (req, res) => {
|
||||
|
||||
router.post('/gettable', authenticate, (req, res) => {
|
||||
const params = req.body;
|
||||
const mytable = getTableByTableName(params.table);
|
||||
const mytable = globalTables.getTableByTableName(params.table);
|
||||
// console.log('mytable', mytable);
|
||||
if (!mytable) {
|
||||
console.log(`Table ${params.table} not found`);
|
||||
@@ -529,7 +431,7 @@ router.post('/gettable', authenticate, (req, res) => {
|
||||
|
||||
router.post('/pickup', authenticate, (req, res) => {
|
||||
const params = req.body;
|
||||
let mytable = getTableByTableName(params.table);
|
||||
let mytable = globalTables.getTableByTableName(params.table);
|
||||
// console.log('mytable', mytable);
|
||||
if (!mytable) {
|
||||
console.log(`Table ${params.table} not found`);
|
||||
@@ -592,7 +494,7 @@ router.patch('/chval', authenticate, async (req, res) => {
|
||||
const idapp = req.body.idapp;
|
||||
const mydata = req.body.data;
|
||||
|
||||
const mytable = getTableByTableName(mydata.table);
|
||||
const mytable = globalTables.getTableByTableName(mydata.table);
|
||||
const fieldsvalue = mydata.fieldsvalue;
|
||||
const unset = mydata.unset;
|
||||
|
||||
@@ -802,7 +704,7 @@ router.patch('/askfunz', authenticate, async (req, res) => {
|
||||
if (!!userfree)
|
||||
return res.send({code: server_constants.RIS_CODE_OK, out: userfree});
|
||||
/*} else if (mydata.myfunc === shared_consts.CallFunz.GET_VALBYTABLE) {
|
||||
const mytable = getTableByTableName(mydata.table);
|
||||
const mytable = globalTables.getTableByTableName(mydata.table);
|
||||
const coltoshow = {
|
||||
[mydata.coltoshow]: 1
|
||||
};
|
||||
@@ -811,7 +713,7 @@ router.patch('/askfunz', authenticate, async (req, res) => {
|
||||
|
||||
return ris;
|
||||
} else if (mydata.myfunc === shared_consts.CallFunz.SET_VALBYTABLE) {
|
||||
const mytable = getTableByTableName(mydata.table);
|
||||
const mytable = globalTables.getTableByTableName(mydata.table);
|
||||
const value = mydata.value;
|
||||
const coltoset = {
|
||||
[mydata.coltoshow]: value
|
||||
@@ -892,7 +794,7 @@ router.get('/copyfromapptoapp/:idapporig/:idappdest', async (req, res) => {
|
||||
// try {
|
||||
// let numrectot = 0;
|
||||
// for (const table of mytablesstr) {
|
||||
// const mytable = getTableByTableName(table);
|
||||
// const mytable = globalTables.getTableByTableName(table);
|
||||
//
|
||||
// tools.mylogshow('copyfromapptoapp: ', table, mytable);
|
||||
//
|
||||
@@ -919,7 +821,7 @@ router.delete('/delrec/:table/:id', authenticate, async (req, res) => {
|
||||
|
||||
console.log('id', id, 'table', tablename);
|
||||
|
||||
const mytable = getTableByTableName(tablename);
|
||||
const mytable = globalTables.getTableByTableName(tablename);
|
||||
|
||||
const fields = {'ALL': 1};
|
||||
|
||||
@@ -991,7 +893,7 @@ router.post('/duprec/:table/:id', authenticate, (req, res) => {
|
||||
|
||||
console.log('id', id, 'table', tablename);
|
||||
|
||||
const mytable = getTableByTableName(tablename);
|
||||
const mytable = globalTables.getTableByTableName(tablename);
|
||||
|
||||
if (!req.user) {
|
||||
return res.status(404).
|
||||
@@ -1439,44 +1341,42 @@ function uploadFile(req, res, version) {
|
||||
|
||||
// Move in the folder application !
|
||||
// tools.move(oldpath, newname, (err) => {
|
||||
tools.move(oldpath, newname, async (err) => {
|
||||
tools.move(oldpath, newname, (err) => {
|
||||
if (err)
|
||||
console.log('err:', err);
|
||||
|
||||
const setup_image_compress = {
|
||||
all: {
|
||||
path: mydir + '/',
|
||||
quality: 80,
|
||||
},
|
||||
versions: [
|
||||
{
|
||||
prefix: server_constants.PREFIX_IMG,
|
||||
width: 512,
|
||||
height: 512,
|
||||
}, {
|
||||
quality: 100,
|
||||
prefix: server_constants.PREFIX_IMG_SMALL,
|
||||
width: 64,
|
||||
height: 64,
|
||||
}],
|
||||
};
|
||||
|
||||
// Salva le immagini in formato compresso
|
||||
try {
|
||||
const ris = await resizer(newname, setup_image_compress);
|
||||
console.log('resizer', newname);
|
||||
if (ris) {
|
||||
if (tools.isFileExists(resized_img)) {
|
||||
tools.delete(newname, false, () => {});
|
||||
let resized_img_small = tools.extractFilePath(newname) + '/' +
|
||||
server_constants.PREFIX_IMG_SMALL +
|
||||
tools.extractFileName(newname);
|
||||
// SMALL
|
||||
sharp(newname).
|
||||
resize(64, 64).
|
||||
toFile(resized_img_small);
|
||||
|
||||
tools.move(resized_img, newname, (err) => {
|
||||
if (err)
|
||||
console.error('err', err);
|
||||
else
|
||||
console.log('move', newname);
|
||||
// MEDIUM
|
||||
let resized_img = tools.extractFilePath(newname) + '/' +
|
||||
server_constants.PREFIX_IMG + tools.extractFileName(newname);
|
||||
sharp(newname).
|
||||
resize(512, 512).
|
||||
toFile(resized_img, function(err) {
|
||||
|
||||
if (tools.isFileExists(resized_img)) {
|
||||
// DELETE THE ORIGINAL BIG
|
||||
tools.delete(newname, false, () => {});
|
||||
|
||||
// RENAME THE MEDIUM IN THE ORIGINAL NAME
|
||||
tools.move(resized_img, newname, (err) => {
|
||||
if (err)
|
||||
console.error('err', err);
|
||||
else
|
||||
console.log('move', newname);
|
||||
});
|
||||
}
|
||||
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('newname', e);
|
||||
}
|
||||
|
||||
63
src/server/router/mygen_router.js
Executable file
63
src/server/router/mygen_router.js
Executable file
@@ -0,0 +1,63 @@
|
||||
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 {MyBacheca} = require('../models/mybacheca');
|
||||
var {User} = require('../models/user');
|
||||
|
||||
const globalTables = require('../tools/globalTables');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
|
||||
//GET orders
|
||||
router.post('/page', authenticate, function(req, res, next) {
|
||||
|
||||
//++TODO: PERMESSI ???
|
||||
|
||||
try {
|
||||
let table = req.body.table;
|
||||
let id = req.body.id;
|
||||
let idapp = req.body.idapp;
|
||||
|
||||
let mytable = null;
|
||||
if (shared_consts.TABLES_ENABLE_GETREC_BYID.includes(table)) {
|
||||
mytable = globalTables.getTableByTableName(table);
|
||||
}
|
||||
|
||||
if (mytable) {
|
||||
|
||||
return mytable.getMyRecById(idapp, id).
|
||||
then((ris) => {
|
||||
|
||||
if (ris) {
|
||||
res.send(ris);
|
||||
|
||||
} else {
|
||||
res.status(400).send();
|
||||
}
|
||||
}).catch((e) => {
|
||||
console.error('Err', e);
|
||||
res.status(400).send(e);
|
||||
})
|
||||
|
||||
}
|
||||
}catch (e) {
|
||||
console.error('/page', e);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@@ -104,6 +104,7 @@ myLoad().then(ris => {
|
||||
const cart_router = require('./router/cart_router');
|
||||
const orders_router = require('./router/orders_router');
|
||||
const myskills_router = require('./router/myskills_router');
|
||||
const mygen_router = require('./router/mygen_router');
|
||||
|
||||
const { MyEvent } = require('./models/myevent');
|
||||
|
||||
@@ -158,6 +159,7 @@ myLoad().then(ris => {
|
||||
app.use('/cart', cart_router);
|
||||
app.use('/orders', orders_router);
|
||||
app.use('/myskills', myskills_router);
|
||||
app.use('/mygen', mygen_router);
|
||||
|
||||
// catch 404 and forward to error handler
|
||||
// app.use(function (req, res, next) {
|
||||
|
||||
@@ -22,6 +22,7 @@ const {Discipline} = require('../models/discipline');
|
||||
const {Skill} = require('../models/skill');
|
||||
const {SubSkill} = require('../models/subskill');
|
||||
const {MySkill} = require('../models/myskill');
|
||||
const {MyBacheca} = require('../models/mybacheca');
|
||||
const {StatusSkill} = require('../models/statusSkill');
|
||||
const {City} = require('../models/city');
|
||||
const {Province} = require('../models/province');
|
||||
@@ -61,6 +62,8 @@ const CashSubCategory = require('../models/cashSubCategory');
|
||||
|
||||
const tools = require('./general');
|
||||
|
||||
const shared_consts = require('./shared_nodejs');
|
||||
|
||||
module.exports = {
|
||||
|
||||
getTableByTableName(tablename) {
|
||||
@@ -154,8 +157,10 @@ module.exports = {
|
||||
mytable = Skill;
|
||||
else if (tablename === 'subskills')
|
||||
mytable = SubSkill;
|
||||
else if (tablename === 'myskills')
|
||||
else if (tablename === shared_consts.TABLES_MYSKILLS)
|
||||
mytable = MySkill;
|
||||
else if (tablename === shared_consts.TABLES_MYBACHECAS)
|
||||
mytable = MyBacheca;
|
||||
else if (tablename === 'statusSkills')
|
||||
mytable = StatusSkill;
|
||||
else if (tablename === 'cities')
|
||||
|
||||
@@ -85,15 +85,25 @@ module.exports = {
|
||||
|
||||
PARAM_SHOW_PROVINCE: 1,
|
||||
|
||||
TABLES_ID_NUMBER: ['permissions', 'levels', 'statusSkills', 'sectors', 'skills', 'subskills', 'cities', 'myskills'],
|
||||
TABLES_USER_ID: ['myskills', 'mygroups'],
|
||||
TABLES_USER_INCLUDE_MY: ['mygroups'],
|
||||
TABLES_UPDATE_LASTMODIFIED: ['myskills', 'mybots', 'mygroups'],
|
||||
TABLES_GETCOMPLETEREC: ['myskills'],
|
||||
TABLES_MYSKILLS: 'myskills',
|
||||
TABLES_MYBACHECAS: 'mybachecas',
|
||||
|
||||
TABLES_PERM_CHANGE_FOR_USERS: ['myskills', 'mygroups'],
|
||||
TABLES_ENABLE_GETREC_BYID: ['mybachecas'],
|
||||
|
||||
TABLES_USER_INCLUDE_MY: ['mygroups'],
|
||||
TABLES_GETCOMPLETEREC: ['myskills', 'mybachecas'],
|
||||
TABLES_PERM_NEWREC: ['skills', 'subskills', 'mygroups'],
|
||||
|
||||
TABLES_ID_NUMBER: ['permissions', 'levels', 'adtypes', 'statusSkills', 'sectors', 'catgrps', 'skills', 'subskills', 'cities', 'provinces', 'myskills', 'mybachecas', 'mygroups'],
|
||||
TABLES_USER_ID: ['myskills', 'mybachecas'],
|
||||
TABLES_UPDATE_LASTMODIFIED: ['myskills', 'mybachecas', 'mybots'],
|
||||
TABLES_FINDER: ['myskills', 'mybachecas', 'mygroups'],
|
||||
|
||||
TABLES_PERM_CHANGE_FOR_USERS: ['myskills', 'mybachecas'],
|
||||
TABLES_VISU_LISTA_USER: ['myskills', 'mybachecas', 'users'],
|
||||
TABLES_NOT_SHOW_IF_USERNAME: ['myskills', 'mybachecas'],
|
||||
|
||||
|
||||
VISIB_ALL: 0,
|
||||
VISIB_ONLYIF_VERIFIED: 1,
|
||||
VISIB_ONLY_MANAGER: 2,
|
||||
|
||||
Reference in New Issue
Block a user