From b4bd150d9388700dfc951bdff1d48a67e6abe081 Mon Sep 17 00:00:00 2001 From: counterweight Date: Mon, 10 Feb 2025 01:42:46 +0100 Subject: [PATCH] all serviced --- src/routes/apiRoutes.js | 10 +--------- src/services/sessionService.js | 8 ++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/routes/apiRoutes.js b/src/routes/apiRoutes.js index 0861498..55a3e01 100644 --- a/src/routes/apiRoutes.js +++ b/src/routes/apiRoutes.js @@ -1,7 +1,4 @@ const express = require('express'); -const uuid = require("uuid"); - -const SessionNpubbed = require('../models/SessionNpubbed'); const appInviteService = require('../services/appInviteService'); const invitedNpubService = require('../services/invitedNpubService'); @@ -18,12 +15,7 @@ router.post('/session-npubbed', async (req, res) => { } try { - const existingRecord = await SessionNpubbed.findOne({ - where: { 'session_uuid': sessionUuid, npub } - }); - - if (existingRecord) { - console.log("Record already exists. No need to create a new one."); + if (await sessionService.isSessionAlreadyRelatedToNpub(sessionUuid, npub)) { return res.json({ message: 'SessionNpubbed record already exists' }); } console.log("No matching record found. Creating a new one..."); diff --git a/src/services/sessionService.js b/src/services/sessionService.js index 2c23fa3..a3b652d 100644 --- a/src/services/sessionService.js +++ b/src/services/sessionService.js @@ -19,5 +19,13 @@ async function relateSessionToNpub(sessionUuid, npub) { }); } +async function isSessionAlreadyRelatedToNpub(sessionUuid, npub) { + if (await SessionNpubbed.findOne({ where: { 'session_uuid': sessionUuid, npub } })) { + return true; + } + return false; +} + exports.createSession = createSession; exports.relateSessionToNpub = relateSessionToNpub; +exports.isSessionAlreadyRelatedToNpub = isSessionAlreadyRelatedToNpub;