diff --git a/src/middlewares/redirectIfMissingProfileDetailsMiddleware.js b/src/middlewares/redirectIfMissingProfileDetailsMiddleware.js index 090bc31..934048d 100644 --- a/src/middlewares/redirectIfMissingProfileDetailsMiddleware.js +++ b/src/middlewares/redirectIfMissingProfileDetailsMiddleware.js @@ -1,7 +1,4 @@ -const profileServiceProvider = require('../services/profileService'); -const ContactDetailsSet = require('../models/ContactDetailsSet'); -const NymSet = require('../models/NymSet'); -const profileService = profileServiceProvider(ContactDetailsSet, NymSet); +const profileService = require('../services/profileService'); async function redirectIfMissingProfileDetailsMiddleware(req, res, next) { const publicKey = req.cookies.publicKey; diff --git a/src/routes/apiRoutes.js b/src/routes/apiRoutes.js index 7bfebb0..fc2ad86 100644 --- a/src/routes/apiRoutes.js +++ b/src/routes/apiRoutes.js @@ -4,14 +4,10 @@ const invitesService = require('../services/invitesService'); const nostrService = require('../services/nostrService'); const loginService = require('../services/loginService'); const sessionService = require('../services/sessionService'); -const profileServiceProvider = require('../services/profileService'); +const profileService = require('../services/profileService'); const offerService = require('../services/offerService'); const errors = require('../errors'); -const ContactDetailsSet = require('../models/ContactDetailsSet'); -const NymSet = require('../models/NymSet'); -const profileService = profileServiceProvider(ContactDetailsSet, NymSet); - const router = express.Router(); class ApiRoutesProvider { diff --git a/src/services/profileService.js b/src/services/profileService.js index 2ea84c8..358499c 100644 --- a/src/services/profileService.js +++ b/src/services/profileService.js @@ -1,35 +1,34 @@ const uuid = require('uuid'); +const ContactDetailsSet = require('../models/ContactDetailsSet'); +const NymSet = require('../models/NymSet'); -const profileServicesProvider = (ContactDetailsSet, NymSet) => { - async function setContactDetails(publicKey, encryptedContactDetails) { - return await ContactDetailsSet.create({ - uuid: uuid.v7(), +async function setContactDetails(publicKey, encryptedContactDetails) { + return await ContactDetailsSet.create({ + uuid: uuid.v7(), + public_key: publicKey, + encrypted_contact_details: encryptedContactDetails, + created_at: new Date().toISOString(), + }); +} + +async function setNym(publicKey, nym) { + return await NymSet.create({ + uuid: uuid.v7(), + public_key: publicKey, + nym: nym, + created_at: new Date().toISOString(), + }); +} + +async function areProfileDetailsComplete(publicKey) { + const isNymSet = await NymSet.findOne({ where: { public_key: publicKey } }); + const areContactDetailsSet = await ContactDetailsSet.findOne({ + where: { public_key: publicKey, - encrypted_contact_details: encryptedContactDetails, - created_at: new Date().toISOString(), - }); - } + }, + }); - async function setNym(publicKey, nym) { - return await NymSet.create({ - uuid: uuid.v7(), - public_key: publicKey, - nym: nym, - created_at: new Date().toISOString(), - }); - } + return isNymSet && areContactDetailsSet; +} - async function areProfileDetailsComplete(publicKey) { - const isNymSet = await NymSet.findOne({ where: { public_key: publicKey } }); - const areContactDetailsSet = await ContactDetailsSet.findOne({ - where: { - public_key: publicKey, - }, - }); - - return isNymSet && areContactDetailsSet; - } - - return { setContactDetails, setNym, areProfileDetailsComplete }; -}; -module.exports = profileServicesProvider; +module.exports = { setContactDetails, setNym, areProfileDetailsComplete };