Renaming database primary key
This commit is contained in:
@@ -11,7 +11,7 @@ const { accounts } = require('../database/models');
|
|||||||
const route = async (req, res) => {
|
const route = async (req, res) => {
|
||||||
const account = await accounts.findOne({
|
const account = await accounts.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: req.user.id
|
index: req.user.index
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ const route = async (req, res) => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
where: {
|
where: {
|
||||||
id: req.user.id
|
index: req.user.index
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const { accounts } = require('../database/models');
|
|||||||
const route = async (req, res) => {
|
const route = async (req, res) => {
|
||||||
const account = await accounts.findOne({
|
const account = await accounts.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: req.user.id
|
index: req.user.index
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const route = async (req, res) => {
|
|||||||
hash: hash
|
hash: hash
|
||||||
}, {
|
}, {
|
||||||
where: {
|
where: {
|
||||||
id: req.user.id
|
index: req.user.index
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ const route = async (req, res) => {
|
|||||||
//cancel deletion if any
|
//cancel deletion if any
|
||||||
await accounts.update({ deletion: null }, {
|
await accounts.update({ deletion: null }, {
|
||||||
where: {
|
where: {
|
||||||
id: account.id
|
index: account.index
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ const route = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//generate the JWT
|
//generate the JWT
|
||||||
const tokens = generate(account.id, account.username, account.type, account.admin, account.mod);
|
const tokens = generate(account.index, account.username, account.type, account.admin, account.mod);
|
||||||
|
|
||||||
//finally
|
//finally
|
||||||
res.status(200).json(tokens);
|
res.status(200).json(tokens);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const Sequelize = require('sequelize');
|
|||||||
const sequelize = require('..');
|
const sequelize = require('..');
|
||||||
|
|
||||||
module.exports = sequelize.define('accounts', {
|
module.exports = sequelize.define('accounts', {
|
||||||
id: {
|
index: {
|
||||||
type: Sequelize.INTEGER(11),
|
type: Sequelize.INTEGER(11),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
autoIncrement: true,
|
autoIncrement: true,
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ const sequelize = require('..');
|
|||||||
|
|
||||||
module.exports = sequelize.define('tokens', {
|
module.exports = sequelize.define('tokens', {
|
||||||
token: 'varchar(320)',
|
token: 'varchar(320)',
|
||||||
username: 'varchar(320)'
|
username: 'varchar(320)' //TODO: why username?
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ const jwt = require('jsonwebtoken');
|
|||||||
const { tokens } = require('../database/models');
|
const { tokens } = require('../database/models');
|
||||||
|
|
||||||
//generates a JWT token based on the given arguments
|
//generates a JWT token based on the given arguments
|
||||||
module.exports = (id, username, type, admin, mod) => {
|
module.exports = (index, username, type, admin, mod) => {
|
||||||
const content = {
|
const content = {
|
||||||
id,
|
index,
|
||||||
username,
|
username,
|
||||||
type,
|
type,
|
||||||
admin,
|
admin,
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ module.exports = (token, callback) => {
|
|||||||
return callback(403);
|
return callback(403);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = generate(user.id, user.username, user.type, user.admin, user.mod);
|
const result = generate(user.index, user.username, user.type, user.admin, user.mod);
|
||||||
|
|
||||||
destroy(token);
|
destroy(token);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user