2022-08-09 19:16:34 +03:00
|
|
|
const mongoose = require("mongoose")
|
2022-04-06 21:14:46 +03:00
|
|
|
|
2022-08-09 19:16:34 +03:00
|
|
|
const schema = new mongoose.Schema({
|
|
|
|
id: { type: String, unique: true },
|
2022-04-06 21:14:46 +03:00
|
|
|
|
|
|
|
name: String,
|
2022-08-09 19:16:34 +03:00
|
|
|
avatar: { type: String, default: "/images/guest.png" },
|
|
|
|
time: { type: Date, default: Date.now },
|
2022-04-06 21:14:46 +03:00
|
|
|
deleted: { type: Boolean, default: false },
|
|
|
|
admin: { type: Boolean, default: 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);
|
|
|
|
|
|
|
|
model.get = id => model.findOne({ id });
|
|
|
|
|
|
|
|
module.exports = model;
|