db tx
This commit is contained in:
parent
a8c30afcdd
commit
139cf1d3c9
2 changed files with 23 additions and 32 deletions
|
|
@ -192,7 +192,7 @@ export default class {
|
||||||
const user = await this.storage.applicationStorage.GetApplicationUser(app, req.user_identifier)
|
const user = await this.storage.applicationStorage.GetApplicationUser(app, req.user_identifier)
|
||||||
return this.paymentManager.GetLnurlPayInfoFromUser(user.user.user_id, app, req.base_url_override)
|
return this.paymentManager.GetLnurlPayInfoFromUser(user.user.user_id, app, req.base_url_override)
|
||||||
}
|
}
|
||||||
async RequestNsecLinkingToken(appId: string, req: Types.RequestNPubLinkingTokenRequest): Promise<Types.RequestNPubLinkingTokenResponse> {
|
async RequestNPubLinkingToken(appId: string, req: Types.RequestNPubLinkingTokenRequest): Promise<Types.RequestNPubLinkingTokenResponse> {
|
||||||
const app = await this.storage.applicationStorage.GetApplication(appId);
|
const app = await this.storage.applicationStorage.GetApplication(appId);
|
||||||
const user = await this.storage.applicationStorage.GetApplicationUser(app, req.user_identifier);
|
const user = await this.storage.applicationStorage.GetApplicationUser(app, req.user_identifier);
|
||||||
if (Array.from(this.nPubLinkingTokens.values()).find(t => t.serialId === user.serial_id)) {
|
if (Array.from(this.nPubLinkingTokens.values()).find(t => t.serialId === user.serial_id)) {
|
||||||
|
|
@ -208,32 +208,27 @@ export default class {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async LinkNpubThroughToken(appId: string, appUserId: string, req: Types.LinkNPubThroughTokenRequest): Promise<void> {
|
async LinkNpubThroughToken(ctx: Types.UserContext, req: Types.LinkNPubThroughTokenRequest): Promise<void> {
|
||||||
|
const { app_id: appId, app_user_id: appUserId } = ctx
|
||||||
const app = await this.storage.applicationStorage.GetApplication(appId)
|
const app = await this.storage.applicationStorage.GetApplication(appId)
|
||||||
const appUser = await this.storage.applicationStorage.GetApplicationUser(app, appUserId)
|
const appUser = await this.storage.applicationStorage.GetApplicationUser(app, appUserId)
|
||||||
|
this.storage.txQueue.PushToQueue({
|
||||||
/*
|
dbTx: true,
|
||||||
needs to be a db tx, otherwise gets foreign constraint error when deleting baseUser after
|
exec: async tx => {
|
||||||
applicationUser, and unique constatin when giving targetted applicationUser the npub
|
await this.storage.applicationStorage.RemoveApplicationUserAndBaseUser(appUser, tx);
|
||||||
*/
|
const entry = this.nPubLinkingTokens.get(req.token)
|
||||||
this.storage.DB.transaction(async tx => {
|
if (entry && entry.expiry > Date.now()) {
|
||||||
await this.storage.applicationStorage.RemoveApplicationUserAndBaseUser(appUser, tx);
|
const copy = { ...entry }
|
||||||
|
const deleted = this.nPubLinkingTokens.delete(req.token)
|
||||||
const entry = this.nPubLinkingTokens.get(req.token)
|
if (deleted) {
|
||||||
if (entry && entry.expiry > Date.now()) {
|
await this.storage.applicationStorage.AddNPubToApplicationUser(copy.serialId, req.nostr_pub, tx)
|
||||||
const copy = { ...entry }
|
} else {
|
||||||
const deleted = this.nPubLinkingTokens.delete(req.token)
|
throw new Error("An uknown error occured")
|
||||||
if (deleted) {
|
}
|
||||||
await this.storage.applicationStorage.AddNPubToApplicationUser(copy.serialId, req.nostr_pub, tx)
|
} else {
|
||||||
} else {
|
throw new Error("Token invalid or expired")
|
||||||
throw new Error("An uknown error occured")
|
}
|
||||||
}
|
}
|
||||||
} else {
|
})
|
||||||
throw new Error("Token invalid or expired")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -205,7 +205,7 @@ export default (mainHandler: Main): Types.ServerMethods => {
|
||||||
user_identifier_CustomCheck: userIdentifier => userIdentifier !== '',
|
user_identifier_CustomCheck: userIdentifier => userIdentifier !== '',
|
||||||
})
|
})
|
||||||
if (err != null) throw new Error(err.message)
|
if (err != null) throw new Error(err.message)
|
||||||
return mainHandler.applicationManager.RequestNsecLinkingToken(ctx.app_id, req)
|
return mainHandler.applicationManager.RequestNPubLinkingToken(ctx.app_id, req)
|
||||||
},
|
},
|
||||||
LinkNPubThroughToken: async ({ ctx, req }) => {
|
LinkNPubThroughToken: async ({ ctx, req }) => {
|
||||||
const err = Types.LinkNPubThroughTokenRequestValidate(req, {
|
const err = Types.LinkNPubThroughTokenRequestValidate(req, {
|
||||||
|
|
@ -213,11 +213,7 @@ export default (mainHandler: Main): Types.ServerMethods => {
|
||||||
token_CustomCheck: token => token !== ''
|
token_CustomCheck: token => token !== ''
|
||||||
})
|
})
|
||||||
if (err != null) throw new Error(err.message)
|
if (err != null) throw new Error(err.message)
|
||||||
|
return mainHandler.applicationManager.LinkNpubThroughToken(ctx, req)
|
||||||
|
|
||||||
|
|
||||||
return mainHandler.applicationManager.LinkNpubThroughToken(ctx.app_id, ctx.app_user_id, req)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue