fix(agent): AgentInstanceRepository use DataSource directly, not TenantAwareRepository
agent_instances is in public schema — no tenant context needed. Fixes 'Tenant context not initialized' when iAgent calls internal API via Bash. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
5c5c365736
commit
b8979d521e
|
|
@ -1,43 +1,36 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { TenantAwareRepository } from '@it0/database';
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { AgentInstance } from '../../domain/entities/agent-instance.entity';
|
||||
|
||||
@Injectable()
|
||||
export class AgentInstanceRepository extends TenantAwareRepository<AgentInstance> {
|
||||
constructor(dataSource: DataSource) {
|
||||
super(dataSource, AgentInstance);
|
||||
export class AgentInstanceRepository {
|
||||
private readonly repo: Repository<AgentInstance>;
|
||||
|
||||
constructor(private readonly dataSource: DataSource) {
|
||||
this.repo = dataSource.getRepository(AgentInstance);
|
||||
}
|
||||
|
||||
findAll(): Promise<AgentInstance[]> {
|
||||
return this.withRepository((repo) =>
|
||||
repo.find({ order: { createdAt: 'DESC' } }),
|
||||
);
|
||||
return this.repo.find({ order: { createdAt: 'DESC' } });
|
||||
}
|
||||
|
||||
findById(id: string): Promise<AgentInstance | null> {
|
||||
return this.withRepository((repo) =>
|
||||
repo.findOne({ where: { id } as any }),
|
||||
);
|
||||
return this.repo.findOne({ where: { id } as any });
|
||||
}
|
||||
|
||||
findByUserId(userId: string): Promise<AgentInstance[]> {
|
||||
return this.withRepository((repo) =>
|
||||
repo.find({ where: { userId } as any, order: { createdAt: 'DESC' } }),
|
||||
);
|
||||
return this.repo.find({ where: { userId } as any, order: { createdAt: 'DESC' } });
|
||||
}
|
||||
|
||||
findByPoolServer(poolServerId: string): Promise<AgentInstance[]> {
|
||||
return this.withRepository((repo) =>
|
||||
repo.find({ where: { poolServerId, status: 'running' } as any }),
|
||||
);
|
||||
return this.repo.find({ where: { poolServerId, status: 'running' } as any });
|
||||
}
|
||||
|
||||
async save(instance: AgentInstance): Promise<AgentInstance> {
|
||||
return this.withRepository((repo) => repo.save(instance));
|
||||
save(instance: AgentInstance): Promise<AgentInstance> {
|
||||
return this.repo.save(instance);
|
||||
}
|
||||
|
||||
// Get all host ports in use on a specific server (across all tenants via public query)
|
||||
// Get all host ports in use on a specific server
|
||||
async getUsedPortsOnServer(dataSource: DataSource, serverHost: string): Promise<number[]> {
|
||||
const rows = await dataSource.query(
|
||||
`SELECT host_port FROM agent_instances WHERE server_host = $1 AND status != 'removed'`,
|
||||
|
|
|
|||
Loading…
Reference in New Issue