fix: complete first version issue remediation
This commit is contained in:
@@ -30,8 +30,8 @@ export class DictionariesController {
|
||||
}
|
||||
|
||||
@Get('phone-carrier-rules')
|
||||
listPhoneCarrierRules() {
|
||||
return this.dictionaries.listPhoneCarrierRules();
|
||||
listPhoneCarrierRules(@Query('keyword') keyword?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string) {
|
||||
return this.dictionaries.listPhoneCarrierRules({ keyword, page: Number(page) || undefined, pageSize: Number(pageSize) || undefined });
|
||||
}
|
||||
|
||||
@Post('phone-carrier-rules')
|
||||
|
||||
@@ -5,6 +5,10 @@ function createPrismaMock() {
|
||||
phoneSegment: {
|
||||
findMany: jest.fn(),
|
||||
},
|
||||
phoneCarrierRule: {
|
||||
findMany: jest.fn().mockResolvedValue([]),
|
||||
count: jest.fn().mockResolvedValue(0),
|
||||
},
|
||||
sensitiveWord: {
|
||||
findMany: jest.fn(),
|
||||
create: jest.fn().mockImplementation(({ data }) => Promise.resolve({ id: 'word-1', ...data })),
|
||||
@@ -80,6 +84,17 @@ describe('DictionariesService', () => {
|
||||
}));
|
||||
});
|
||||
|
||||
it('paginates carrier rules with a real database count', async () => {
|
||||
const prisma = createPrismaMock();
|
||||
prisma.phoneCarrierRule.findMany.mockResolvedValue([{ id: 'rule-1', carrier: 'mobile', pattern: '^13' }]);
|
||||
prisma.phoneCarrierRule.count.mockResolvedValue(26);
|
||||
const service = new DictionariesService(prisma as never);
|
||||
|
||||
await expect(service.listPhoneCarrierRules({ keyword: '13', page: 2, pageSize: 25 })).resolves.toEqual(expect.objectContaining({ total: 26, page: 2, pageSize: 25 }));
|
||||
expect(prisma.phoneCarrierRule.findMany).toHaveBeenCalledWith(expect.objectContaining({ skip: 25, take: 25, where: { OR: expect.any(Array) } }));
|
||||
expect(prisma.phoneCarrierRule.count).toHaveBeenCalledWith({ where: { OR: expect.any(Array) } });
|
||||
});
|
||||
|
||||
it('creates and soft deletes blacklist and sensitive word entries with operation logs', async () => {
|
||||
const prisma = createPrismaMock();
|
||||
const service = new DictionariesService(prisma as never);
|
||||
|
||||
@@ -23,6 +23,12 @@ export interface CreatePhoneCarrierRuleDto {
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
export interface PageQuery {
|
||||
keyword?: string;
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
}
|
||||
|
||||
export interface CreateSensitiveWordDto {
|
||||
word: string;
|
||||
level?: string;
|
||||
@@ -98,8 +104,21 @@ export class DictionariesService {
|
||||
return this.prisma.phoneSegment.create({ data });
|
||||
}
|
||||
|
||||
listPhoneCarrierRules() {
|
||||
return this.prisma.phoneCarrierRule.findMany({ orderBy: [{ priority: 'asc' }, { createdAt: 'desc' }], take: 200 });
|
||||
async listPhoneCarrierRules(query: PageQuery = {}) {
|
||||
const page = Math.max(1, Number(query.page ?? 1));
|
||||
const pageSize = Math.min(100, Math.max(1, Number(query.pageSize ?? 25)));
|
||||
const where = query.keyword?.trim() ? {
|
||||
OR: [
|
||||
{ carrier: { contains: query.keyword.trim() } },
|
||||
{ pattern: { contains: query.keyword.trim() } },
|
||||
{ remark: { contains: query.keyword.trim() } },
|
||||
],
|
||||
} : undefined;
|
||||
const [items, total] = await Promise.all([
|
||||
this.prisma.phoneCarrierRule.findMany({ where, orderBy: [{ priority: 'asc' }, { createdAt: 'desc' }], skip: (page - 1) * pageSize, take: pageSize }),
|
||||
this.prisma.phoneCarrierRule.count({ where }),
|
||||
]);
|
||||
return { items, total, page, pageSize };
|
||||
}
|
||||
|
||||
createPhoneCarrierRule(data: CreatePhoneCarrierRuleDto) {
|
||||
|
||||
Reference in New Issue
Block a user