Skip to content

Commit

Permalink
Merge pull request #69 from versx/v5-support
Browse files Browse the repository at this point in the history
WhMgr v5 support
  • Loading branch information
versx authored Jan 24, 2022
2 parents 2e0faa4 + 4685af0 commit 2c41061
Show file tree
Hide file tree
Showing 26 changed files with 673 additions and 455 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "whmgr-ui",
"version": "1.13.0",
"version": "1.2.0",
"description": "",
"main": "src/index.js",
"scripts": {
Expand Down
10 changes: 5 additions & 5 deletions src/data/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ const getInvasionTypes = () => {

const getLureTypes = () => {
return [
{ name: 'Normal' },
{ name: 'Glacial' },
{ name: 'Mossy' },
{ name: 'Magnetic' },
{ name: 'Rainy' },
{ id: 501, name: 'Normal' },
{ id: 502, name: 'Glacial' },
{ id: 503, name: 'Mossy' },
{ id: 504, name: 'Magnetic' },
{ id: 505, name: 'Rainy' },
];
};

Expand Down
10 changes: 6 additions & 4 deletions src/models/gym.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const { DataTypes, Model, } = require('sequelize');
const sequelize = require('../services/sequelize.js')(true);
const { parseJsonColumn } = require('../services/utils.js');

class Gym extends Model {

Expand Down Expand Up @@ -100,14 +101,15 @@ Gym.init({
pokemonIds: {
type: DataTypes.JSON,
defaultValue: null,
//defaultValue: '[]',
get() {
var data = this.getDataValue('pokemonIds');
return Array.isArray(data)
? data
: JSON.parse(data || '[]');
return parseJsonColumn(data);
},
},
exEligible: {
type: DataTypes.BOOLEAN,
defaultValue: false,
},
location: {
type: DataTypes.STRING(32),
defaultValue: null,
Expand Down
33 changes: 15 additions & 18 deletions src/models/invasion.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const { DataTypes, Model, } = require('sequelize');
const sequelize = require('../services/sequelize.js')(true);
const { parseJsonColumn } = require('../services/utils.js');

class Invasion extends Model {

Expand All @@ -14,16 +15,6 @@ class Invasion extends Model {
});
}

static async create(invasions) {
if (invasions.length === 0) {
return;
}
const results = await Invasion.bulkCreate(invasions, {
updateOnDuplicate: Invasion.fromInvasionFields,
});
console.log('[Invasion] Results:', results);
}

static getAll(guildId, userId) {
return Invasion.findAll({
where: {
Expand Down Expand Up @@ -102,22 +93,28 @@ Invasion.init({
//unique: true,
},
gruntType: {
type: DataTypes.INTEGER(2).UNSIGNED,
allowNull: true,
type: DataTypes.JSON,
defaultValue: null,
get() {
var data = this.getDataValue('gruntType');
return parseJsonColumn(data);
},
},
rewardPokemonId: {
type: DataTypes.TEXT(),
type: DataTypes.JSON,
defaultValue: null,
get() {
var data = this.getDataValue('rewardPokemonId');
return parseJsonColumn(data);
},
},
city: {
areas: {
type: DataTypes.JSON,
allowNull: false,
defaultValue: '[]',
get() {
var data = this.getDataValue('city');
return Array.isArray(data)
? data
: JSON.parse(data || '[]');
var data = this.getDataValue('areas');
return parseJsonColumn(data);
},
},
location: {
Expand Down
17 changes: 10 additions & 7 deletions src/models/lure.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const { DataTypes, Model, } = require('sequelize');
const sequelize = require('../services/sequelize.js')(true);
const { parseJsonColumn } = require('../services/utils.js');

class Lure extends Model {

Expand Down Expand Up @@ -100,18 +101,20 @@ Lure.init({
allowNull: false,
},
lureType: {
type: DataTypes.INTEGER(11).UNSIGNED,
allowNull: false,
type: DataTypes.JSON,
defaultValue: null,
get() {
var data = this.getDataValue('lureType');
return parseJsonColumn(data);
},
},
city: {
areas: {
type: DataTypes.JSON,
allowNull: false,
defaultValue: '[]',
get() {
var data = this.getDataValue('city');
return Array.isArray(data)
? data
: JSON.parse(data || '[]');
var data = this.getDataValue('areas');
return parseJsonColumn(data);
},
},
location: {
Expand Down
46 changes: 46 additions & 0 deletions src/models/metadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';

const { DataTypes, Model, } = require('sequelize');
const sequelize = require('../services/sequelize.js')(true);

class Metadata extends Model {

static create = async (key, value) => await Metadata.create(key, value);

static getAll = () => Metadata.findAll();

static getByKey = (key) => Metadata.findByPk(key);

static async update(key, value) {
await Metadata.upsert({
key: key,
value: value,
});
}

static deleteById(key) {
return Metadata.destroy({
where: { key },
});
}

static deleteAll = () => Metadata.destroy();
}

Metadata.init({
key: {
type: DataTypes.STRING(255),
primaryKey: true,
allowNull: false,
},
value: {
type: DataTypes.TEXT(),
},
}, {
sequelize,
timestamps: false,
underscored: true,
tableName: 'metadata',
});

module.exports = Metadata;
41 changes: 25 additions & 16 deletions src/models/pokemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const { DataTypes, Model, Op, } = require('sequelize');
const sequelize = require('../services/sequelize.js')(true);
const { parseJsonColumn } = require('../services/utils.js');

class Pokemon extends Model {

Expand All @@ -23,14 +24,14 @@ class Pokemon extends Model {
});
}

static getByPokemon(guildId, userId, pokemon, form, iv, ivList, minLevel, maxLevel, gender, size) {
static getByPokemon(guildId, userId, pokemon, forms, iv, ivList, minLevel, maxLevel, gender, size) {
return Pokemon.findOne({
where: {
guildId: guildId,
userId: userId,
pokemonId: pokemon,
form: {
[Op.or]: [null, form],
forms: {
[Op.or]: [null, forms],
},
minIv: iv,
ivList: ivList,
Expand Down Expand Up @@ -84,13 +85,25 @@ Pokemon.init({
allowNull: false,
},
pokemonId: {
type: DataTypes.TEXT(),
type: DataTypes.JSON,
allowNull: false,
get() {
var data = this.getDataValue('pokemonId');
return parseJsonColumn(data);
},
/*
set(val) {
this.setDataValue('city', JSON.stringify(val || []));
}
*/
},
form: {
type: DataTypes.TEXT(),
allowNull: true,
defaultValue: null,
forms: {
type: DataTypes.JSON,
allowNull: false,
get() {
var data = this.getDataValue('forms');
return parseJsonColumn(data);
},
},
minCp: {
type: DataTypes.INTEGER(11),
Expand Down Expand Up @@ -127,25 +140,21 @@ Pokemon.init({
defaultValue: '[]',
get() {
var data = this.getDataValue('ivList');
return Array.isArray(data)
? data
: JSON.parse(data || '[]');
return parseJsonColumn(data);
},
/*
set(val) {
this.setDataValue('iv_list', JSON.stringify(val || []));
}
*/
},
city: {
areas: {
type: DataTypes.JSON,
allowNull: false,
defaultValue: '[]',
get() {
var data = this.getDataValue('city');
return Array.isArray(data)
? data
: JSON.parse(data || '[]');
var data = this.getDataValue('areas');
return parseJsonColumn(data);
},
/*
set(val) {
Expand Down
32 changes: 19 additions & 13 deletions src/models/pvp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const { DataTypes, Model, Op, } = require('sequelize');
const sequelize = require('../services/sequelize.js')(true);
const { parseJsonColumn } = require('../services/utils.js');

class PVP extends Model {

Expand All @@ -23,14 +24,14 @@ class PVP extends Model {
});
}

static getPokemonByLeague(guildId, userId, pokemon, form, league) {
static getPokemonByLeague(guildId, userId, pokemon, forms, league) {
return PVP.findOne({
where: {
guildId: guildId,
userId: userId,
pokemonId: pokemon,
form: {
[Op.or]: [null, form],
forms: {
[Op.or]: [null, forms],
},
league: league,
}
Expand Down Expand Up @@ -99,13 +100,20 @@ PVP.init({
allowNull: false,
},
pokemonId: {
type: DataTypes.TEXT(),
type: DataTypes.JSON,
allowNull: false,
get() {
var data = this.getDataValue('pokemonId');
return parseJsonColumn(data);
},
},
form: {
type: DataTypes.TEXT(),
allowNull: true,
defaultValue: null,
forms: {
type: DataTypes.JSON,
allowNull: false,
get() {
var data = this.getDataValue('forms');
return parseJsonColumn(data);
},
},
minRank: {
type: DataTypes.INTEGER(11),
Expand All @@ -121,15 +129,13 @@ PVP.init({
type: DataTypes.STRING(255),
allowNull: false,
},
city: {
areas: {
type: DataTypes.JSON,
allowNull: false,
defaultValue: '[]',
get() {
var data = this.getDataValue('city');
return Array.isArray(data)
? data
: JSON.parse(data || '[]');
var data = this.getDataValue('areas');
return parseJsonColumn(data);
},
/*
set(val) {
Expand Down
11 changes: 5 additions & 6 deletions src/models/quest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const { DataTypes, Model } = require('sequelize');
const sequelize = require('../services/sequelize.js')(true);
const { parseJsonColumn } = require('../services/utils.js');

class Quest extends Model {

Expand Down Expand Up @@ -104,15 +105,13 @@ Quest.init({
type: DataTypes.TEXT,
allowNull: true,
},
city: {
type: DataTypes.JSONTEXT,
areas: {
type: DataTypes.JSON,
allowNull: false,
defaultValue: '[]',
get() {
const data = this.getDataValue('city');
return Array.isArray(data)
? data
: JSON.parse(data || '[]');
const data = this.getDataValue('areas');
return parseJsonColumn(data);
}
},
location: {
Expand Down
Loading

0 comments on commit 2c41061

Please sign in to comment.