akf-forum/models/Category.js

21 lines
501 B
JavaScript
Raw Normal View History

2022-09-09 17:13:37 +03:00
const mongoose = require("mongoose")
const schema = new mongoose.Schema({
name: { type: String, unique: true },
desp: String, position: Number,
id: { type: String, unique: true },
authorID: { type: String }
});
schema.methods.takeId = async function () {
this.id = String(await model.count() || 0);
return this;
}
2022-09-09 20:47:28 +03:00
schema.methods.getLink = function (id = this.id) {
2023-03-19 17:14:33 +03:00
return "/categories/" + id;
2022-09-09 20:47:28 +03:00
}
2022-09-09 17:13:37 +03:00
const model = mongoose.model('category', schema);
module.exports = model;