06112602ec
Version the NestJS TDLib gateway with Docker deployment, migrations, automated tests and platform integration documentation while excluding all account sessions, credentials, runtime databases and backups.
70 lines
1.9 KiB
TypeScript
70 lines
1.9 KiB
TypeScript
import {
|
|
Controller, Post, Body, Param, UseGuards,
|
|
} from '@nestjs/common';
|
|
import { ApiTags, ApiBearerAuth, ApiSecurity } from '@nestjs/swagger';
|
|
import { TgAuthService } from './tg-auth.service';
|
|
import {
|
|
SetPhoneNumberDto, SubmitCodeDto, SubmitPasswordDto, ResendCodeDto,
|
|
} from './dto/tg-auth.dto';
|
|
import { TenantGuard } from '../../common/guards/tenant.guard';
|
|
import { CurrentUser } from '../../common/decorators/current-user.decorator';
|
|
|
|
@ApiTags('TG Auth')
|
|
@ApiBearerAuth()
|
|
@ApiSecurity('tenant-id')
|
|
@Controller('tg-accounts/:accountId/auth')
|
|
@UseGuards(TenantGuard)
|
|
export class TgAuthController {
|
|
constructor(private readonly tgAuthService: TgAuthService) {}
|
|
|
|
@Post('phone')
|
|
setPhoneNumber(
|
|
@CurrentUser('tenantId') tenantId: string,
|
|
@Param('accountId') accountId: string,
|
|
@Body() dto: SetPhoneNumberDto,
|
|
) {
|
|
return this.tgAuthService.setPhoneNumber(tenantId, accountId, dto.phoneNumber);
|
|
}
|
|
|
|
@Post('code')
|
|
submitCode(
|
|
@CurrentUser('tenantId') tenantId: string,
|
|
@Param('accountId') accountId: string,
|
|
@Body() dto: SubmitCodeDto,
|
|
) {
|
|
return this.tgAuthService.submitCode(tenantId, accountId, dto.code);
|
|
}
|
|
|
|
@Post('password')
|
|
submitPassword(
|
|
@CurrentUser('tenantId') tenantId: string,
|
|
@Param('accountId') accountId: string,
|
|
@Body() dto: SubmitPasswordDto,
|
|
) {
|
|
return this.tgAuthService.submitPassword(tenantId, accountId, dto.password);
|
|
}
|
|
|
|
@Post('resend')
|
|
resendCode(
|
|
@CurrentUser('tenantId') tenantId: string,
|
|
@Param('accountId') accountId: string,
|
|
) {
|
|
return this.tgAuthService.resendCode(tenantId, accountId);
|
|
}
|
|
|
|
@Post('logout')
|
|
logout(
|
|
@CurrentUser('tenantId') tenantId: string,
|
|
@Param('accountId') accountId: string,
|
|
) {
|
|
return this.tgAuthService.logout(tenantId, accountId);
|
|
}
|
|
|
|
@Post('state')
|
|
getState(
|
|
@Param('accountId') accountId: string,
|
|
) {
|
|
return this.tgAuthService.getAuthState(accountId) || { status: 'unknown' };
|
|
}
|
|
}
|