Skip to content

Commit

Permalink
fix: missing vpa mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
williamluke4 committed Nov 28, 2023
1 parent 2b1f405 commit 605b2b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
16 changes: 14 additions & 2 deletions src/server/api/routers/me.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const meRouter = createTRPCRouter({

update: authenticatedProcedure
.input(UserProfileFormSchema)
.mutation(async ({ ctx, input: { vpa: _vpa, ...pi } }) => {
.mutation(async ({ ctx, input: { vpa, ...pi } }) => {
const address = ctx.session?.user?.account.blockchain_address;
if (!address) throw new Error("No user found");
const user = await ctx.kysely
Expand All @@ -54,7 +54,19 @@ export const meRouter = createTRPCRouter({
.set(pi)
.where("user_identifier", "=", user.userId)
.execute();

if (vpa && user.vpa) {
await ctx.kysely
.updateTable("vpa")
.set({ vpa })
.where("linked_account", "=", user.accountId)
.execute();
}
if (vpa && !user.vpa) {
await ctx.kysely
.insertInto("vpa")
.values({ vpa, linked_account: user.accountId })
.execute();
}
return true;
}),
vouchers: authenticatedProcedure.query(async ({ ctx }) => {
Expand Down
8 changes: 1 addition & 7 deletions src/server/api/routers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,7 @@ export const userRouter = createTRPCRouter({
.set(pi)
.where("user_identifier", "=", user.userId)
.execute();
if (vpa) {
await ctx.kysely
.updateTable("vpa")
.set({ vpa })
.where("linked_account", "=", user.accountId)
.execute();
}

return true;
}
),
Expand Down

0 comments on commit 605b2b8

Please sign in to comment.