Refactoring et ajout de routes Hero Wars

This commit is contained in:
2025-11-27 10:50:17 +01:00
parent c9ce3f343e
commit 60feffd929
47 changed files with 1224 additions and 236 deletions
@@ -0,0 +1,55 @@
var mongoose = require('mongoose');
var uniqueValidator = require('mongoose-unique-validator');
var HWClanSchema = new mongoose.Schema({
id: { type: String, unique: true },
country: String,
description: String,
disbanding: Boolean,
frameId: Number,
icon: {
flagColor1: Number,
flagColor2: Number,
flagShape: Number,
iconColor: Number,
iconShape: Number,
},
level: String,
members: [{ type: mongoose.Schema.Types.ObjectId, ref: 'HWMember' }],
membersCount: Number,
minLevel: String,
ownerId: String,
/*roleNames: { type: mongoose.Schema.Types.ObjectId, ref: 'HWClanRoles' },*/
serverId: String,
title: String,
topActivity: String,
topDungeon: String,
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }
}, {timestamps: true, toJSON: {virtuals: true}});
HWClanSchema.plugin(uniqueValidator, { message: 'is already taken' });
HWClanSchema.methods.toJSONFor = function() {
return {
id: this.id,
country: this.country,
description: this.description,
disbanding: this.disbanding,
frameId: this.frameId,
icon: this.icon,
level: this.level,
members: this.members,
membersCount: this.membersCount,
minLevel: this.minLevel,
ownerId: this.ownerId,
serverId: this.serverId,
title: this.title,
topActivity: this.topActivity,
topDungeon: this.topDungeon,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
author: this.author.toJSONFor()
};
};
mongoose.model('HWClan', HWClanSchema);
@@ -0,0 +1,22 @@
var mongoose = require('mongoose');
var uniqueValidator = require('mongoose-unique-validator');
var HWClanRolesSchema = new mongoose.Schema({
member: String,
officer: String,
owner: String,
warlorld: String
}, {timestamps: false, toJSON: {virtuals: true}});
HWClanRolesSchema.plugin(uniqueValidator, { message: 'is already taken' });
HWClanRolesSchema.methods.toJSONFor = function() {
return {
member: this.member,
officer: this.officer,
owner: this.owner,
warlorld: this.warlorld
};
};
mongoose.model('HWClanRoles', HWClanRolesSchema);
@@ -0,0 +1,135 @@
var mongoose = require('mongoose');
var uniqueValidator = require('mongoose-unique-validator');
/*
var HWMemberSchemaOld = new mongoose.Schema({
id: { type: String, lowercase: true, unique: true },
name: String,
lastLoginTime: String,
serverId: String,
level: String,
clanId: String,
clanRole: String,
commander: Boolean,
avatarId: String,
isChatModerator: Boolean,
frameId: Number,
leagueId: Number,
clanTitle: String,
champion: Boolean,
stat: {
activitySum: Number,
todayActivity: Number,
dungeonActivitySum: Number,
todayDungeonActivity: Number,
raidSum: Number,
wasChampion: Boolean,
todayPrestige: Number,
prestigeSum: Number,
},
inactivity: {
daysLeft: Number,
timeLeft: Number,
dropDate: Number,
dropDelay: String,
},
adventureSum: Number,
clanGiftsSum: Number,
clanWarSum: Number,
weekStat: {
activity: [Number],
dungeonActivity: [Number],
adventureStat: [Number],
clanWarStat: [Number],
prestigeStat: [Number],
clanGifts: [Number],
},
score: Number,
scoreGifts: Number,
warGifts: Number,
rewards: Number,
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }
}, {timestamps: true, toJSON: {virtuals: true}});
*/
var HWMemberSchema = new mongoose.Schema({
id: { type: String, unique: true },
allowPm: String,
avatarId: String,
clanIcon: {
flagColor1: Number,
flagColor2: Number,
flagShape: Number,
iconColor: Number,
iconShape: Number,
},
clanId: String,
clanRole: String,
clanTitle: String,
commander: Boolean,
frameId: Number,
isChatModerator: Boolean,
lastLoginTime: String,
leagueId: Number,
level: String,
name: String,
serverId: String,
champion: Boolean,
stat: {
activitySum: Number,
todayActivity: Number,
dungeonActivitySum: Number,
todayDungeonActivity: Number,
raidSum: Number,
wasChampion: Boolean,
todayPrestige: Number,
prestigeSum: Number,
},
inactivity: {
daysLeft: Number,
timeLeft: Number,
dropDate: Number,
dropDelay: String,
},
adventureSum: Number,
clanGiftsSum: Number,
clanWarSum: Number,
weekStat: {
activity: [Number],
dungeonActivity: [Number],
adventureStat: [Number],
clanWarStat: [Number],
prestigeStat: [Number],
clanGifts: [Number],
},
score: Number,
scoreGifts: Number,
warGifts: Number,
rewards: Number,
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }
}, {timestamps: true, toJSON: {virtuals: true}});
HWMemberSchema.plugin(uniqueValidator, { message: 'is already taken' });
HWMemberSchema.methods.toJSONFor = function() {
return {
id: this.id,
allowPm: this.allowPm,
avatarId: this.avatarId,
clanIcon: this.clanIcon,
clanId: this.clanId,
clanRole: this.clanRole,
clanTitle: this.clanTitle,
commander: this.commander,
frameId: this.frameId,
isChatModerator: this.isChatModerator,
lastLoginTime: this.lastLoginTime,
leagueId: this.leagueId,
level: this.level,
name: this.name,
serverId: this.serverId,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
author: this.author.toJSONFor()
};
};
mongoose.model('HWMember', HWMemberSchema);
@@ -0,0 +1 @@
exports.HWMember = require('./Member');
+2
View File
@@ -13,4 +13,6 @@ exports.X2DataLog = require('./X2DataLog');
exports.Article = require('./Article');
exports.Comment = require('./Comment');
exports.Tag = require('./Tag');
exports.HWClan = require('./herowars/Clan');
exports.HWMember = require('./herowars/Member');
+18 -2
View File
@@ -1,24 +1,40 @@
var DataTypes = require("sequelize").DataTypes;
const sequelize = require('./config/sequelize');
const ArticleModel = require('./models/mysql/Article');
const ArticleTageModel = require('./models/mysql/ArticleTag');
//const ArticleTageModel = require('./models/mysql/ArticleTag');
const BrandModel = require('./models/mysql/Brand');
const CategoryModel = require('./models/mysql/Category');
const CommentModel = require('./models/mysql/Comment');
const FavoriteModel = require('./models/mysql/Favorite');
const FollowerModel = require('./models/mysql/Follower');
const PackagingModel = require('./models/mysql/Packaging');
const ProductModel = require('./models/mysql/Product');
const ProductCategoryXrefModel = require('./models/mysql/ProductCategoryXref');
const ProductTagXrefModel = require('./models/mysql/ProductTagXref');
const RoleModel = require('./models/mysql/Role');
const TagModel = require('./models/mysql/Tag');
const TagListModel = require('./models/mysql/TagList');
const UserModel = require('./models/mysql/User');
const UserRoleXrefModel = require('./models/mysql/UserRoleXref');
const DB = {
sequelize,
User: UserModel(sequelize, DataTypes),
Article: ArticleModel(sequelize, DataTypes),
ArticleTag: ArticleTageModel(sequelize, DataTypes),
//ArticleTag: ArticleTageModel(sequelize, DataTypes),
Brand: BrandModel(sequelize, DataTypes),
Category: CategoryModel(sequelize, DataTypes),
Comment: CommentModel(sequelize, DataTypes),
Favorite: FavoriteModel(sequelize, DataTypes),
Follower: FollowerModel(sequelize, DataTypes),
Packaging: PackagingModel(sequelize, DataTypes),
Product: ProductModel(sequelize, DataTypes),
ProductCategoryXref: ProductCategoryXrefModel(sequelize, DataTypes),
ProductTagXref: ProductTagXrefModel(sequelize, DataTypes),
Role: RoleModel(sequelize, DataTypes),
Tag: TagModel(sequelize, DataTypes),
TagList: TagListModel(sequelize, DataTypes),
UserRoleXref: UserRoleXrefModel(sequelize, DataTypes),
};
module.exports = DB;
+57 -57
View File
@@ -1,69 +1,69 @@
const DB = require('../mysql');
const associate = () => {
/*
DB.User.hasMany(DB.Article, {
foreignKey: 'authorId',
onDelete: "CASCADE"
});
DB.Article.belongsTo(DB.User, {
foreignKey: 'authorId',
as: 'author',
});
*/
DB.Article.belongsToMany(DB.Tag, { as: 'tagNameTags', through: DB.ArticleTag, foreignKey: "articleId", otherKey: "tagName" });
DB.Article.belongsToMany(DB.Tag, { as: 'tagNameTagTagLists', through: DB.TagList, foreignKey: "articleId", otherKey: "tagName" });
DB.Article.belongsToMany(DB.Tag, { as: 'articleTags', through: DB.TagList, foreignKey: "articleId", otherKey: "tagName" });
DB.Article.belongsToMany(DB.User, { as: 'userIdUsers', through: DB.Favorite, foreignKey: "articleId", otherKey: "userId" });
DB.Tag.belongsToMany(DB.Article, { as: 'articleIdArticles', through: DB.ArticleTag, foreignKey: "tagName", otherKey: "articleId" });
DB.Category.belongsToMany(DB.Product, { as: 'productIdProducts', through: DB.ProductCategoryXref, foreignKey: "categoryId", otherKey: "productId" });
DB.Product.belongsToMany(DB.Category, { as: 'productCategories', through: DB.ProductCategoryXref, foreignKey: "productId", otherKey: "categoryId" });
DB.Product.belongsToMany(DB.Tag, { as: 'productTags', through: DB.ProductTagXref, foreignKey: "productId", otherKey: "tagName" });
DB.Role.belongsToMany(DB.User, { as: 'userIdUserUserRoleXrefs', through: DB.UserRoleXref, foreignKey: "roleId", otherKey: "userId" });
DB.Tag.belongsToMany(DB.Article, { as: 'articleIdArticleTagLists', through: DB.TagList, foreignKey: "tagName", otherKey: "articleId" });
DB.User.belongsToMany(DB.Article, { as: 'articleIdArticleFavorites', through: DB.Favorite, foreignKey: "userId", otherKey: "articleId" });
DB.Tag.belongsToMany(DB.Product, { as: 'productIdProductProductTagXrefs', through: DB.ProductTagXref, foreignKey: "tagName", otherKey: "productId" });
DB.User.belongsToMany(DB.Article, { as: 'articleIdArticles', through: DB.Favorite, foreignKey: "userId", otherKey: "articleId" });
DB.User.belongsToMany(DB.Role, { as: 'roleIdRoles', through: DB.UserRoleXref, foreignKey: "userId", otherKey: "roleId" });
DB.User.belongsToMany(DB.User, { as: 'followerIdUsers', through: DB.Follower, foreignKey: "userId", otherKey: "followerId" });
DB.User.belongsToMany(DB.User, { as: 'userIdUserFollowers', through: DB.Follower, foreignKey: "followerId", otherKey: "userId" });
DB.ArticleTag.belongsTo(DB.Article, { as: "article", foreignKey: "articleId" });
DB.Article.hasMany(DB.ArticleTag, { as: "articleTags", foreignKey: "articleId" });
DB.Comment.belongsTo(DB.Article, { as: "article", foreignKey: "articleId" });
DB.Article.hasMany(DB.Comment, { as: "comments", foreignKey: "articleId" });
DB.Favorite.belongsTo(DB.Article, { as: "article", foreignKey: "articleId" });
DB.Article.hasMany(DB.Favorite, { as: "favorites", foreignKey: "articleId" });
DB.TagList.belongsTo(DB.Article, { as: "article", foreignKey: "articleId" });
DB.Article.hasMany(DB.TagList, { as: "tagLists", foreignKey: "articleId" });
DB.ArticleTag.belongsTo(DB.Tag, { as: "tagNameTag", foreignKey: "tagName" });
DB.Tag.hasMany(DB.ArticleTag, { as: "articleTags", foreignKey: "tagName" });
DB.TagList.belongsTo(DB.Tag, { as: "tagNameTag", foreignKey: "tagName" });
DB.Tag.hasMany(DB.TagList, { as: "tagLists", foreignKey: "tagName" });
DB.Article.belongsTo(DB.User, { as: "author", foreignKey: "authorId" });
DB.User.hasMany(DB.Article, { as: "articles", foreignKey: "authorId" });
DB.Comment.belongsTo(DB.User, { as: "author", foreignKey: "authorId" });
DB.User.hasMany(DB.Comment, { as: "comments", foreignKey: "authorId" });
DB.Favorite.belongsTo(DB.User, { as: "user", foreignKey: "userId" });
DB.User.hasMany(DB.Favorite, { as: "favorites", foreignKey: "userId" });
DB.Follower.belongsTo(DB.User, { as: "user", foreignKey: "userId" });
DB.User.hasMany(DB.Follower, { as: "followers", foreignKey: "userId" });
DB.Follower.belongsTo(DB.User, { as: "follower", foreignKey: "followerId" });
DB.User.hasMany(DB.Follower, { as: "followerFollowers", foreignKey: "followerId" });
DB.Comment.belongsTo(DB.Article, { as: "article", foreignKey: "articleId"});
DB.Article.hasMany(DB.Comment, { as: "comments", foreignKey: "articleId"});
DB.Favorite.belongsTo(DB.Article, { as: "article", foreignKey: "articleId"});
DB.Article.hasMany(DB.Favorite, { as: "favorites", foreignKey: "articleId"});
DB.TagList.belongsTo(DB.Article, { as: "article", foreignKey: "articleId"});
DB.Article.hasMany(DB.TagList, { as: "tagLists", foreignKey: "articleId"});
DB.Product.belongsTo(DB.Brand, { as: "brand", foreignKey: "brandId"});
DB.Brand.hasMany(DB.Product, { as: "products", foreignKey: "brandId"});
DB.ProductCategoryXref.belongsTo(DB.Category, { as: "category", foreignKey: "categoryId"});
DB.Category.hasMany(DB.ProductCategoryXref, { as: "productCategoryXrefs", foreignKey: "categoryId"});
DB.Product.belongsTo(DB.Packaging, { as: "packaging", foreignKey: "packagingId"});
DB.Packaging.hasMany(DB.Product, { as: "products", foreignKey: "packagingId"});
DB.ProductCategoryXref.belongsTo(DB.Product, { as: "product", foreignKey: "productId"});
DB.Product.hasMany(DB.ProductCategoryXref, { as: "productCategoryXrefs", foreignKey: "productId"});
DB.ProductTagXref.belongsTo(DB.Product, { as: "product", foreignKey: "productId"});
DB.Product.hasMany(DB.ProductTagXref, { as: "productTagXrefs", foreignKey: "productId"});
DB.UserRoleXref.belongsTo(DB.Role, { as: "role", foreignKey: "roleId"});
DB.Role.hasMany(DB.UserRoleXref, { as: "userRoleXrefs", foreignKey: "roleId"});
DB.ProductTagXref.belongsTo(DB.Tag, { as: "tagNameTag", foreignKey: "tagName"});
DB.Tag.hasMany(DB.ProductTagXref, { as: "productTagXrefs", foreignKey: "tagName"});
DB.TagList.belongsTo(DB.Tag, { as: "tagNameTag", foreignKey: "tagName"});
DB.Tag.hasMany(DB.TagList, { as: "tagLists", foreignKey: "tagName"});
DB.Article.belongsTo(DB.User, { as: "author", foreignKey: "authorId"});
DB.User.hasMany(DB.Article, { as: "articles", foreignKey: "authorId"});
DB.Comment.belongsTo(DB.User, { as: "author", foreignKey: "authorId"});
DB.User.hasMany(DB.Comment, { as: "comments", foreignKey: "authorId"});
DB.Favorite.belongsTo(DB.User, { as: "user", foreignKey: "userId"});
DB.User.hasMany(DB.Favorite, { as: "favorites", foreignKey: "userId"});
DB.Follower.belongsTo(DB.User, { as: "user", foreignKey: "userId"});
DB.User.hasMany(DB.Follower, { as: "followers", foreignKey: "userId"});
DB.Follower.belongsTo(DB.User, { as: "follower", foreignKey: "followerId"});
DB.User.hasMany(DB.Follower, { as: "followerFollowers", foreignKey: "followerId"});
DB.Product.belongsTo(DB.User, { as: "owner", foreignKey: "ownerId"});
DB.User.hasMany(DB.Product, { as: "products", foreignKey: "ownerId"});
DB.UserRoleXref.belongsTo(DB.User, { as: "user", foreignKey: "userId"});
DB.User.hasMany(DB.UserRoleXref, { as: "userRoleXrefs", foreignKey: "userId"});
/*
// Relations
DB.User.belongsToMany(DB.User, { as: "followers", through: "Followers", foreignKey: "userId", timestamps: false });
DB.User.belongsToMany(DB.User, { as: "following", through: "Followers", foreignKey: "followerId", timestamps: false });
DB.User.hasMany(DB.Article, { foreignKey: "authorId", onDelete: "CASCADE" });
DB.Article.belongsTo(DB.User, { as: "author", foreignKey: "authorId" });
DB.User.hasMany(DB.Comment, { foreignKey: "authorId", onDelete: "CASCADE" });
DB.Comment.belongsTo(DB.User, { as: "author", foreignKey: "authorId" });
DB.Article.hasMany(DB.Comment, { foreignKey: "articleId", onDelete: "CASCADE" });
DB.Comment.belongsTo(DB.Article, { foreignKey: "articleId" });
DB.User.belongsToMany(DB.Article, { as: "favorites", through: "Favorites", timestamps: false });
DB.Article.belongsToMany(DB.User, { through: "Favorites", foreignKey: "articleId", timestamps: false });
DB.Article.belongsToMany(DB.Tag, { through: "TagLists", as: "tagLists", foreignKey: "articleId", timestamps: false, onDelete: "CASCADE" });
DB.Tag.belongsToMany(DB.Article, { through: "ArticleTags", uniqueKey: false, timestamps: false });
// Relations
DB.User.belongsToMany(DB.User, { as: "followers", through: "Followers", foreignKey: "userId", timestamps: false });
DB.User.belongsToMany(DB.User, { as: "following", through: "Followers", foreignKey: "followerId", timestamps: false });
DB.User.hasMany(DB.Article, { foreignKey: "authorId", onDelete: "CASCADE" });
DB.Article.belongsTo(DB.User, { as: "author", foreignKey: "authorId" });
DB.User.hasMany(DB.Comment, { foreignKey: "authorId", onDelete: "CASCADE" });
DB.Comment.belongsTo(DB.User, { as: "author", foreignKey: "authorId" });
DB.Article.hasMany(DB.Comment, { foreignKey: "articleId", onDelete: "CASCADE" });
DB.Comment.belongsTo(DB.Article, { foreignKey: "articleId" });
DB.User.belongsToMany(DB.Article, { as: "favorites", through: "Favorites", timestamps: false });
DB.Article.belongsToMany(DB.User, { through: "Favorites", foreignKey: "articleId", timestamps: false });
DB.Article.belongsToMany(DB.Tag, { through: "TagLists", as: "tagLists", foreignKey: "articleId", timestamps: false, onDelete: "CASCADE" });
DB.Tag.belongsToMany(DB.Article, { through: "ArticleTags", uniqueKey: false, timestamps: false });
*/
};
module.exports = associate;