~sircmpwn/sr.ht-dev

meta.sr.ht: api: fix webhooks being called with outdated data v1 APPLIED

Conrad Hoffmann: 1
 api: fix webhooks being called with outdated data

 1 files changed, 3 insertions(+), 2 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/34433/mbox | git am -3
Learn more about email & git

[PATCH meta.sr.ht] api: fix webhooks being called with outdated data Export this patch

When a user updates their profile, the database gets updated
accordingly, but the webhooks get called with data retrieved before the
update.

Make the update statement return the new values and apply them to the
user object that gets passed to the webhooks.
---
 api/graph/schema.resolvers.go | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/api/graph/schema.resolvers.go b/api/graph/schema.resolvers.go
index d81a4ba..5c2ed91 100644
--- a/api/graph/schema.resolvers.go
+++ b/api/graph/schema.resolvers.go
@@ -121,13 +121,14 @@ func (r *mutationResolver) UpdateUser(ctx context.Context, input map[string]inte
		var err error

		if len(input) != 0 {
			_, err = query.
			err = query.
				Where(database.WithAlias(user.Alias(), `id`)+"= ?",
					auth.ForContext(ctx).UserID).
				Set(database.WithAlias(user.Alias(), `updated`),
					sq.Expr(`now() at time zone 'utc'`)).
				Suffix(`RETURNING url, location, bio`).
				RunWith(tx).
				ExecContext(ctx)
				ScanContext(ctx, &user.URL, &user.Location, &user.Bio)
			if err != nil {
				return err
			}
-- 
2.37.1
Thanks!

To git@git.sr.ht:~sircmpwn/meta.sr.ht
   085a966..9d9fed0  master -> master