profile service
This commit is contained in:
parent
42fea55233
commit
ec725f8e4e
4 changed files with 16 additions and 18 deletions
|
|
@ -148,7 +148,6 @@ class ApiRoutesProvider {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (error instanceof this.errors.ForbiddenError) {
|
if (error instanceof this.errors.ForbiddenError) {
|
||||||
console.log('helo?1');
|
|
||||||
return res.status(403).json({
|
return res.status(403).json({
|
||||||
success: false,
|
success: false,
|
||||||
message: 'This public key is not authorized.',
|
message: 'This public key is not authorized.',
|
||||||
|
|
@ -160,8 +159,7 @@ class ApiRoutesProvider {
|
||||||
message: 'Unexpected error.',
|
message: 'Unexpected error.',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log('helo?2');
|
|
||||||
console.log(completedLoginChallenge);
|
|
||||||
await this.services.sessionService.relateSessionToPublicKey(
|
await this.services.sessionService.relateSessionToPublicKey(
|
||||||
sessionUuid,
|
sessionUuid,
|
||||||
completedLoginChallenge.public_key
|
completedLoginChallenge.public_key
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ class ServicesProvider {
|
||||||
}).provide();
|
}).provide();
|
||||||
|
|
||||||
const ProfileServiceProvider = require('../services/profileService');
|
const ProfileServiceProvider = require('../services/profileService');
|
||||||
const profileService = new ProfileServiceProvider().provide();
|
const profileService = new ProfileServiceProvider({ models }).provide();
|
||||||
const OfferServiceProvider = require('../services/offerService');
|
const OfferServiceProvider = require('../services/offerService');
|
||||||
const offerService = new OfferServiceProvider().provide();
|
const offerService = new OfferServiceProvider().provide();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ class LoginServiceProvider {
|
||||||
completedNostrChallenge.public_key
|
completedNostrChallenge.public_key
|
||||||
))
|
))
|
||||||
) {
|
) {
|
||||||
console.log('helo4');
|
|
||||||
throw new this.errors.ForbiddenError(
|
throw new this.errors.ForbiddenError(
|
||||||
`Public key ${completedNostrChallenge.public_key} is not authorized.`
|
`Public key ${completedNostrChallenge.public_key} is not authorized.`
|
||||||
);
|
);
|
||||||
|
|
@ -53,9 +52,6 @@ class LoginServiceProvider {
|
||||||
created_at: new Date().toISOString(),
|
created_at: new Date().toISOString(),
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('helo3');
|
|
||||||
console.log(completedLoginChallenge);
|
|
||||||
|
|
||||||
return completedLoginChallenge;
|
return completedLoginChallenge;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,37 +3,41 @@ const uuid = require('uuid');
|
||||||
const models = require('../models');
|
const models = require('../models');
|
||||||
|
|
||||||
class ProfileServiceProvider {
|
class ProfileServiceProvider {
|
||||||
|
constructor({ models }) {
|
||||||
|
this.models = models;
|
||||||
|
}
|
||||||
provide() {
|
provide() {
|
||||||
async function setContactDetails(publicKey, encryptedContactDetails) {
|
const setContactDetails = async (publicKey, encryptedContactDetails) => {
|
||||||
return await models.ContactDetailsSet.create({
|
return await this.models.ContactDetailsSet.create({
|
||||||
uuid: uuid.v7(),
|
uuid: uuid.v7(),
|
||||||
public_key: publicKey,
|
public_key: publicKey,
|
||||||
encrypted_contact_details: encryptedContactDetails,
|
encrypted_contact_details: encryptedContactDetails,
|
||||||
created_at: new Date().toISOString(),
|
created_at: new Date().toISOString(),
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
async function setNym(publicKey, nym) {
|
const setNym = async (publicKey, nym) => {
|
||||||
return await models.NymSet.create({
|
return await this.models.NymSet.create({
|
||||||
uuid: uuid.v7(),
|
uuid: uuid.v7(),
|
||||||
public_key: publicKey,
|
public_key: publicKey,
|
||||||
nym: nym,
|
nym: nym,
|
||||||
created_at: new Date().toISOString(),
|
created_at: new Date().toISOString(),
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
async function areProfileDetailsComplete(publicKey) {
|
const areProfileDetailsComplete = async (publicKey) => {
|
||||||
const isNymSet = await models.NymSet.findOne({
|
console.log(this.models);
|
||||||
|
const isNymSet = await this.models.NymSet.findOne({
|
||||||
where: { public_key: publicKey },
|
where: { public_key: publicKey },
|
||||||
});
|
});
|
||||||
const areContactDetailsSet = await models.ContactDetailsSet.findOne({
|
const areContactDetailsSet = await this.models.ContactDetailsSet.findOne({
|
||||||
where: {
|
where: {
|
||||||
public_key: publicKey,
|
public_key: publicKey,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return isNymSet && areContactDetailsSet;
|
return isNymSet && areContactDetailsSet;
|
||||||
}
|
};
|
||||||
|
|
||||||
return { setContactDetails, setNym, areProfileDetailsComplete };
|
return { setContactDetails, setNym, areProfileDetailsComplete };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue