provider-ize profile service
This commit is contained in:
parent
76e6bee411
commit
ba9fa84407
4 changed files with 51 additions and 39 deletions
|
|
@ -1,38 +1,35 @@
|
|||
const uuid = require('uuid');
|
||||
const ContactDetailsSet = require('../models/ContactDetailsSet');
|
||||
const NymSet = require('../models/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) {
|
||||
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: {
|
||||
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(),
|
||||
});
|
||||
}
|
||||
|
||||
return isNymSet && areContactDetailsSet;
|
||||
}
|
||||
async function setNym(publicKey, nym) {
|
||||
return await NymSet.create({
|
||||
uuid: uuid.v7(),
|
||||
public_key: publicKey,
|
||||
nym: nym,
|
||||
created_at: new Date().toISOString(),
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
setContactDetails,
|
||||
setNym,
|
||||
areProfileDetailsComplete,
|
||||
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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue