- Bot Telegram ...

This commit is contained in:
Paolo Arena
2020-01-03 22:02:18 +01:00
parent f359f8f723
commit 8f784df4fa
10 changed files with 208 additions and 36 deletions

View File

@@ -146,6 +146,9 @@ var UserSchema = new mongoose.Schema({
teleg_checkcode: {
type: Number
},
manage_telegram: {
type: Boolean
},
dateofbirth: {
type: Date,
},
@@ -207,15 +210,15 @@ UserSchema.statics.setPermissionsById = function (id, perm) {
UserSchema.statics.isAdmin = function (user) {
try {
return ((user.perm & shared_consts.Permissions.Admin) === shared_consts.Permissions.Admin);
return ((perm & shared_consts.Permissions.Admin) === shared_consts.Permissions.Admin);
} catch (e) {
return false
}
};
UserSchema.statics.isManager = function (user) {
UserSchema.statics.isManager = function (perm) {
try {
return ((user.perm & shared_consts.Permissions.Manager) === shared_consts.Permissions.Manager);
return ((perm & shared_consts.Permissions.Manager) === shared_consts.Permissions.Manager);
} catch (e) {
return false
}
@@ -422,6 +425,17 @@ UserSchema.statics.UserByIdTelegram = async function (idapp, teleg_id) {
});
};
UserSchema.statics.TelegIdByUsername = async function (idapp, username) {
const User = this;
return await User.findOne({ idapp, username }, {'profile.teleg_id': 1})
.then((rec) => {
return (!!rec) ? rec.profile.teleg_id : null;
}).catch((e) => {
console.error('TelegIdByUsername', e);
});
};
UserSchema.statics.SetTelegramCheckCode = async function (idapp, username, teleg_checkcode) {
const User = this;
@@ -455,6 +469,29 @@ UserSchema.statics.SetTelegramIdSuccess = async function (idapp, username, teleg
};
UserSchema.statics.getNameSurnameByUsername = async function (idapp, username) {
const User = this;
return await User.findOne({ idapp, username }, {name: 1, surname: 1})
.then((rec) => {
return (!!rec) ? `${rec.name} ${rec.surname}` : '';
}).catch((e) => {
console.error('getNameSurnameByUsername', e);
});
};
UserSchema.statics.getusersManagers = async function (idapp) {
const User = this;
return await User.find({ idapp, 'profile.manage_telegram': true }, {'profile.teleg_id': 1})
.then((arrrec) => {
return (!!arrrec) ? arrrec : null;
}).catch((e) => {
console.error('getusersManagers', e);
});
};
UserSchema.statics.getUsersList = function (idapp) {
const User = this;
@@ -474,6 +511,7 @@ UserSchema.statics.getUsersList = function (idapp) {
};
UserSchema.statics.getUsersListByParams = function (params) {
const User = this;