feat: optimize routing and operations views

This commit is contained in:
hectorzhao
2026-07-29 22:32:28 +08:00
parent 500f43f673
commit c0a4317a7e
21 changed files with 718 additions and 86 deletions
+14 -6
View File
@@ -1,6 +1,7 @@
import { BadRequestException, ConflictException, Injectable } from '@nestjs/common';
import { BadRequestException, ConflictException, Injectable, Optional } from '@nestjs/common';
import { Prisma } from '@prisma/client';
import { PrismaService } from '../prisma/prisma.service';
import { PhoneRoutingLookupService } from './phone-routing-lookup.service';
export interface CreatePhoneSegmentDto {
prefix: string;
@@ -83,7 +84,10 @@ export interface DictionaryListQuery {
@Injectable()
export class DictionariesService {
constructor(private readonly prisma: PrismaService) {}
constructor(
private readonly prisma: PrismaService,
@Optional() private readonly phoneRoutingLookup?: PhoneRoutingLookupService,
) {}
async listPhoneSegments(query: PhoneSegmentListQuery = {}) {
const page = Math.max(1, Number(query.page ?? 1));
@@ -129,7 +133,7 @@ export class DictionariesService {
return { items, total, page, pageSize };
}
createPhoneCarrierRule(data: CreatePhoneCarrierRuleDto) {
async createPhoneCarrierRule(data: CreatePhoneCarrierRuleDto) {
if (!data.carrier || !data.pattern) {
throw new BadRequestException('carrier and pattern are required');
}
@@ -138,7 +142,7 @@ export class DictionariesService {
} catch {
throw new BadRequestException('pattern must be a valid regular expression');
}
return this.prisma.phoneCarrierRule.create({
const created = await this.prisma.phoneCarrierRule.create({
data: {
carrier: data.carrier,
pattern: data.pattern,
@@ -147,10 +151,14 @@ export class DictionariesService {
remark: data.remark,
},
});
this.phoneRoutingLookup?.invalidateCarrierRules();
return created;
}
deletePhoneCarrierRule(id: string) {
return this.prisma.phoneCarrierRule.delete({ where: { id } });
async deletePhoneCarrierRule(id: string) {
const deleted = await this.prisma.phoneCarrierRule.delete({ where: { id } });
this.phoneRoutingLookup?.invalidateCarrierRules();
return deleted;
}
listSensitiveWords(query: DictionaryListQuery = {}) {