merge services
This commit is contained in:
parent
2b6853bf11
commit
ea91107347
4 changed files with 37 additions and 43 deletions
|
|
@ -1,33 +0,0 @@
|
|||
const uuid = require("uuid");
|
||||
|
||||
const PublicKeySignedUp = require('../models/PublicKeySignedUp');
|
||||
|
||||
const invitesService = require('./invitesService');
|
||||
|
||||
async function signUpPublicKey(inviteUuid, publicKey) {
|
||||
|
||||
if (await invitesService.isAppInviteSpent(inviteUuid)) {
|
||||
throw new Error("Can't invite npub, invite is already spent.");
|
||||
}
|
||||
|
||||
await PublicKeySignedUp.create({
|
||||
uuid: uuid.v7(),
|
||||
app_invite_uuid: inviteUuid,
|
||||
public_key: publicKey,
|
||||
created_at: new Date().toISOString()
|
||||
});
|
||||
}
|
||||
|
||||
async function isPublicKeySignedUp(publicKey) {
|
||||
|
||||
if (await PublicKeySignedUp.findOne({
|
||||
where: { public_key: publicKey }
|
||||
})) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
exports.signUpPublicKey = signUpPublicKey;
|
||||
exports.isPublicKeySignedUp = isPublicKeySignedUp;
|
||||
|
|
@ -38,8 +38,36 @@ async function createAppInvite(inviterNpub) {
|
|||
);
|
||||
}
|
||||
|
||||
async function signUpPublicKey(inviteUuid, publicKey) {
|
||||
|
||||
exports.appInviteExists = appInviteExists;
|
||||
exports.getAppInvite = getAppInvite;
|
||||
exports.isAppInviteSpent = isAppInviteSpent;
|
||||
exports.createAppInvite = createAppInvite;
|
||||
if (await isAppInviteSpent(inviteUuid)) {
|
||||
throw new Error("Can't invite npub, invite is already spent.");
|
||||
}
|
||||
|
||||
await PublicKeySignedUp.create({
|
||||
uuid: uuid.v7(),
|
||||
app_invite_uuid: inviteUuid,
|
||||
public_key: publicKey,
|
||||
created_at: new Date().toISOString()
|
||||
});
|
||||
}
|
||||
|
||||
async function isPublicKeySignedUp(publicKey) {
|
||||
|
||||
if (await PublicKeySignedUp.findOne({
|
||||
where: { public_key: publicKey }
|
||||
})) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
appInviteExists,
|
||||
getAppInvite,
|
||||
isAppInviteSpent,
|
||||
createAppInvite,
|
||||
signUpPublicKey,
|
||||
isPublicKeySignedUp
|
||||
};
|
||||
|
|
@ -3,7 +3,7 @@ const uuid = require("uuid");
|
|||
const SessionCreated = require('../models/SessionCreated');
|
||||
const SessionNpubbed = require('../models/SessionNpubbed');
|
||||
|
||||
const PublicKeySignedUpService = require('./PublicKeySignedUpService');
|
||||
const invitesService = require('./invitesService');
|
||||
|
||||
const constants = require('../constants');
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ async function isSessionAuthorized(sessionUuid) {
|
|||
|
||||
const npub = await getNpubRelatedToSession(sessionUuid);
|
||||
|
||||
if (await PublicKeySignedUpService.isPublicKeySignedUp(npub)) {
|
||||
if (await invitesService.isPublicKeySignedUp(npub)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue