Skip to content

Commit

Permalink
display list of tenant users
Browse files Browse the repository at this point in the history
  • Loading branch information
briskt committed Nov 26, 2023
1 parent b7fde66 commit cdd6bc1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion assets/data/api/users.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {User} from 'data/types/user'
import api from '../api'

export const viewUser = async (id: string): Promise<User> => {
export const getUser = async (id: string): Promise<User> => {
const response = await api.get('/api/users/' + encodeURIComponent(id))
return response.json()
}
Expand Down
10 changes: 6 additions & 4 deletions assets/pages/admin/tenants/[id].svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import TenantUser from './_components/TenantUser.svelte'
import {getTenant} from 'data/api/tenants'
import type {Tenant} from 'data/types/tenant'
import {localeTime} from 'helpers/time'
Expand Down Expand Up @@ -37,12 +38,13 @@
{#if tenant.UserIDs && tenant.UserIDs.length}
<table>
<tr>
<th>ID</th>
<th>Role</th>
<th>Email</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
{#each tenant.UserIDs as id (id)}
<tr>
<td>{id}</td>
</tr>
<TenantUser {id} />
{/each}
</table>
{:else}
Expand Down
21 changes: 21 additions & 0 deletions assets/pages/admin/tenants/_components/TenantUser.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script lang="ts">
import {getUser} from 'data/api/users'
import type {User} from 'data/types/user'
import {onMount} from 'svelte'
export let id = '' as string
let user = {} as User
onMount(async () => {
user = await getUser(id)
})
</script>

<tr>
<td>{user.Role}</td>
<td>{user.Email}</td>
<td>{user.FirstName}</td>
<td>{user.LastName}</td>
</tr>
7 changes: 6 additions & 1 deletion server/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,10 @@ func (s *Server) tenantHandler(c echo.Context) error {
return echo.NewHTTPError(http.StatusNotFound, err)
}

return c.JSON(http.StatusOK, tenant)
t, err := db.ConvertTenant(c, tenant)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

return c.JSON(http.StatusOK, t)
}

0 comments on commit cdd6bc1

Please sign in to comment.