55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import { Body, Controller, Get, Param, Patch, Post, Query, UseGuards } from '@nestjs/common';
|
|||
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||
|
|
import { CurrentUser } from '../auth/current-user.decorator';
|
||
|
|
import { ChargeSmsWalletDto, UpdateSmsAccountDto } from './dto/sms-account.dto';
|
||
|
|
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);
|
||
|
|
}
|
||
|
|
|
||
|
|
@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);
|
||
|
|
}
|
||
|
|
}
|