Files
api/src/sms/sms.controller.ts
T

112 lines
2.7 KiB
TypeScript
Raw Normal View History

import {
Body,
Controller,
Get,
Param,
Patch,
Post,
Put,
Query,
UseGuards,
} from '@nestjs/common';
2026-07-23 19:41:21 +03:30
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
import { CurrentUser } from '../auth/current-user.decorator';
import {
ChargeSmsWalletDto,
SmsTableQueryDto,
UpdateSmsAccountDto,
UpdateSmsChargeInfoDto,
} from './dto/sms-account.dto';
2026-07-23 19:41:21 +03:30
import { SmsService } from './sms.service';
@Controller('sms')
@UseGuards(JwtAuthGuard)
export class SmsController {
constructor(private readonly smsService: SmsService) {}
@Get('tenants')
listTenants() {
return this.smsService.listTenants();
}
@Get('lowest')
lowest(@Query('limit') limit?: string) {
return this.smsService.getLowestBalances(Number(limit) || 5);
}
@Get('tenants/:id')
getAccount(@Param('id') id: string) {
return this.smsService.getAccount(id);
}
@Get('tenants/:id/charge-info')
getChargeInfo(@Param('id') id: string) {
return this.smsService.getChargeInfo(id);
}
@Put('tenants/:id/charge-info')
updateChargeInfo(
@Param('id') id: string,
@Body() dto: UpdateSmsChargeInfoDto,
@CurrentUser() user: { id: string },
) {
return this.smsService.updateChargeInfo(id, dto, user.id);
}
@Get('tenants/:id/report')
report(
@Param('id') id: string,
@Query('fromDate') fromDate?: string,
@Query('toDate') toDate?: string,
) {
return this.smsService.getPeriodReport(id, fromDate, toDate);
}
@Get('tenants/:id/report/charges')
chargeReport(
@Param('id') id: string,
@Query('fromDate') fromDate?: string,
@Query('toDate') toDate?: string,
) {
return this.smsService.getChargeReport(id, fromDate, toDate);
}
@Post('tenants/:id/logs/table')
logsTable(@Param('id') id: string, @Body() dto: SmsTableQueryDto) {
return this.smsService.getLogsTable(id, dto);
}
@Post('tenants/:id/ledger/table')
ledgerTable(@Param('id') id: string, @Body() dto: SmsTableQueryDto) {
return this.smsService.getLedgerTable(id, dto);
}
2026-07-23 19:41:21 +03:30
@Patch('tenants/:id')
updateAccount(
@Param('id') id: string,
@Body() dto: UpdateSmsAccountDto,
@CurrentUser() user: { id: string },
) {
return this.smsService.updateAccount(id, dto, user.id);
}
@Post('tenants/:id/charge')
charge(
@Param('id') id: string,
@Body() dto: ChargeSmsWalletDto,
@CurrentUser() user: { id: string },
) {
return this.smsService.chargeWallet(id, dto, user.id);
}
@Post('tenants/:id/block')
block(@Param('id') id: string, @CurrentUser() user: { id: string }) {
return this.smsService.setBlocked(id, true, user.id);
}
@Post('tenants/:id/unblock')
unblock(@Param('id') id: string, @CurrentUser() user: { id: string }) {
return this.smsService.setBlocked(id, false, user.id);
}
}