33 lines
987 B
TypeScript
33 lines
987 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { DataSource } from 'typeorm';
|
|
import { TenantAwareRepository } from '@it0/database';
|
|
import { AgentSession } from '../../domain/entities/agent-session.entity';
|
|
|
|
@Injectable()
|
|
export class SessionRepository extends TenantAwareRepository<AgentSession> {
|
|
constructor(dataSource: DataSource) {
|
|
super(dataSource, AgentSession);
|
|
}
|
|
|
|
async findByTenant(tenantId: string): Promise<AgentSession[]> {
|
|
return this.withRepository((repo) =>
|
|
repo.find({ where: { tenantId } as any }),
|
|
);
|
|
}
|
|
|
|
async findByStatus(status: string): Promise<AgentSession[]> {
|
|
return this.withRepository((repo) =>
|
|
repo.find({ where: { status } as any }),
|
|
);
|
|
}
|
|
|
|
async findByInstanceId(tenantId: string, agentInstanceId: string): Promise<AgentSession[]> {
|
|
return this.withRepository((repo) =>
|
|
repo.find({
|
|
where: { tenantId, agentInstanceId } as any,
|
|
order: { updatedAt: 'DESC' },
|
|
}),
|
|
);
|
|
}
|
|
}
|