provider-ize profile service
This commit is contained in:
parent
76e6bee411
commit
ba9fa84407
4 changed files with 51 additions and 39 deletions
18
src/app.js
18
src/app.js
|
|
@ -1,8 +1,15 @@
|
|||
function createApp() {
|
||||
const express = require('express');
|
||||
const cookieParser = require('cookie-parser');
|
||||
const path = require('path');
|
||||
const express = require('express');
|
||||
const cookieParser = require('cookie-parser');
|
||||
const path = require('path');
|
||||
|
||||
function buildDependencies() {
|
||||
const dependencies = {};
|
||||
|
||||
dependencies.sequelize = require('./database');
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
function createApp(dependencies) {
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
|
|
@ -32,7 +39,8 @@ function createApp() {
|
|||
return app;
|
||||
}
|
||||
|
||||
const app = createApp();
|
||||
const dependencies = buildDependencies();
|
||||
const app = createApp(dependencies);
|
||||
app.listen(app.get('port'), () => {
|
||||
console.log(`Server started on port ${app.get('port')}`);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
const profileService = require('../services/profileService');
|
||||
const profileServiceProvider = require('../services/profileService');
|
||||
const ContactDetailsSet = require('../models/ContactDetailsSet');
|
||||
const NymSet = require('../models/NymSet');
|
||||
const profileService = profileServiceProvider(ContactDetailsSet, NymSet);
|
||||
|
||||
async function redirectIfMissingProfileDetailsMiddleware(req, res, next) {
|
||||
const publicKey = req.cookies.publicKey;
|
||||
|
|
|
|||
|
|
@ -4,12 +4,16 @@ const invitesService = require('../services/invitesService');
|
|||
const nostrService = require('../services/nostrService');
|
||||
const loginService = require('../services/loginService');
|
||||
const sessionService = require('../services/sessionService');
|
||||
const profileService = require('../services/profileService');
|
||||
const profileServiceProvider = require('../services/profileService');
|
||||
const offerService = require('../services/offerService');
|
||||
const errors = require('../errors');
|
||||
const attachPublicKeyMiddleware = require('../middlewares/attachPublicKeyMiddleware');
|
||||
const rejectIfNotAuthorizedMiddleware = require('../middlewares/rejectIfNotAuthorizedMiddleware');
|
||||
|
||||
const ContactDetailsSet = require('../models/ContactDetailsSet');
|
||||
const NymSet = require('../models/NymSet');
|
||||
const profileService = profileServiceProvider(ContactDetailsSet, NymSet);
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.get('/signup/nostr-challenge', async (req, res) => {
|
||||
|
|
|
|||
|
|
@ -1,26 +1,25 @@
|
|||
const uuid = require('uuid');
|
||||
const ContactDetailsSet = require('../models/ContactDetailsSet');
|
||||
const NymSet = require('../models/NymSet');
|
||||
|
||||
async function setContactDetails(publicKey, encryptedContactDetails) {
|
||||
const profileServicesProvider = (ContactDetailsSet, NymSet) => {
|
||||
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) {
|
||||
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) {
|
||||
async function areProfileDetailsComplete(publicKey) {
|
||||
const isNymSet = await NymSet.findOne({ where: { public_key: publicKey } });
|
||||
const areContactDetailsSet = await ContactDetailsSet.findOne({
|
||||
where: {
|
||||
|
|
@ -29,10 +28,8 @@ async function areProfileDetailsComplete(publicKey) {
|
|||
});
|
||||
|
||||
return isNymSet && areContactDetailsSet;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
setContactDetails,
|
||||
setNym,
|
||||
areProfileDetailsComplete,
|
||||
return { setContactDetails, setNym, areProfileDetailsComplete };
|
||||
};
|
||||
module.exports = profileServicesProvider;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue