Adds /v1/dataquery/* endpoints proxying to dataquery-api (ClickHouse) and Yente/OpenSanctions (Hetzner): POST /v1/dataquery/company/lookup — search RO/DE/UK/US registries POST /v1/dataquery/sanctions — OFAC SDN + OpenSanctions (HIT/CLEAR) GET /v1/dataquery/:group/schema — ClickHouse group schema POST /v1/dataquery/:group/query — raw SELECT within group scope SQL injection prevention via sanitize() + dataquery-api table-scope enforcement. Timeouts: 12s per upstream call. Promise.allSettled for parallel fan-out.
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
|
|
import { CompanyLookupDto, RawQueryDto, SanctionsCheckDto } from './dataquery.dto';
|
|
import { DataqueryService } from './dataquery.service';
|
|
|
|
/**
|
|
* Proxy catre dataquery-api (ClickHouse grupe pe Netcup)
|
|
* si Yente/OpenSanctions (Hetzner).
|
|
*
|
|
* Toate rutele necesita sesiune si tenant activ — fara @Public().
|
|
* Prefix global v1 → rutele sunt /v1/dataquery/...
|
|
*/
|
|
@Controller('dataquery')
|
|
export class DataqueryController {
|
|
constructor(private readonly svc: DataqueryService) {}
|
|
|
|
/** Cauta compania in registrele nationale. country: ro|de|uk|us|all (default all). */
|
|
@Post('company/lookup')
|
|
companyLookup(@Body() dto: CompanyLookupDto) {
|
|
return this.svc.companyLookup(dto.name, dto.country ?? 'all');
|
|
}
|
|
|
|
/** Screening sanctiuni OFAC + OpenSanctions. Returneaza verdict: HIT | CLEAR. */
|
|
@Post('sanctions')
|
|
sanctionsCheck(@Body() dto: SanctionsCheckDto) {
|
|
return this.svc.sanctionsCheck(dto.name);
|
|
}
|
|
|
|
/** Schema (coloane + randuri) pentru orice grupa ClickHouse. */
|
|
@Get(':group/schema')
|
|
schema(@Param('group') group: string) {
|
|
return this.svc.groupSchema(group);
|
|
}
|
|
|
|
/** Query SELECT arbitrar intr-o grupa (scoped la tabelele grupei). */
|
|
@Post(':group/query')
|
|
query(@Param('group') group: string, @Body() dto: RawQueryDto) {
|
|
return this.svc.groupQuery(group, dto.sql);
|
|
}
|
|
}
|