sms-setting and campain
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
Patch,
|
||||
Post,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
||||
import { Permissions } from '../auth/decorators/permissions.decorator';
|
||||
import { Roles } from '../auth/decorators/roles.decorator';
|
||||
import { PermissionsGuard } from '../auth/guards/permissions.guard';
|
||||
import { RolesGuard } from '../auth/guards/roles.guard';
|
||||
import { AuthUser } from '../auth/interfaces/auth-user.interface';
|
||||
import { PermissionCode } from '../authorization/enums/permission-code.enum';
|
||||
import { UserRole } from '../users/enums/user-role.enum';
|
||||
import {
|
||||
ApiStandardController,
|
||||
ApiStandardOkResponse,
|
||||
} from '../swagger/decorators/swagger-response.decorator';
|
||||
import { SWAGGER_JWT_AUTH } from '../swagger/swagger.setup';
|
||||
import {
|
||||
PreviewSmsScenarioDto,
|
||||
UpdateSmsScenarioSettingDto,
|
||||
} from './dto/update-sms-scenario-setting.dto';
|
||||
import { SmsScenarioKey } from './enums/sms-scenario-key.enum';
|
||||
import { ReserveSmsService } from './reserve-sms.service';
|
||||
import { SmsSettingsService } from './sms-settings.service';
|
||||
|
||||
@ApiTags('SMS Settings')
|
||||
@ApiBearerAuth(SWAGGER_JWT_AUTH)
|
||||
@ApiStandardController()
|
||||
@Controller('sms-settings')
|
||||
@UseGuards(RolesGuard, PermissionsGuard)
|
||||
export class SmsSettingsController {
|
||||
constructor(
|
||||
private readonly smsSettingsService: SmsSettingsService,
|
||||
private readonly reserveSmsService: ReserveSmsService,
|
||||
) {}
|
||||
|
||||
@Roles(UserRole.ADMIN)
|
||||
@Permissions(PermissionCode.SMS_TEMPLATES_READ)
|
||||
@ApiStandardOkResponse(Object, { isArray: true })
|
||||
@Get('scenarios')
|
||||
getScenarios() {
|
||||
return this.smsSettingsService.getScenarioDefinitions();
|
||||
}
|
||||
|
||||
@Roles(UserRole.ADMIN)
|
||||
@Permissions(PermissionCode.SMS_TEMPLATES_READ)
|
||||
@ApiStandardOkResponse(Object, { isArray: true })
|
||||
@Get()
|
||||
findAll(@CurrentUser() user: AuthUser) {
|
||||
return this.smsSettingsService.findAll(user);
|
||||
}
|
||||
|
||||
@Roles(UserRole.ADMIN)
|
||||
@Permissions(PermissionCode.SMS_TEMPLATES_WRITE)
|
||||
@ApiStandardOkResponse(Object)
|
||||
@Patch(':key')
|
||||
update(
|
||||
@Param('key') key: SmsScenarioKey,
|
||||
@Body() updateDto: UpdateSmsScenarioSettingDto,
|
||||
@CurrentUser() user: AuthUser,
|
||||
) {
|
||||
return this.smsSettingsService.update(key, updateDto, user);
|
||||
}
|
||||
|
||||
@Roles(UserRole.ADMIN)
|
||||
@Permissions(PermissionCode.SMS_TEMPLATES_READ)
|
||||
@ApiStandardOkResponse(Object)
|
||||
@Post('preview')
|
||||
preview(@Body() dto: PreviewSmsScenarioDto, @CurrentUser() user: AuthUser) {
|
||||
return this.smsSettingsService.preview(dto, user);
|
||||
}
|
||||
|
||||
@Roles(UserRole.ADMIN)
|
||||
@Permissions(PermissionCode.SMS_TEMPLATES_WRITE)
|
||||
@ApiStandardOkResponse(Object)
|
||||
@Post('trigger-reminders')
|
||||
async triggerReminders(@CurrentUser() user: AuthUser) {
|
||||
const sentCount = await this.reserveSmsService.processDailyReminders();
|
||||
return { sentCount };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user