forked from spacebar/SplatNet-Backend
(untested) seperate db saving to allow for hopefully equipment screen to work. api not implemented currently.
This commit is contained in:
parent
718a20a0cb
commit
ca3b145a0c
5 changed files with 100 additions and 17 deletions
|
|
@ -1,31 +1,24 @@
|
|||
const { Sequelize } = require('sequelize');
|
||||
|
||||
const connection_string = process.env.DB_URL;
|
||||
const options = {
|
||||
const sequelize = new Sequelize(process.env.DB_URL, {
|
||||
dialect: 'postgres',
|
||||
logging: false,
|
||||
pool: { max: 5, min: 0, acquire: 30000, idle: 10000 }
|
||||
};
|
||||
|
||||
const sequelize = new Sequelize(connection_string, options);
|
||||
|
||||
module.exports = {
|
||||
connection: sequelize,
|
||||
connect
|
||||
};
|
||||
|
||||
require('./models/result');
|
||||
require('./models/splatfest_result');
|
||||
});
|
||||
|
||||
async function connect() {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('PostgreSQL connected.');
|
||||
|
||||
await sequelize.sync();
|
||||
await sequelize.sync({ force: true });
|
||||
console.log('PostgreSQL synchronized');
|
||||
} catch (error) {
|
||||
console.error('PostgreSQL connection error:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
connection: sequelize,
|
||||
connect
|
||||
};
|
||||
20
judd/models/equipment.js
Normal file
20
judd/models/equipment.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
const { DataTypes } = require('sequelize');
|
||||
const { connection } = require('../database');
|
||||
|
||||
const Equipment = connection.define('Equipment', {
|
||||
PId: {
|
||||
type: DataTypes.BIGINT,
|
||||
allowNull: false
|
||||
},
|
||||
weapon: {
|
||||
type: DataTypes.INTEGER
|
||||
},
|
||||
sumpaint: {
|
||||
type: DataTypes.INTEGER
|
||||
}
|
||||
}, {
|
||||
tableName: 'equipment',
|
||||
timestamps: true
|
||||
});
|
||||
|
||||
module.exports = { Equipment };
|
||||
34
judd/models/equipmentLast.js
Normal file
34
judd/models/equipmentLast.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
const { DataTypes } = require('sequelize');
|
||||
const { connection } = require('../database');
|
||||
|
||||
const EquipmentLast = connection.define('EquipmentLast', {
|
||||
PId: {
|
||||
type: DataTypes.BIGINT,
|
||||
allowNull: false,
|
||||
unique: true
|
||||
},
|
||||
weapon: { type: DataTypes.INTEGER },
|
||||
// shoes
|
||||
Gear_Shoes: { type: DataTypes.INTEGER },
|
||||
Gear_Shoes_Skill0: { type: DataTypes.INTEGER },
|
||||
Gear_Shoes_Skill1: { type: DataTypes.INTEGER },
|
||||
Gear_Shoes_Skill2: { type: DataTypes.INTEGER },
|
||||
// clothes
|
||||
Gear_Clothes: { type: DataTypes.INTEGER },
|
||||
Gear_Clothes_Skill0: { type: DataTypes.INTEGER },
|
||||
Gear_Clothes_Skill1: { type: DataTypes.INTEGER },
|
||||
Gear_Clothes_Skill2: { type: DataTypes.INTEGER },
|
||||
// hat
|
||||
Gear_Head: { type: DataTypes.INTEGER },
|
||||
Gear_Head_Skill0: { type: DataTypes.INTEGER },
|
||||
Gear_Head_Skill1: { type: DataTypes.INTEGER },
|
||||
Gear_Head_Skill2: { type: DataTypes.INTEGER },
|
||||
// levels
|
||||
Rank: { type: DataTypes.INTEGER },
|
||||
Udemae: { type: DataTypes.INTEGER }
|
||||
}, {
|
||||
tableName: 'equipment_last',
|
||||
timestamps: true
|
||||
});
|
||||
|
||||
module.exports = { EquipmentLast };
|
||||
|
|
@ -8,6 +8,9 @@ const validateBOSSDigestMiddleware = require('./middleware/validate-boss-digest'
|
|||
const copyRequestStreamMiddleware = require('./middleware/copy-request-stream');
|
||||
const validateMultipartMiddleware = require('./middleware/validate-multipart');
|
||||
const database = require('./database');
|
||||
require('./models/splatfest_result');
|
||||
require('./models/equipment');
|
||||
require('./models/equipmentLast');
|
||||
|
||||
const app = express();
|
||||
app.set('trust proxy', true);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,43 @@
|
|||
const multer = require('multer');
|
||||
const { joi } = require('../util');
|
||||
const { SplatfestResult } = require('../models/splatfest_result');
|
||||
const { Equipment } = require('../models/equipment');
|
||||
const { EquipmentLast } = require('../models/equipmentLast');
|
||||
|
||||
module.exports = {
|
||||
type: 'telemetry',
|
||||
result_model: SplatfestResult,
|
||||
result_model: {
|
||||
create: async (data) => {
|
||||
const result = await SplatfestResult.create(data);
|
||||
|
||||
await Equipment.create({
|
||||
PId: data.PId,
|
||||
weapon: data.Weapon,
|
||||
sumpaint: data.SumPaint
|
||||
});
|
||||
|
||||
await EquipmentLast.upsert({
|
||||
PId: data.PId,
|
||||
weapon: data.Weapon,
|
||||
Gear_Shoes: data.Gear_Shoes,
|
||||
Gear_Shoes_Skill0: data.Gear_Shoes_Skill0,
|
||||
Gear_Shoes_Skill1: data.Gear_Shoes_Skill1,
|
||||
Gear_Shoes_Skill2: data.Gear_Shoes_Skill2,
|
||||
Gear_Clothes: data.Gear_Clothes,
|
||||
Gear_Clothes_Skill0: data.Gear_Clothes_Skill0,
|
||||
Gear_Clothes_Skill1: data.Gear_Clothes_Skill1,
|
||||
Gear_Clothes_Skill2: data.Gear_Clothes_Skill2,
|
||||
Gear_Head: data.Gear_Head,
|
||||
Gear_Head_Skill0: data.Gear_Head_Skill0,
|
||||
Gear_Head_Skill1: data.Gear_Head_Skill1,
|
||||
Gear_Head_Skill2: data.Gear_Head_Skill2,
|
||||
Rank: data.Rank,
|
||||
Udemae: data.Udemae
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
},
|
||||
validation_schema: joi.object({
|
||||
ServerEnv: joi.string(),
|
||||
PId: joi.numberstring(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue