mirror of
https://github.com/Akif9748/akf-forum.git
synced 2024-11-22 20:10:40 +03:00
36 lines
No EOL
879 B
JavaScript
36 lines
No EOL
879 B
JavaScript
const mongoose = require("mongoose")
|
|
const cache = require("./cache")
|
|
const schema = new mongoose.Schema({
|
|
id: { type: String, unique: true },
|
|
author: Object,
|
|
threadID: String,
|
|
authorID: String,
|
|
content: String,
|
|
time: { type: Date, default: Date.now },
|
|
deleted: { type: Boolean, default: false },
|
|
edited: { type: Boolean, default: false },
|
|
react: {
|
|
like: [Number],
|
|
dislike: [Number]
|
|
}
|
|
})
|
|
|
|
schema.methods.get_author = cache.getAuthor
|
|
|
|
schema.methods.takeId = async function () {
|
|
this.id = String(await model.count() || 0);
|
|
return this;
|
|
}
|
|
|
|
schema.methods.getLink = function (id = this.id) {
|
|
return "/messages/" + id;
|
|
}
|
|
|
|
const model = mongoose.model('message', schema);
|
|
|
|
model.get = async id => {
|
|
const message = await model.findOne({ id })
|
|
return await message.get_author();
|
|
};
|
|
|
|
module.exports = model; |