This commit is contained in:
recaptcha committed 2022-08-10 13:06:23 +02:00
1 parent d3d221f9e3
commit e59845661f
19 files changed
+4803 -4

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const UserSchema = new Schema(
{
_id: {
type: Number,
required: true,
},
anixartId: {
type: Number,
required: true,
}
},
{ versionKey: false }
);
// Возвращает пользователя и создаёт его, если нет
UserSchema.statics.firstOrCreate = async function(tgUser, anixartId) {
let user = await this.findById(tgUser.id);
if (!user && !tgUser.is_bot) {
user = await new this({
_id: tgUser.id,
anixartId: anixartId
}).save();
}
return user;
};
module.exports = mongoose.model("users", UserSchema);