46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { Body, Controller, Get, Post, Query, UseGuards } from '@nestjs/common';
|
|||
|
|
import { RemoteTenant } from '../auth/remote-tenant.decorator';
|
||
|
|
import { RemoteTokenGuard } from '../auth/remote-token.guard';
|
||
|
|
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;
|
||
|
|
};
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Product apps (Hamkar/Khanegi) → SuperAdmin SMS wallet.
|
||
|
|
* Auth: Authorization: Bearer {Tenant.remoteApiToken}
|
||
|
|
*
|
||
|
|
* GET /api/remote/sms/status?parts=1
|
||
|
|
* POST /api/remote/sms/consume
|
||
|
|
*/
|
||
|
|
@Controller('remote/sms')
|
||
|
|
@UseGuards(RemoteTokenGuard)
|
||
|
|
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);
|
||
|
|
}
|
||
|
|
}
|