mirror of
https://github.com/Akif9748/akf-forum.git
synced 2024-11-29 22:20:41 +03:00
Akif9748
ae83e014a0
The dublicate key error fixed, ids as string. classes removed. using mongoose's magic
28 lines
No EOL
644 B
JavaScript
28 lines
No EOL
644 B
JavaScript
const mongoose = require("mongoose")
|
|
|
|
const schema = new mongoose.Schema({
|
|
id: { type: String, unique: true },
|
|
|
|
name: String,
|
|
avatar: { type: String, default: "/images/guest.png" },
|
|
time: { type: Date, default: Date.now },
|
|
deleted: { type: Boolean, default: false },
|
|
admin: { type: Boolean, default: false }
|
|
|
|
});
|
|
|
|
|
|
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; |