Nuovo Sistema di registrazione:

tramite il BOT, viene memorizzato l'username telegram e si usa quello come username per la APP, e l'ID telegram viene passato direttamente, senza chiedere la verifica.

- ospitalità (inizio).
This commit is contained in:
Paolo Arena
2022-05-04 00:26:12 +02:00
parent 5139d321b5
commit 311e714d7d
9 changed files with 720 additions and 91 deletions

498
src/server/models/myhosp.js Executable file
View File

@@ -0,0 +1,498 @@
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 MyHospSchema = 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,
},
idStatusSkill: [
{
type: Number,
}],
idContribType: [
{
type: String,
}],
idCity: [
{
type: Number,
}],
dateTimeStart: {
type: Date,
},
dateTimeEnd: {
type: Date,
},
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,
},
//**ADDFIELD_MyHospS
website: {
type: String,
},
date_created: {
type: Date,
default: Date.now,
},
date_updated: {
type: Date,
default: Date.now,
},
});
MyHospSchema.pre('save', async function(next) {
if (this.isNew) {
const myrec = await MyHosp.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();
});
MyHospSchema.statics.findAllIdApp = async function(idapp) {
const MyHosp = this;
const query = [
{$match: {idapp}},
{$sort: {descr: 1}},
];
return MyHosp.aggregate(query).then((arrrec) => {
return arrrec;
});
};
MyHospSchema.statics.getFieldsForSearch = function() {
return [];
};
MyHospSchema.statics.getFieldsLastForSearch = function() {
return [
{field: 'note', type: tools.FieldType.string},
{field: 'descr', type: tools.FieldType.string},
{field: 'recSkill.descr', type: tools.FieldType.string},
{field: 'MyHosp.descr', type: tools.FieldType.string},
];
};
MyHospSchema.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,
MyHosp: 1,
idStatusSkill: 1,
idContribType: 1,
dateTimeStart: 1,
dateTimeEnd: 1,
idCity: 1,
numLevel: 1,
adType: 1,
photos: 1,
note: 1,
//**ADDFIELD_MyHospS
website: 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);
};
MyHospSchema.statics.getMyRecById = function(idapp, id) {
const MyHosp = 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,
dateTimeStart: 1,
dateTimeEnd: 1,
'idCity': 1,
'numLevel': 1,
adType: 1,
'photos': 1,
'note': 1,
website: 1,
//**ADDFIELD_MyHospS
'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,
dateTimeStart: 1,
dateTimeEnd: 1,
'idCity': 1,
'numLevel': 1,
adType: 1,
'photos': 1,
'note': 1,
website: 1,
//**ADDFIELD_MyHospS
'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,
dateTimeStart: 1,
dateTimeEnd: 1,
'idCity': 1,
'numLevel': 1,
adType: 1,
'photos': 1,
'note': 1,
website: 1,
//**ADDFIELD_MyHospS
'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': 'MyHosp',
},
},*/
{
'$replaceRoot': {
'newRoot': {
'$mergeObjects': [
{
'$arrayElemAt': [
'$MyHosp',
0,
],
},
'$$ROOT',
],
},
},
},
{
'$project': {
'recSkill': 1,
'sector': 1,
'idSector': 1,
'idSkill': 1,
// 'idSubSkill': 1,
'idStatusSkill': 1,
'idContribType': 1,
dateTimeStart: 1,
dateTimeEnd: 1,
'idCity': 1,
'numLevel': 1,
adType: 1,
'photos': 1,
'note': 1,
website: 1,
//**ADDFIELD_MyHospS
'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,
dateTimeStart: 1,
dateTimeEnd: 1,
'idCity': 1,
'numLevel': 1,
adType: 1,
'photos': 1,
'note': 1,
website: 1,
//**ADDFIELD_MyHospS
'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 MyHosp.aggregate(query).then((rec) => {
return rec ? rec[0] : null;
});
};
MyHospSchema.statics.getCompleteRecord = function(idapp, id) {
const MyHosp = this;
return MyHosp.getMyRecById(idapp, id);
};
const MyHosp = mongoose.model('MyHosp', MyHospSchema);
module.exports = {MyHosp};

View File

@@ -76,19 +76,19 @@ module.exports.getProducerByTitle = function (query,sort, callback) {
}
module.exports.filterProducerByDepartment = function (department, callback) {
let regexp = new RegExp(`${department}`, 'i')
let regexp = new RegExp(`^${department}$`, 'i')
var query = { department: { $regex: regexp } };
Producer.find(query, callback)
}
module.exports.filterProducerByCategory = function (category, callback) {
let regexp = new RegExp(`${category}`, 'i')
let regexp = new RegExp(`^${category}$`, 'i')
var query = { category: { $regex: regexp } };
Producer.find(query, callback);
}
module.exports.filterProducerByTitle = function (title, callback) {
let regexp = new RegExp(`${title}`, 'i')
let regexp = new RegExp(`^${title}$`, 'i')
var query = { title: { $regex: regexp } };
Producer.find(query, callback);
}

View File

@@ -162,19 +162,19 @@ module.exports.getProductByCode = function (idapp, code) {
}
module.exports.filterProductByDepartment = function (department, callback) {
let regexp = new RegExp(`${department}`, 'i')
let regexp = new RegExp(`^${department}$`, 'i')
var query = { department: { $regex: regexp } };
Product.find(query, callback)
}
module.exports.filterProductByCategory = function (category, callback) {
let regexp = new RegExp(`${category}`, 'i')
let regexp = new RegExp(`^${category}$`, 'i')
var query = { category: { $regex: regexp } };
Product.find(query, callback);
}
module.exports.filterProductByTitle = function (title, callback) {
let regexp = new RegExp(`${title}`, 'i')
let regexp = new RegExp(`^${title}$`, 'i')
var query = { title: { $regex: regexp } };
Product.find(query, callback);
}

View File

@@ -549,7 +549,7 @@ UserSchema.statics.findByCredentials = function(idapp, username, password, pwdcr
const User = this;
let pwd = '';
let regexp = new RegExp(`${username}`, 'i');
let regexp = new RegExp(`^${username}$`, 'i');
return User.findOne({
idapp,
@@ -647,7 +647,7 @@ UserSchema.statics.findByUsername = async function(idapp, username, alsoemail, o
UserSchema.statics.getUserShortDataByUsername = async function(idapp, username) {
const User = this;
let regexp = new RegExp(`${username}`, 'i');
let regexp = new RegExp(`^${username}$`, 'i');
const myrec = await User.findOne({
'idapp': idapp,
@@ -2196,7 +2196,7 @@ UserSchema.statics.getNameSurnameByUsername = async function(
UserSchema.statics.getIdByUsername = async function(idapp, username) {
const User = this;
let regexp = new RegExp(`${username}`, 'i');
let regexp = new RegExp(`^${username}$`, 'i');
return User.findOne({
idapp,
@@ -2212,7 +2212,7 @@ UserSchema.statics.getIdByUsername = async function(idapp, username) {
UserSchema.statics.getRealUsernameByUsername = async function(idapp, username) {
const User = this;
let regexp = new RegExp(`${username}`, 'i');
let regexp = new RegExp(`^${username}$`, 'i');
return User.findOne({
idapp,