use service
This commit is contained in:
parent
c9e76bbfd6
commit
c8ddd96743
4 changed files with 25 additions and 16 deletions
|
|
@ -1,11 +0,0 @@
|
||||||
const AppInvite = require('../models/AppInvite');
|
|
||||||
|
|
||||||
async function inviteExists(inviteUuid) {
|
|
||||||
const invite = await AppInvite.findOne({ where: { uuid: inviteUuid } });
|
|
||||||
if (invite) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.inviteExists = inviteExists;
|
|
||||||
|
|
@ -5,7 +5,7 @@ const SessionNpubbed = require('../models/SessionNpubbed');
|
||||||
const InvitedNpub = require('../models/InvitedNpub');
|
const InvitedNpub = require('../models/InvitedNpub');
|
||||||
|
|
||||||
|
|
||||||
const inviteController = require('../controllers/inviteControllers')
|
const appInviteServices = require('../services/appInviteServices')
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
|
|
@ -50,7 +50,7 @@ router.post('/invited-npub', async (req, res) => {
|
||||||
const inviteUuid = req.cookies.inviteUuid;
|
const inviteUuid = req.cookies.inviteUuid;
|
||||||
const npub = req.body.npub;
|
const npub = req.body.npub;
|
||||||
|
|
||||||
if (!inviteController.inviteExists(inviteUuid)) {
|
if (!appInviteServices.appInviteExists(inviteUuid)) {
|
||||||
return res.status(404).render('error', { message: 'Invite not found' });
|
return res.status(404).render('error', { message: 'Invite not found' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
const AppInvite = require('../models/AppInvite');
|
|
||||||
const InvitedNpub = require('../models/InvitedNpub');
|
const InvitedNpub = require('../models/InvitedNpub');
|
||||||
|
|
||||||
|
const appInviteServices = require('../services/appInviteServices')
|
||||||
|
|
||||||
router.get('/', (req, res) => {
|
router.get('/', (req, res) => {
|
||||||
res.render('index', { uuid: req.cookies.sessionUuid });
|
res.render('index', { uuid: req.cookies.sessionUuid });
|
||||||
});
|
});
|
||||||
|
|
@ -14,12 +15,13 @@ router.get('/invite/:inviteUuid', async (req, res) => {
|
||||||
res.cookie('inviteUuid', inviteUuid, { httpOnly: true, maxAge: 86400000 });
|
res.cookie('inviteUuid', inviteUuid, { httpOnly: true, maxAge: 86400000 });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const invite = await AppInvite.findOne({ where: { uuid: inviteUuid } });
|
|
||||||
|
|
||||||
if (!invite) {
|
if (!appInviteServices.appInviteExists(inviteUuid)) {
|
||||||
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 isInviteSpent = await InvitedNpub.findOne({
|
const isInviteSpent = await InvitedNpub.findOne({
|
||||||
where: {
|
where: {
|
||||||
app_invite_uuid: inviteUuid
|
app_invite_uuid: inviteUuid
|
||||||
|
|
|
||||||
18
src/services/appInviteServices.js
Normal file
18
src/services/appInviteServices.js
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
const AppInvite = require('../models/AppInvite');
|
||||||
|
|
||||||
|
async function appInviteExists(inviteUuid) {
|
||||||
|
const invite = await AppInvite.findOne({ where: { uuid: inviteUuid } });
|
||||||
|
if (invite) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getInvite(inviteUuid) {
|
||||||
|
const invite = await AppInvite.findOne({ where: { uuid: inviteUuid } });
|
||||||
|
return invite;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
exports.appInviteExists = appInviteExists;
|
||||||
|
exports.getInvite = getInvite;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue