Skip to content

Commit

Permalink
feat(backend): use auth service client in tenant service
Browse files Browse the repository at this point in the history
  • Loading branch information
BlairCurrey committed Dec 18, 2024
1 parent 02cc1d5 commit 5635631
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 194 deletions.
10 changes: 4 additions & 6 deletions packages/backend/src/auth-service-client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ export class AuthServiceClient {
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private async request<T = any>(
path: string,
options: RequestInit
): Promise<T> {
private async request<T>(path: string, options: RequestInit): Promise<T> {
const response = await fetch(`${this.baseUrl}${path}`, options)

if (!response.ok) {
Expand Down Expand Up @@ -71,7 +68,7 @@ export class AuthServiceClient {
public tenant = {
get: (id: string) =>
this.request<Tenant>(`/tenant/${id}`, { method: 'GET' }),
create: (data: Omit<Tenant, 'id'>) =>
create: (data: Tenant) =>
this.request('/tenant', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
Expand All @@ -83,6 +80,7 @@ export class AuthServiceClient {
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
}),
delete: (id: string) => this.request(`/tenant/${id}`, { method: 'DELETE' })
delete: (id: string, deletedAt?: Date) =>
this.request(`/tenant/${id}`, { method: 'DELETE' })
}
}
6 changes: 3 additions & 3 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,16 @@ export function initIocContainer(
return createInMemoryDataStore(config.localCacheDuration)
})

container.singleton('authServiceClient', async () => {
container.singleton('authServiceClient', () => {
return new AuthServiceClient(config.authServiceApiUrl)
})

container.singleton('tenantService', async (deps) => {
return createTenantService({
logger: await deps.use('logger'),
knex: await deps.use('knex'),
apolloClient: await deps.use('apolloClient'),
tenantCache: await deps.use('tenantCache')
tenantCache: await deps.use('tenantCache'),
authServiceClient: deps.use('authServiceClient')
})
})

Expand Down
Loading

0 comments on commit 5635631

Please sign in to comment.