diff --git a/src/routes/apiRoutes.js b/src/routes/apiRoutes.js index f97ae1a..b93b1f0 100644 --- a/src/routes/apiRoutes.js +++ b/src/routes/apiRoutes.js @@ -148,7 +148,6 @@ class ApiRoutesProvider { }); } if (error instanceof this.errors.ForbiddenError) { - console.log('helo?1'); return res.status(403).json({ success: false, message: 'This public key is not authorized.', @@ -160,8 +159,7 @@ class ApiRoutesProvider { message: 'Unexpected error.', }); } - console.log('helo?2'); - console.log(completedLoginChallenge); + await this.services.sessionService.relateSessionToPublicKey( sessionUuid, completedLoginChallenge.public_key diff --git a/src/services/index.js b/src/services/index.js index bf41899..f71ab58 100644 --- a/src/services/index.js +++ b/src/services/index.js @@ -43,7 +43,7 @@ class ServicesProvider { }).provide(); const ProfileServiceProvider = require('../services/profileService'); - const profileService = new ProfileServiceProvider().provide(); + const profileService = new ProfileServiceProvider({ models }).provide(); const OfferServiceProvider = require('../services/offerService'); const offerService = new OfferServiceProvider().provide(); diff --git a/src/services/loginService.js b/src/services/loginService.js index b4e74cd..73a0b58 100644 --- a/src/services/loginService.js +++ b/src/services/loginService.js @@ -39,7 +39,6 @@ class LoginServiceProvider { completedNostrChallenge.public_key )) ) { - console.log('helo4'); throw new this.errors.ForbiddenError( `Public key ${completedNostrChallenge.public_key} is not authorized.` ); @@ -53,9 +52,6 @@ class LoginServiceProvider { created_at: new Date().toISOString(), }); - console.log('helo3'); - console.log(completedLoginChallenge); - return completedLoginChallenge; }; diff --git a/src/services/profileService.js b/src/services/profileService.js index 34bcd6f..391d953 100644 --- a/src/services/profileService.js +++ b/src/services/profileService.js @@ -3,37 +3,41 @@ const uuid = require('uuid'); const models = require('../models'); class ProfileServiceProvider { + constructor({ models }) { + this.models = models; + } provide() { - async function setContactDetails(publicKey, encryptedContactDetails) { - return await models.ContactDetailsSet.create({ + const setContactDetails = async (publicKey, encryptedContactDetails) => { + return await this.models.ContactDetailsSet.create({ uuid: uuid.v7(), public_key: publicKey, encrypted_contact_details: encryptedContactDetails, created_at: new Date().toISOString(), }); - } + }; - async function setNym(publicKey, nym) { - return await models.NymSet.create({ + const setNym = async (publicKey, nym) => { + return await this.models.NymSet.create({ uuid: uuid.v7(), public_key: publicKey, nym: nym, created_at: new Date().toISOString(), }); - } + }; - async function areProfileDetailsComplete(publicKey) { - const isNymSet = await models.NymSet.findOne({ + const areProfileDetailsComplete = async (publicKey) => { + console.log(this.models); + const isNymSet = await this.models.NymSet.findOne({ where: { public_key: publicKey }, }); - const areContactDetailsSet = await models.ContactDetailsSet.findOne({ + const areContactDetailsSet = await this.models.ContactDetailsSet.findOne({ where: { public_key: publicKey, }, }); return isNymSet && areContactDetailsSet; - } + }; return { setContactDetails, setNym, areProfileDetailsComplete }; }