akf-forum/models/User.js

30 lines
815 B
JavaScript
Raw Normal View History

const mongoose = require("mongoose")
2022-08-27 10:31:16 +03:00
const { def_theme } = require("../config.json");
const schema = new mongoose.Schema({
id: { type: String },
2022-04-06 21:14:46 +03:00
name: String,
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 },
2022-08-29 19:31:59 +03:00
edited: { type: Boolean, default: false },
about: { type: String, default: "" },
2022-08-27 10:31:16 +03:00
admin: { type: Boolean, default: false },
theme: { type: String, default: def_theme }
2022-04-06 21:14:46 +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;