2022-08-09 19:16:34 +03:00
|
|
|
const mongoose = require("mongoose")
|
2022-09-24 01:39:06 +03:00
|
|
|
const { def_theme, limits, email_auth } = require("../config.json");
|
2022-08-09 19:16:34 +03:00
|
|
|
const schema = new mongoose.Schema({
|
2022-09-17 00:27:38 +03:00
|
|
|
id: { type: String, unique: true },
|
2022-09-23 23:10:13 +03:00
|
|
|
discordID: { type: String },
|
2022-09-17 20:25:19 +03:00
|
|
|
name: { type: String, maxlength: limits.names },
|
2022-09-09 16:29:36 +03:00
|
|
|
avatar: { type: String, default: "/images/avatars/default.jpg" },
|
2022-08-09 19:16:34 +03:00
|
|
|
time: { type: Date, default: Date.now },
|
2022-04-06 21:14:46 +03:00
|
|
|
deleted: { type: Boolean, default: false },
|
2022-08-29 19:31:59 +03:00
|
|
|
edited: { type: Boolean, default: false },
|
2022-09-17 20:25:19 +03:00
|
|
|
about: { type: String, default: "", maxlength: limits.desp },
|
2022-08-27 10:31:16 +03:00
|
|
|
admin: { type: Boolean, default: false },
|
2022-09-09 18:00:32 +03:00
|
|
|
theme: { type: String, default: def_theme },
|
2022-09-16 22:26:03 +03:00
|
|
|
lastSeen: { type: Date, default: Date.now, select: false },
|
|
|
|
hideLastSeen: { type: Boolean, default: false },
|
2022-09-23 23:10:13 +03:00
|
|
|
ips: { type: [String], default: [], select: false },
|
2022-09-24 00:15:17 +03:00
|
|
|
password: { type: String, select: false },
|
2022-09-24 01:39:06 +03:00
|
|
|
discord_code: { type: String, select: false },
|
|
|
|
approved: { type: Boolean, default: !email_auth },
|
|
|
|
email: { type: String, select: false },
|
|
|
|
email_code: { type: String, select: false },
|
2022-08-09 19:16:34 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
schema.methods.takeId = async function () {
|
|
|
|
this.id = String(await model.count() || 0);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
schema.methods.getLink = function (id = this.id) {
|
|
|
|
return "/users/" + id;
|
|
|
|
}
|
|
|
|
|
|
|
|
const model = mongoose.model('user', schema);
|
|
|
|
|
2022-09-16 22:26:03 +03:00
|
|
|
model.get = (id, select) => model.findOne({ id }).select(select);
|
2022-08-09 19:16:34 +03:00
|
|
|
|
|
|
|
module.exports = model;
|