feat: wire admin workflows to real APIs
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
@@ -20,6 +20,7 @@ export interface CreateBlacklistDto {
|
||||
phoneNumber: string;
|
||||
reason?: string;
|
||||
status?: string;
|
||||
operatorId?: string;
|
||||
}
|
||||
|
||||
export interface CreateDrainageFieldDto {
|
||||
@@ -31,6 +32,18 @@ export interface CreateDrainageFieldDto {
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export interface DictionaryStatusDto {
|
||||
status?: string;
|
||||
operatorId?: string;
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
export interface DictionaryListQuery {
|
||||
tenantId?: string;
|
||||
keyword?: string;
|
||||
status?: string;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class DictionariesService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
@@ -43,45 +56,94 @@ export class DictionariesService {
|
||||
return this.prisma.phoneSegment.create({ data });
|
||||
}
|
||||
|
||||
listSensitiveWords() {
|
||||
return this.prisma.sensitiveWord.findMany({ orderBy: { createdAt: 'desc' }, take: 200 });
|
||||
listSensitiveWords(query: DictionaryListQuery = {}) {
|
||||
return this.prisma.sensitiveWord.findMany({
|
||||
where: {
|
||||
status: query.status && query.status !== 'all' ? query.status : undefined,
|
||||
OR: query.keyword ? [
|
||||
{ word: { contains: query.keyword } },
|
||||
{ level: { contains: query.keyword } },
|
||||
] : undefined,
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: 200,
|
||||
});
|
||||
}
|
||||
|
||||
createSensitiveWord(data: CreateSensitiveWordDto) {
|
||||
return this.prisma.sensitiveWord.create({
|
||||
async createSensitiveWord(data: CreateSensitiveWordDto) {
|
||||
const created = await this.prisma.sensitiveWord.create({
|
||||
data: {
|
||||
word: data.word,
|
||||
level: data.level ?? 'block',
|
||||
status: data.status ?? 'active',
|
||||
},
|
||||
});
|
||||
await this.writeOperationLog(undefined, 'sensitive_word.create', 'sensitive_word', created.id, { word: data.word });
|
||||
return created;
|
||||
}
|
||||
|
||||
listGlobalBlacklist() {
|
||||
return this.prisma.globalBlacklist.findMany({ orderBy: { createdAt: 'desc' }, take: 200 });
|
||||
async changeSensitiveWordStatus(id: string, data: DictionaryStatusDto) {
|
||||
const status = data.status ?? 'active';
|
||||
const updated = await this.prisma.sensitiveWord.update({ where: { id }, data: { status } });
|
||||
await this.writeOperationLog(data.operatorId, `sensitive_word.${status}`, 'sensitive_word', id, { reason: data.reason });
|
||||
return updated;
|
||||
}
|
||||
|
||||
createGlobalBlacklist(data: CreateBlacklistDto) {
|
||||
return this.prisma.globalBlacklist.create({
|
||||
listGlobalBlacklist(query: DictionaryListQuery = {}) {
|
||||
return this.prisma.globalBlacklist.findMany({
|
||||
where: {
|
||||
status: query.status && query.status !== 'all' ? query.status : undefined,
|
||||
OR: query.keyword ? [
|
||||
{ phoneNumber: { contains: query.keyword } },
|
||||
{ reason: { contains: query.keyword } },
|
||||
] : undefined,
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: 200,
|
||||
});
|
||||
}
|
||||
|
||||
async createGlobalBlacklist(data: CreateBlacklistDto) {
|
||||
const created = await this.prisma.globalBlacklist.create({
|
||||
data: {
|
||||
phoneNumber: data.phoneNumber,
|
||||
reason: data.reason,
|
||||
status: data.status ?? 'active',
|
||||
},
|
||||
});
|
||||
await this.writeOperationLog(data.operatorId, 'global_blacklist.create', 'global_blacklist', created.id, {
|
||||
phoneNumber: data.phoneNumber,
|
||||
reason: data.reason,
|
||||
});
|
||||
return created;
|
||||
}
|
||||
|
||||
listEnterpriseBlacklist(tenantId?: string) {
|
||||
async changeGlobalBlacklistStatus(id: string, data: DictionaryStatusDto) {
|
||||
const status = data.status ?? 'active';
|
||||
const updated = await this.prisma.globalBlacklist.update({ where: { id }, data: { status } });
|
||||
await this.writeOperationLog(data.operatorId, `global_blacklist.${status}`, 'global_blacklist', id, { reason: data.reason });
|
||||
return updated;
|
||||
}
|
||||
|
||||
listEnterpriseBlacklist(query: DictionaryListQuery = {}) {
|
||||
return this.prisma.enterpriseBlacklist.findMany({
|
||||
where: tenantId ? { tenantId } : undefined,
|
||||
where: {
|
||||
tenantId: query.tenantId,
|
||||
status: query.status && query.status !== 'all' ? query.status : undefined,
|
||||
OR: query.keyword ? [
|
||||
{ phoneNumber: { contains: query.keyword } },
|
||||
{ reason: { contains: query.keyword } },
|
||||
] : undefined,
|
||||
},
|
||||
include: { tenant: true },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: 200,
|
||||
});
|
||||
}
|
||||
|
||||
createEnterpriseBlacklist(data: CreateBlacklistDto) {
|
||||
async createEnterpriseBlacklist(data: CreateBlacklistDto) {
|
||||
if (!data.tenantId) {
|
||||
throw new Error('tenantId is required for enterprise blacklist');
|
||||
throw new BadRequestException('tenantId is required for enterprise blacklist');
|
||||
}
|
||||
const createData: Prisma.EnterpriseBlacklistUncheckedCreateInput = {
|
||||
tenantId: data.tenantId,
|
||||
@@ -89,7 +151,20 @@ export class DictionariesService {
|
||||
reason: data.reason,
|
||||
status: data.status ?? 'active',
|
||||
};
|
||||
return this.prisma.enterpriseBlacklist.create({ data: createData });
|
||||
const created = await this.prisma.enterpriseBlacklist.create({ data: createData });
|
||||
await this.writeOperationLog(data.operatorId, 'enterprise_blacklist.create', 'enterprise_blacklist', created.id, {
|
||||
tenantId: data.tenantId,
|
||||
phoneNumber: data.phoneNumber,
|
||||
reason: data.reason,
|
||||
});
|
||||
return created;
|
||||
}
|
||||
|
||||
async changeEnterpriseBlacklistStatus(id: string, data: DictionaryStatusDto) {
|
||||
const status = data.status ?? 'active';
|
||||
const updated = await this.prisma.enterpriseBlacklist.update({ where: { id }, data: { status } });
|
||||
await this.writeOperationLog(data.operatorId, `enterprise_blacklist.${status}`, 'enterprise_blacklist', id, { reason: data.reason });
|
||||
return updated;
|
||||
}
|
||||
|
||||
listDrainageFields() {
|
||||
@@ -108,4 +183,16 @@ export class DictionariesService {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private writeOperationLog(userId: string | undefined, action: string, resource: string, resourceId: string, detail: Record<string, unknown>) {
|
||||
return this.prisma.operationLog.create({
|
||||
data: {
|
||||
userId,
|
||||
action,
|
||||
resource,
|
||||
resourceId,
|
||||
detail: detail as Prisma.InputJsonValue,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user