Files
freeplanet_serverside/src/server/models/mailinglist.js
Surya Paolo 53a70a1c96 - Aggiornato node.js alla versione 22.18.1
- Aggiornato tutti i pacchetti del server all'ultima versione.
- passato mongoose da versione 5 a versione 6
2025-03-03 00:46:08 +01:00

93 lines
2.4 KiB
JavaScript
Executable File

const mongoose = require('mongoose').set('debug', false)
const Schema = mongoose.Schema;
const tools = require('../tools/general');
mongoose.Promise = global.Promise;
mongoose.level = "F";
const { User } = require('./user');
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
const MailingListSchema = new Schema({
});
MailingListSchema.statics.executeQueryTable = function (idapp, params) {
params.fieldsearch = User.getFieldsForSearch();
return tools.executeQueryTable(this, idapp, params);
};
MailingListSchema.statics.findAllIdAppSubscribed = function (idapp) {
const myfind = {
idapp,
news_on: true,
$or: [
{ deleted: { $exists: false } },
{ deleted: { $exists: true, $eq: false } }],
$or: [
{ email_errata: { $exists: false } },
{ email_errata: { $exists: true, $ne: true } }],
};
// Extract only the Teacher where in the users table the field permissions is set 'Teacher' bit.
return tools.findAllQueryIdApp(User, myfind);
};
MailingListSchema.statics.getnumSent = async function (idapp, idUser) {
const myfind = { idapp, news_on: true, lastid_newstosent: idUser };
// Extract only the Teacher where in the users table the field permissions is set 'Teacher' bit.
return await User.countDocuments(myfind);
};
MailingListSchema.statics.isOk = async function (idapp, iduser, idUser) {
const myfind = { idapp, _id: iduser, news_on: true, lastid_newstosent: { $ne: idUser } };
// Extract only the Teacher where in the users table the field permissions is set 'Teacher' bit.
return await User.countDocuments(myfind) > 0;
};
MailingListSchema.statics.findAllIdApp = async function (idapp) {
const myfind = { idapp };
return await tools.findAllQueryIdApp(User, myfind);
};
MailingListSchema.statics.isUnsubscribed = async function (idapp, hash) {
let myperson = await User.findOne({ idapp, hash });
if (!!myperson) {
return (!myperson.news_on)
}
};
MailingListSchema.statics.findByHash = function (idapp, hash) {
const myfind = { idapp, hash };
// Extract only the Teacher where in the users table the field permissions is set 'Teacher' bit.
return User.findOne(myfind).lean();
};
const MailingList = mongoose.model('MailingList', MailingListSchema);
User.createIndexes()
.then(() => { })
.catch((err) => { throw err; });
module.exports = { MailingList };