Skip to content
Snippets Groups Projects
Verified Commit 10553f7e authored by Berend Sliedrecht's avatar Berend Sliedrecht Committed by Konstantin Tsabolov
Browse files

fix: catch the invalid tenant id error


Signed-off-by: default avatarBerend Sliedrecht <berend@animo.id>
parent 91336d97
No related branches found
No related tags found
1 merge request!40End to end run preparation
......@@ -20,3 +20,28 @@ export class EventTenantsCreate extends BaseEvent<TenantRecord, undefined> {
return new EventTenantsCreate(e.data, undefined, e.id, e.type, e.timestamp);
}
}
export type EventTenantsGetAllTenantIdsInput = BaseEventInput<
Record<string, unknown>,
undefined
>;
export class EventTenantsGetAllTenantIds extends BaseEvent<
Array<string>,
undefined
> {
public static token = 'tenants.getAllTenantIds';
public get instance() {
return this.data;
}
public static fromEvent(e: EventTenantsGetAllTenantIds) {
return new EventTenantsGetAllTenantIds(
e.data,
undefined,
e.id,
e.type,
e.timestamp,
);
}
}
......@@ -50,6 +50,7 @@ import { LEDGERS } from '../config/ledger.js';
import { AgentLogger } from './logger.js';
export type AppAgent = Agent<AgentService['modules']>;
export type TenantAgent = Agent<Omit<AgentService['modules'], 'tenant'>>;
@Injectable()
export class AgentService implements OnApplicationShutdown {
......
import type { AppAgent } from './agent.service.js';
import type { AppAgent, TenantAgent } from './agent.service.js';
import { Injectable } from '@nestjs/common';
......@@ -12,23 +12,18 @@ export class WithTenantService {
this.agent = agentService.agent;
}
public invoke<T>(
public async invoke<T>(
tenantId: string,
cb: (tenant: AppAgent) => Promise<T>,
cb: (tenant: TenantAgent) => Promise<T>,
): Promise<T> {
// eslint-disable-next-line no-async-promise-executor
return new Promise<T>(async (resolve, reject) => {
await this.agent.modules.tenants.withTenantAgent(
{ tenantId },
async (tenant) => {
try {
const ret = await cb(tenant as unknown as AppAgent);
resolve(ret);
} catch (e) {
reject(e);
}
},
);
});
try {
const tenant = await this.agent.modules.tenants.getTenantAgent({
tenantId,
});
return cb(tenant as unknown as TenantAgent);
} catch (e) {
return Promise.reject(e);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment