51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import { Controller, Get, Param, NotFoundException, Logger } from '@nestjs/common';
|
|
import { PrismaService } from '@/infrastructure/persistence/prisma/prisma.service';
|
|
|
|
/**
|
|
* 内部 API - 供 2.0 服务间调用,不需要 JWT 认证
|
|
*/
|
|
@Controller('internal')
|
|
export class InternalController {
|
|
private readonly logger = new Logger(InternalController.name);
|
|
|
|
constructor(private readonly prisma: PrismaService) {}
|
|
|
|
/**
|
|
* 根据 accountSequence 获取用户的 Kava 地址
|
|
* trading-service 创建卖单时调用
|
|
*/
|
|
@Get('users/:accountSequence/kava-address')
|
|
async getUserKavaAddress(
|
|
@Param('accountSequence') accountSequence: string,
|
|
): Promise<{ kavaAddress: string }> {
|
|
// 1. 通过 SyncedLegacyUser 查找 legacyId
|
|
const legacyUser = await this.prisma.syncedLegacyUser.findUnique({
|
|
where: { accountSequence },
|
|
select: { legacyId: true },
|
|
});
|
|
|
|
if (!legacyUser) {
|
|
this.logger.warn(`[Internal] Legacy user not found: ${accountSequence}`);
|
|
throw new NotFoundException(`用户未找到: ${accountSequence}`);
|
|
}
|
|
|
|
// 2. 通过 legacyUserId + chainType 查找 KAVA 钱包地址
|
|
const walletAddress = await this.prisma.syncedWalletAddress.findUnique({
|
|
where: {
|
|
legacyUserId_chainType: {
|
|
legacyUserId: legacyUser.legacyId,
|
|
chainType: 'KAVA',
|
|
},
|
|
},
|
|
select: { address: true, status: true },
|
|
});
|
|
|
|
if (!walletAddress || walletAddress.status !== 'ACTIVE') {
|
|
this.logger.warn(`[Internal] Kava address not found for: ${accountSequence}`);
|
|
throw new NotFoundException(`未找到 Kava 钱包地址: ${accountSequence}`);
|
|
}
|
|
|
|
return { kavaAddress: walletAddress.address };
|
|
}
|
|
}
|