Reworked middleware to work with new models
This commit is contained in:
parent
98c4f879c5
commit
bc324d2488
3 changed files with 18 additions and 19 deletions
|
|
@ -7,13 +7,13 @@ async function GetOrg(req, res, next) {
|
|||
const result = await Organization.findByPk(orgID, {
|
||||
include: [
|
||||
{
|
||||
association: 'orgOwner',
|
||||
where: { userID: user.userID },
|
||||
association: 'owner',
|
||||
where: { id: user.id },
|
||||
required: false,
|
||||
},
|
||||
{
|
||||
association: 'orgMember',
|
||||
where: { userID: user.userID },
|
||||
association: 'member',
|
||||
where: { id: user.id },
|
||||
required: false,
|
||||
},
|
||||
],
|
||||
|
|
@ -23,7 +23,7 @@ async function GetOrg(req, res, next) {
|
|||
return res.status(500).send('There is no organization with this id.');
|
||||
}
|
||||
|
||||
if (!result.orgOwner && result.orgMember.length == 0) {
|
||||
if (!result.owner && result.member.length == 0) {
|
||||
return res
|
||||
.status(403)
|
||||
.send('You do not know any organizations with this id.');
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ async function checkKnownUser(req, res, next) {
|
|||
const user = req.user;
|
||||
const userID = req.params.userID || req.query.userID || req.body.userID;
|
||||
|
||||
if (user.userID == userID) {
|
||||
if (user.id == userID) {
|
||||
return next();
|
||||
}
|
||||
|
||||
|
|
@ -13,21 +13,21 @@ async function checkKnownUser(req, res, next) {
|
|||
{
|
||||
association: 'ownedOrg',
|
||||
include: {
|
||||
association: 'orgMember',
|
||||
where: { userID: user.userID },
|
||||
association: 'member',
|
||||
where: { id: user.id },
|
||||
},
|
||||
},
|
||||
{
|
||||
association: 'memberOrgs',
|
||||
association: 'memberOrg',
|
||||
include: [
|
||||
{
|
||||
association: 'orgMember',
|
||||
where: { userID: user.userID },
|
||||
association: 'owner',
|
||||
where: { id: user.id },
|
||||
required: false,
|
||||
},
|
||||
{
|
||||
association: 'orgOwner',
|
||||
where: { userID: user.userID },
|
||||
association: 'member',
|
||||
where: { id: user.id },
|
||||
required: false,
|
||||
},
|
||||
],
|
||||
|
|
@ -39,8 +39,8 @@ async function checkKnownUser(req, res, next) {
|
|||
return res.status(500).send('No user with that ID exists.');
|
||||
}
|
||||
|
||||
const filteredResult = result.memberOrgs.filter(
|
||||
(org) => org.orgMembers.length != 0 || org_owner
|
||||
const filteredResult = result.memberOrg.filter(
|
||||
(org) => org.member.length != 0 || org.owner
|
||||
);
|
||||
|
||||
if (filteredResult.length == 0 && result.ownedOrg) {
|
||||
|
|
|
|||
|
|
@ -7,17 +7,16 @@ async function tokenAuth(req, res, next) {
|
|||
return res.status(403).send('Unauthorized user');
|
||||
}
|
||||
|
||||
const result = await Token.findOne({
|
||||
where: { tokenID: token },
|
||||
});
|
||||
const result = await Token.findByPk(token);
|
||||
|
||||
const date = new Date();
|
||||
|
||||
if (
|
||||
!result ||
|
||||
(token.expires == true &&
|
||||
date.setDate(date.getDate + 1) > result.createdAt)
|
||||
) {
|
||||
await Token.destroy({ where: { tokenID: token } });
|
||||
await Token.destroy({ where: { id: token } });
|
||||
return res.status(511).send('Session expired');
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue