mirror of
https://github.com/ION606/selmerBot.git
synced 2026-06-06 07:12:58 +00:00
Adding the base for the currency system
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
const Sequelize = require('sequelize');
|
||||
|
||||
/*
|
||||
* Make sure you are on at least version 5 of Sequelize! Version 4 as used in this guide will pose a security threat.
|
||||
* You can read more about this issue on the [Sequelize issue tracker](https://github.com/sequelize/sequelize/issues/7310).
|
||||
*/
|
||||
|
||||
const sequelize = new Sequelize('database', 'username', 'password', {
|
||||
host: 'localhost',
|
||||
dialect: 'sqlite',
|
||||
logging: false,
|
||||
storage: 'database.sqlite',
|
||||
});
|
||||
|
||||
const Users = require('./models/Users.js')(sequelize, Sequelize.DataTypes);
|
||||
const CurrencyShop = require('./models/CurrencyShop.js')(sequelize, Sequelize.DataTypes);
|
||||
const UserItems = require('./models/UserItems.js')(sequelize, Sequelize.DataTypes);
|
||||
|
||||
UserItems.belongsTo(CurrencyShop, { foreignKey: 'item_id', as: 'item' });
|
||||
|
||||
Reflect.defineProperty(Users.prototype, 'addItem', {
|
||||
/* eslint-disable-next-line func-name-matching */
|
||||
value: async function addItem(item) {
|
||||
const userItem = await UserItems.findOne({
|
||||
where: { user_id: this.user_id, item_id: item.id },
|
||||
});
|
||||
|
||||
if (userItem) {
|
||||
userItem.amount += 1;
|
||||
return userItem.save();
|
||||
}
|
||||
|
||||
return UserItems.create({ user_id: this.user_id, item_id: item.id, amount: 1 });
|
||||
},
|
||||
});
|
||||
|
||||
Reflect.defineProperty(Users.prototype, 'getItems', {
|
||||
/* eslint-disable-next-line func-name-matching */
|
||||
value: function getItems() {
|
||||
return UserItems.findAll({
|
||||
where: { user_id: this.user_id },
|
||||
include: ['item'],
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = { Users, CurrencyShop, UserItems };
|
||||
Reference in New Issue
Block a user