feat: complete cmpp platform phases 0-5
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import { Body, Controller, Get, Post } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { TenantId } from '../common/tenant-id.decorator';
|
||||
import {
|
||||
CreateBlacklistDto,
|
||||
CreateDrainageFieldDto,
|
||||
CreatePhoneSegmentDto,
|
||||
CreateSensitiveWordDto,
|
||||
DictionariesService,
|
||||
} from './dictionaries.service';
|
||||
|
||||
@ApiTags('dictionaries')
|
||||
@Controller('admin/dictionaries')
|
||||
export class DictionariesController {
|
||||
constructor(private readonly dictionaries: DictionariesService) {}
|
||||
|
||||
@Get('phone-segments')
|
||||
listPhoneSegments() {
|
||||
return this.dictionaries.listPhoneSegments();
|
||||
}
|
||||
|
||||
@Post('phone-segments')
|
||||
createPhoneSegment(@Body() body: CreatePhoneSegmentDto) {
|
||||
return this.dictionaries.createPhoneSegment(body);
|
||||
}
|
||||
|
||||
@Get('sensitive-words')
|
||||
listSensitiveWords() {
|
||||
return this.dictionaries.listSensitiveWords();
|
||||
}
|
||||
|
||||
@Post('sensitive-words')
|
||||
createSensitiveWord(@Body() body: CreateSensitiveWordDto) {
|
||||
return this.dictionaries.createSensitiveWord(body);
|
||||
}
|
||||
|
||||
@Get('blacklists/global')
|
||||
listGlobalBlacklist() {
|
||||
return this.dictionaries.listGlobalBlacklist();
|
||||
}
|
||||
|
||||
@Post('blacklists/global')
|
||||
createGlobalBlacklist(@Body() body: CreateBlacklistDto) {
|
||||
return this.dictionaries.createGlobalBlacklist(body);
|
||||
}
|
||||
|
||||
@Get('blacklists/enterprise')
|
||||
listEnterpriseBlacklist(@TenantId() tenantId?: string) {
|
||||
return this.dictionaries.listEnterpriseBlacklist(tenantId);
|
||||
}
|
||||
|
||||
@Post('blacklists/enterprise')
|
||||
createEnterpriseBlacklist(@Body() body: CreateBlacklistDto) {
|
||||
return this.dictionaries.createEnterpriseBlacklist(body);
|
||||
}
|
||||
|
||||
@Get('drainage-fields')
|
||||
listDrainageFields() {
|
||||
return this.dictionaries.listDrainageFields();
|
||||
}
|
||||
|
||||
@Post('drainage-fields')
|
||||
createDrainageField(@Body() body: CreateDrainageFieldDto) {
|
||||
return this.dictionaries.createDrainageField(body);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { DictionariesController } from './dictionaries.controller';
|
||||
import { DictionariesService } from './dictionaries.service';
|
||||
|
||||
@Module({
|
||||
controllers: [DictionariesController],
|
||||
providers: [DictionariesService],
|
||||
exports: [DictionariesService],
|
||||
})
|
||||
export class DictionariesModule {}
|
||||
@@ -0,0 +1,111 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
export interface CreatePhoneSegmentDto {
|
||||
prefix: string;
|
||||
carrier: string;
|
||||
province?: string;
|
||||
city?: string;
|
||||
}
|
||||
|
||||
export interface CreateSensitiveWordDto {
|
||||
word: string;
|
||||
level?: string;
|
||||
status?: string;
|
||||
}
|
||||
|
||||
export interface CreateBlacklistDto {
|
||||
tenantId?: string;
|
||||
phoneNumber: string;
|
||||
reason?: string;
|
||||
status?: string;
|
||||
}
|
||||
|
||||
export interface CreateDrainageFieldDto {
|
||||
code: string;
|
||||
name: string;
|
||||
fieldType: string;
|
||||
required?: boolean;
|
||||
status?: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class DictionariesService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
listPhoneSegments() {
|
||||
return this.prisma.phoneSegment.findMany({ orderBy: { prefix: 'asc' }, take: 200 });
|
||||
}
|
||||
|
||||
createPhoneSegment(data: CreatePhoneSegmentDto) {
|
||||
return this.prisma.phoneSegment.create({ data });
|
||||
}
|
||||
|
||||
listSensitiveWords() {
|
||||
return this.prisma.sensitiveWord.findMany({ orderBy: { createdAt: 'desc' }, take: 200 });
|
||||
}
|
||||
|
||||
createSensitiveWord(data: CreateSensitiveWordDto) {
|
||||
return this.prisma.sensitiveWord.create({
|
||||
data: {
|
||||
word: data.word,
|
||||
level: data.level ?? 'block',
|
||||
status: data.status ?? 'active',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
listGlobalBlacklist() {
|
||||
return this.prisma.globalBlacklist.findMany({ orderBy: { createdAt: 'desc' }, take: 200 });
|
||||
}
|
||||
|
||||
createGlobalBlacklist(data: CreateBlacklistDto) {
|
||||
return this.prisma.globalBlacklist.create({
|
||||
data: {
|
||||
phoneNumber: data.phoneNumber,
|
||||
reason: data.reason,
|
||||
status: data.status ?? 'active',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
listEnterpriseBlacklist(tenantId?: string) {
|
||||
return this.prisma.enterpriseBlacklist.findMany({
|
||||
where: tenantId ? { tenantId } : undefined,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: 200,
|
||||
});
|
||||
}
|
||||
|
||||
createEnterpriseBlacklist(data: CreateBlacklistDto) {
|
||||
if (!data.tenantId) {
|
||||
throw new Error('tenantId is required for enterprise blacklist');
|
||||
}
|
||||
const createData: Prisma.EnterpriseBlacklistUncheckedCreateInput = {
|
||||
tenantId: data.tenantId,
|
||||
phoneNumber: data.phoneNumber,
|
||||
reason: data.reason,
|
||||
status: data.status ?? 'active',
|
||||
};
|
||||
return this.prisma.enterpriseBlacklist.create({ data: createData });
|
||||
}
|
||||
|
||||
listDrainageFields() {
|
||||
return this.prisma.drainageField.findMany({ orderBy: { createdAt: 'desc' }, take: 200 });
|
||||
}
|
||||
|
||||
createDrainageField(data: CreateDrainageFieldDto) {
|
||||
return this.prisma.drainageField.create({
|
||||
data: {
|
||||
code: data.code,
|
||||
name: data.name,
|
||||
fieldType: data.fieldType,
|
||||
required: data.required ?? false,
|
||||
status: data.status ?? 'active',
|
||||
description: data.description,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user