2026-08-05 14:13:44 +03:30
|
|
|
import { Body, Controller, Get, Post, Query, UseGuards } from '@nestjs/common';
|
|
|
|
|
import { RemoteTenant } from '../auth/remote-tenant.decorator';
|
2026-08-05 17:11:55 +03:30
|
|
|
import { RemoteSmsAuthGuard } from '../auth/remote-sms-auth.guard';
|
2026-08-05 14:13:44 +03:30
|
|
|
import { RemoteSmsConsumeDto } from './dto/sms-account.dto';
|
|
|
|
|
import { SmsService } from './sms.service';
|
|
|
|
|
|
|
|
|
|
type RemoteTenantInfo = {
|
|
|
|
|
id: string;
|
|
|
|
|
nameFa: string;
|
|
|
|
|
domain: string | null;
|
|
|
|
|
product: string;
|
|
|
|
|
isActive: boolean;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2026-08-05 17:11:55 +03:30
|
|
|
* Product apps → SuperAdmin SMS wallet.
|
|
|
|
|
*
|
|
|
|
|
* Auth (preferred): shared HMAC
|
|
|
|
|
* X-Abshode-Domain, X-Abshode-Timestamp, X-Abshode-Signature
|
|
|
|
|
* Fallback: Authorization Bearer {Tenant.remoteApiToken}
|
2026-08-05 14:13:44 +03:30
|
|
|
*
|
|
|
|
|
* GET /api/remote/sms/status?parts=1
|
|
|
|
|
* POST /api/remote/sms/consume
|
|
|
|
|
*/
|
|
|
|
|
@Controller('remote/sms')
|
2026-08-05 17:11:55 +03:30
|
|
|
@UseGuards(RemoteSmsAuthGuard)
|
2026-08-05 14:13:44 +03:30
|
|
|
export class RemoteSmsController {
|
|
|
|
|
constructor(private readonly smsService: SmsService) {}
|
|
|
|
|
|
|
|
|
|
@Get('status')
|
|
|
|
|
status(
|
|
|
|
|
@RemoteTenant() tenant: RemoteTenantInfo,
|
|
|
|
|
@Query('parts') parts?: string,
|
|
|
|
|
@Query('isAlert') isAlert?: string,
|
|
|
|
|
) {
|
|
|
|
|
const n = Math.max(1, Math.min(50, Number(parts) || 1));
|
|
|
|
|
const alert = isAlert === '1' || isAlert === 'true';
|
|
|
|
|
return this.smsService.remoteStatus(tenant.id, n, alert);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('consume')
|
|
|
|
|
consume(
|
|
|
|
|
@RemoteTenant() tenant: RemoteTenantInfo,
|
|
|
|
|
@Body() dto: RemoteSmsConsumeDto,
|
|
|
|
|
) {
|
|
|
|
|
return this.smsService.remoteConsume(tenant.id, dto);
|
|
|
|
|
}
|
|
|
|
|
}
|