Add public API keys, outbound webhooks, and bulk SMS campaigns with settings UI and org modules.
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
Post,
|
||||
Query,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import {
|
||||
IsArray,
|
||||
IsBoolean,
|
||||
IsDateString,
|
||||
IsInt,
|
||||
IsOptional,
|
||||
IsString,
|
||||
Max,
|
||||
MaxLength,
|
||||
Min,
|
||||
MinLength,
|
||||
ValidateIf,
|
||||
} from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { CurrentUser } from '../auth/current-user.decorator';
|
||||
import { Roles } from '../auth/roles.decorator';
|
||||
import { RolesGuard } from '../auth/roles.guard';
|
||||
import { OrgModuleGuard } from '../billing/org-module.guard';
|
||||
import { RequireOrgModule } from '../billing/org-module.decorator';
|
||||
import { SmsCampaignsService } from './sms-campaigns.service';
|
||||
|
||||
class CreateSmsCampaignDto {
|
||||
@IsString()
|
||||
@MinLength(2)
|
||||
@MaxLength(120)
|
||||
name!: string;
|
||||
|
||||
@IsString()
|
||||
@MinLength(2)
|
||||
@MaxLength(900)
|
||||
body!: string;
|
||||
|
||||
@IsArray()
|
||||
@IsString({ each: true })
|
||||
personIds!: string[];
|
||||
|
||||
@IsOptional()
|
||||
@ValidateIf((_, v) => v !== '' && v != null)
|
||||
@IsDateString()
|
||||
scheduledAt?: string | null;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
queueNow?: boolean;
|
||||
}
|
||||
|
||||
class ListQueryDto {
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
page?: number = 1;
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
@Max(50)
|
||||
limit?: number = 20;
|
||||
}
|
||||
|
||||
@Controller('sms-campaigns')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard, OrgModuleGuard)
|
||||
@RequireOrgModule('sms_campaigns')
|
||||
@Roles('owner', 'admin')
|
||||
export class SmsCampaignsController {
|
||||
constructor(private readonly campaigns: SmsCampaignsService) {}
|
||||
|
||||
@Get()
|
||||
list(
|
||||
@CurrentUser() user: { organizationId: string },
|
||||
@Query() query: ListQueryDto,
|
||||
) {
|
||||
return this.campaigns.list(
|
||||
user.organizationId,
|
||||
query.page ?? 1,
|
||||
query.limit ?? 20,
|
||||
);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
get(
|
||||
@CurrentUser() user: { organizationId: string },
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
return this.campaigns.get(user.organizationId, id);
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(
|
||||
@CurrentUser()
|
||||
user: { organizationId: string; userId: string; role: string },
|
||||
@Body() dto: CreateSmsCampaignDto,
|
||||
) {
|
||||
return this.campaigns.create(
|
||||
{
|
||||
organizationId: user.organizationId,
|
||||
userId: user.userId,
|
||||
role: user.role as 'owner' | 'admin' | 'sales' | 'support',
|
||||
},
|
||||
dto,
|
||||
);
|
||||
}
|
||||
|
||||
@Post(':id/queue')
|
||||
queue(
|
||||
@CurrentUser() user: { organizationId: string },
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
return this.campaigns.queue(user.organizationId, id);
|
||||
}
|
||||
|
||||
@Post(':id/cancel')
|
||||
cancel(
|
||||
@CurrentUser() user: { organizationId: string },
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
return this.campaigns.cancel(user.organizationId, id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user