check if invite is spent
This commit is contained in:
parent
c8ddd96743
commit
e48def3661
3 changed files with 20 additions and 17 deletions
|
|
@ -54,13 +54,7 @@ router.post('/invited-npub', async (req, res) => {
|
||||||
return res.status(404).render('error', { message: 'Invite not found' });
|
return res.status(404).render('error', { message: 'Invite not found' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const isInviteSpent = await InvitedNpub.findOne({
|
if (appInviteServices.isAppInviteSpent(inviteUuid)) {
|
||||||
where: {
|
|
||||||
app_invite_uuid: inviteUuid
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (isInviteSpent) {
|
|
||||||
return res.status(410).json({ error: 'Invite has already been used.' });
|
return res.status(410).json({ error: 'Invite has already been used.' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,15 +20,9 @@ router.get('/invite/:inviteUuid', async (req, res) => {
|
||||||
return res.status(404).render('error', { message: 'Invite not found' });
|
return res.status(404).render('error', { message: 'Invite not found' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const invite = appInviteServices.getInvite(inviteUuid);
|
const invite = await appInviteServices.getAppInvite(inviteUuid);
|
||||||
|
|
||||||
const isInviteSpent = await InvitedNpub.findOne({
|
if (await appInviteServices.isAppInviteSpent(inviteUuid)) {
|
||||||
where: {
|
|
||||||
app_invite_uuid: inviteUuid
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (isInviteSpent) {
|
|
||||||
return res.render('invite_spent', { invite })
|
return res.render('invite_spent', { invite })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
const AppInvite = require('../models/AppInvite');
|
const AppInvite = require('../models/AppInvite');
|
||||||
|
const InvitedNpub = require('../models/InvitedNpub');
|
||||||
|
|
||||||
async function appInviteExists(inviteUuid) {
|
async function appInviteExists(inviteUuid) {
|
||||||
const invite = await AppInvite.findOne({ where: { uuid: inviteUuid } });
|
const invite = await AppInvite.findOne({ where: { uuid: inviteUuid } });
|
||||||
|
|
@ -8,11 +9,25 @@ async function appInviteExists(inviteUuid) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getInvite(inviteUuid) {
|
async function getAppInvite(inviteUuid) {
|
||||||
const invite = await AppInvite.findOne({ where: { uuid: inviteUuid } });
|
const invite = await AppInvite.findOne({ where: { uuid: inviteUuid } });
|
||||||
return invite;
|
return invite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function isAppInviteSpent(inviteUuid) {
|
||||||
|
const invitedNpub = await InvitedNpub.findOne({
|
||||||
|
where: {
|
||||||
|
app_invite_uuid: inviteUuid
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (invitedNpub) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
exports.appInviteExists = appInviteExists;
|
exports.appInviteExists = appInviteExists;
|
||||||
exports.getInvite = getInvite;
|
exports.getAppInvite = getAppInvite;
|
||||||
|
exports.isAppInviteSpent = isAppInviteSpent;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue