From 0ac18c08beb4148e50b075cae30a0559973a7d91 Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Wed, 27 Dec 2023 17:17:47 -0700 Subject: [PATCH] show tenant name in user list --- app/user.go | 1 + assets/data/api/tenants.ts | 2 ++ assets/data/types/user.ts | 1 + assets/pages/admin/users.svelte | 11 +++++++++++ db/user.go | 8 ++++++-- 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/user.go b/app/user.go index c69a530..70e2627 100644 --- a/app/user.go +++ b/app/user.go @@ -28,6 +28,7 @@ type User struct { Email string AvatarURL string Role string + TenantID string LastLoginAt *time.Time CreatedAt time.Time UpdatedAt time.Time diff --git a/assets/data/api/tenants.ts b/assets/data/api/tenants.ts index 6b34681..6595325 100644 --- a/assets/data/api/tenants.ts +++ b/assets/data/api/tenants.ts @@ -1,6 +1,8 @@ import type {Tenant, TenantCreate, TenantUserCreate} from 'data/types/tenant' import api from '../api' +// TODO: cache tenant list + export const addTenant = async (name: string): Promise => { const body: TenantCreate = { Name: name, diff --git a/assets/data/types/user.ts b/assets/data/types/user.ts index 6617330..4ed7317 100644 --- a/assets/data/types/user.ts +++ b/assets/data/types/user.ts @@ -8,6 +8,7 @@ export type User = { UpdatedAt: string //date LastName: string Role: string + TenantID: string } export const isAdmin = (user: User) => user.Role == Admin diff --git a/assets/pages/admin/users.svelte b/assets/pages/admin/users.svelte index a9a5653..eca3b5c 100644 --- a/assets/pages/admin/users.svelte +++ b/assets/pages/admin/users.svelte @@ -1,14 +1,23 @@

Users

@@ -16,6 +25,7 @@ + @@ -27,6 +37,7 @@ {#each users as user (user.ID)} + diff --git a/db/user.go b/db/user.go index f23fa23..735a6e0 100644 --- a/db/user.go +++ b/db/user.go @@ -123,7 +123,7 @@ func findUserByID(ctx echo.Context, id string) (User, error) { } func ConvertUser(_ echo.Context, u User) (app.User, error) { - return app.User{ + user := app.User{ ID: u.ID, FirstName: u.FirstName, LastName: u.LastName, @@ -133,5 +133,9 @@ func ConvertUser(_ echo.Context, u User) (app.User, error) { LastLoginAt: u.LastLoginAt, CreatedAt: u.CreatedAt, UpdatedAt: u.UpdatedAt, - }, nil + } + if u.TenantID != nil { + user.TenantID = *u.TenantID + } + return user, nil }
RoleTenant First Name Last Name Email
{user.Role}{getTenantNameFromID(user.TenantID)} {user.FirstName} {user.LastName} {user.Email}