a lot of renames
This commit is contained in:
parent
966fde1111
commit
619503e799
9 changed files with 80 additions and 73 deletions
|
|
@ -1,33 +0,0 @@
|
|||
const uuid = require("uuid");
|
||||
|
||||
const PublicKeyInvited = require('../models/PublicKeyInvited');
|
||||
|
||||
const appInviteService = require('./appInviteService');
|
||||
|
||||
async function createPublicKeyInvite(inviteUuid, publicKey) {
|
||||
|
||||
if (await appInviteService.isAppInviteSpent(inviteUuid)) {
|
||||
throw new Error("Can't invite npub, invite is already spent.");
|
||||
}
|
||||
|
||||
await PublicKeyInvited.create({
|
||||
uuid: uuid.v7(),
|
||||
app_invite_uuid: inviteUuid,
|
||||
public_key_invited: publicKey,
|
||||
created_at: new Date().toISOString()
|
||||
});
|
||||
}
|
||||
|
||||
async function isPublicKeyInvited(publicKey) {
|
||||
|
||||
if (await PublicKeyInvited.findOne({
|
||||
where: { public_key_invited: publicKey }
|
||||
})) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
exports.createPublicKeyInvite = createPublicKeyInvite;
|
||||
exports.isPublicKeyInvited = isPublicKeyInvited;
|
||||
33
src/services/PublicKeySignedUpService.js
Normal file
33
src/services/PublicKeySignedUpService.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
const uuid = require("uuid");
|
||||
|
||||
const PublicKeySignedUp = require('../models/PublicKeySignedUp');
|
||||
|
||||
const appInviteService = require('./appInviteService');
|
||||
|
||||
async function signUpPublicKey(inviteUuid, publicKey) {
|
||||
|
||||
if (await appInviteService.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;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
const uuid = require('uuid');
|
||||
|
||||
const AppInviteCreated = require('../models/AppInviteCreated');
|
||||
const PublicKeyInvited = require('../models/PublicKeyInvited');
|
||||
const PublicKeySignedUp = require('../models/PublicKeySignedUp');
|
||||
|
||||
async function appInviteExists(inviteUuid) {
|
||||
const invite = await AppInviteCreated.findOne({ where: { uuid: inviteUuid } });
|
||||
|
|
@ -17,7 +17,7 @@ async function getAppInvite(inviteUuid) {
|
|||
}
|
||||
|
||||
async function isAppInviteSpent(inviteUuid) {
|
||||
const invitedNpub = await PublicKeyInvited.findOne({
|
||||
const invitedNpub = await PublicKeySignedUp.findOne({
|
||||
where: {
|
||||
app_invite_uuid: inviteUuid
|
||||
}
|
||||
|
|
@ -30,7 +30,7 @@ async function isAppInviteSpent(inviteUuid) {
|
|||
}
|
||||
|
||||
async function createAppInvite(inviterNpub) {
|
||||
await AppInviteCreated.create({
|
||||
return await AppInviteCreated.create({
|
||||
uuid: uuid.v7(),
|
||||
inviter_npub: inviterNpub,
|
||||
created_at: new Date().toISOString()
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ const uuid = require("uuid");
|
|||
const SessionCreated = require('../models/SessionCreated');
|
||||
const SessionNpubbed = require('../models/SessionNpubbed');
|
||||
|
||||
const invitedNpubService = require('./PublicKeyInvitedService');
|
||||
const PublicKeySignedUpService = require('./PublicKeySignedUpService');
|
||||
|
||||
const constants = require('../constants');
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ async function isSessionAuthorized(sessionUuid) {
|
|||
|
||||
const npub = await getNpubRelatedToSession(sessionUuid);
|
||||
|
||||
if (await invitedNpubService.isNpubInvited(npub)) {
|
||||
if (await PublicKeySignedUpService.isPublicKeySignedUp(npub)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue