chore(models): remove dead MongoDB Article, Comment, Tag models
Migration to MySQL is complete for these three entities — ArticleService, CommentService, and TagService all use Sequelize exclusively. No remaining references to the Mongoose versions anywhere in the codebase.
This commit is contained in:
@@ -1,60 +0,0 @@
|
|||||||
var mongoose = require('mongoose');
|
|
||||||
var uniqueValidator = require('mongoose-unique-validator');
|
|
||||||
var slug = require('slug');
|
|
||||||
var User = mongoose.model('User');
|
|
||||||
//var Membre = mongoose.model('Membre');
|
|
||||||
|
|
||||||
var ArticleSchema = new mongoose.Schema({
|
|
||||||
slug: { type: String, lowercase: true, unique: true },
|
|
||||||
title: String,
|
|
||||||
description: String,
|
|
||||||
body: String,
|
|
||||||
membre: String,
|
|
||||||
// membre: Membre.schema,
|
|
||||||
// membre: { type: mongoose.Schema.Types.ObjectId, ref: 'Membre' },
|
|
||||||
author: { type: mongoose.Schema.Types.UUID, ref: 'User' },
|
|
||||||
comments: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Comment' }],
|
|
||||||
favoritesCount: { type: Number, default: 0 },
|
|
||||||
tagList: [{ type: String }]
|
|
||||||
}, { timestamps: true, toJSON: { virtuals: true } });
|
|
||||||
|
|
||||||
ArticleSchema.plugin(uniqueValidator, { message: 'is already taken' });
|
|
||||||
|
|
||||||
ArticleSchema.pre('validate', function (next) {
|
|
||||||
if (!this.slug) {
|
|
||||||
this.slugify();
|
|
||||||
}
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
|
|
||||||
ArticleSchema.methods.slugify = function () {
|
|
||||||
this.slug = slug(this.title) + '-' + (Math.random() * Math.pow(36, 6) | 0).toString(36);
|
|
||||||
};
|
|
||||||
|
|
||||||
ArticleSchema.methods.updateFavoriteCount = function () {
|
|
||||||
var article = this;
|
|
||||||
|
|
||||||
return User.count({ favorites: { $in: [article._id] } }).then(function (count) {
|
|
||||||
article.favoritesCount = count;
|
|
||||||
|
|
||||||
return article.save();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
ArticleSchema.methods.toJSONFor = function (user) {
|
|
||||||
return {
|
|
||||||
slug: this.slug,
|
|
||||||
title: this.title,
|
|
||||||
description: this.description,
|
|
||||||
body: this.body,
|
|
||||||
createdAt: this.createdAt,
|
|
||||||
updatedAt: this.updatedAt,
|
|
||||||
tagList: this.tagList,
|
|
||||||
membre: this.membre,
|
|
||||||
favorited: user ? user.isFavorite(this._id) : false,
|
|
||||||
favoritesCount: this.favoritesCount,
|
|
||||||
author: this.author.toProfileJSONFor(user)
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
mongoose.model('Article', ArticleSchema);
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
var mongoose = require('mongoose');
|
|
||||||
|
|
||||||
var CommentSchema = new mongoose.Schema({
|
|
||||||
body: String,
|
|
||||||
author: { type: mongoose.Schema.Types.UUID, ref: 'User' },
|
|
||||||
article: { type: mongoose.Schema.Types.ObjectId, ref: 'Article' }
|
|
||||||
}, { timestamps: true, toJSON: { virtuals: true } });
|
|
||||||
|
|
||||||
// Requires population of author
|
|
||||||
CommentSchema.methods.toJSONFor = function (user) {
|
|
||||||
return {
|
|
||||||
id: this._id,
|
|
||||||
body: this.body,
|
|
||||||
createdAt: this.createdAt,
|
|
||||||
author: this.author.toProfileJSONFor(user)
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
mongoose.model('Comment', CommentSchema);
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
const mongoose = require('mongoose');
|
|
||||||
const uniqueValidator = require('mongoose-unique-validator');
|
|
||||||
|
|
||||||
const TagSchema = new mongoose.Schema({
|
|
||||||
tagName: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
unique: true
|
|
||||||
},
|
|
||||||
articles: [{
|
|
||||||
type: mongoose.Schema.Types.ObjectId,
|
|
||||||
ref: 'Article'
|
|
||||||
}]
|
|
||||||
})
|
|
||||||
|
|
||||||
TagSchema.plugin(uniqueValidator);
|
|
||||||
|
|
||||||
module.exports = mongoose.model('Tag', TagSchema);
|
|
||||||
@@ -10,9 +10,6 @@ exports.QcmCategory = require('./QcmCategory');
|
|||||||
exports.QcmQuestion = require('./QcmQuestion');
|
exports.QcmQuestion = require('./QcmQuestion');
|
||||||
exports.QcmChoice = require('./QcmChoice');
|
exports.QcmChoice = require('./QcmChoice');
|
||||||
exports.X2DataLog = require('./X2DataLog');
|
exports.X2DataLog = require('./X2DataLog');
|
||||||
exports.Article = require('./Article');
|
|
||||||
exports.Comment = require('./Comment');
|
|
||||||
exports.Tag = require('./Tag');
|
|
||||||
exports.HWClan = require('./herowars/Clan');
|
exports.HWClan = require('./herowars/Clan');
|
||||||
exports.HWMember = require('./herowars/Member');
|
exports.HWMember = require('./herowars/Member');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user