fix: close documented platform polish gaps

This commit is contained in:
hectorzhao
2026-07-11 18:20:38 +08:00
parent 6236547871
commit 2ecbb920a6
25 changed files with 193 additions and 110 deletions
+16 -27
View File
@@ -11,7 +11,7 @@ export interface CreatePhoneSegmentDto {
export interface PhoneSegmentListQuery {
keyword?: string;
cursor?: string;
page?: number;
pageSize?: number;
}
@@ -71,33 +71,22 @@ export class DictionariesService {
constructor(private readonly prisma: PrismaService) {}
async listPhoneSegments(query: PhoneSegmentListQuery = {}) {
const pageSize = Math.min(100, Math.max(1, Number(query.pageSize ?? 20)));
const page = Math.max(1, Number(query.page ?? 1));
const pageSize = Math.min(100, Math.max(1, Number(query.pageSize ?? 25)));
const keyword = query.keyword?.trim();
const items = await this.prisma.phoneSegment.findMany({
where: {
AND: [
query.cursor ? { prefix: { gt: query.cursor } } : {},
keyword ? {
OR: [
{ prefix: { startsWith: keyword } },
{ carrier: { contains: keyword } },
{ province: { contains: keyword } },
{ city: { contains: keyword } },
],
} : {},
],
},
orderBy: { prefix: 'asc' },
take: pageSize + 1,
});
const hasMore = items.length > pageSize;
const pageItems = hasMore ? items.slice(0, pageSize) : items;
return {
items: pageItems,
pageSize,
hasMore,
nextCursor: hasMore ? pageItems.at(-1)?.prefix ?? null : null,
};
const where = keyword ? {
OR: [
{ prefix: { startsWith: keyword } },
{ carrier: { contains: keyword } },
{ province: { contains: keyword } },
{ city: { contains: keyword } },
],
} : undefined;
const [items, total] = await Promise.all([
this.prisma.phoneSegment.findMany({ where, orderBy: { prefix: 'asc' }, skip: (page - 1) * pageSize, take: pageSize }),
this.prisma.phoneSegment.count({ where }),
]);
return { items, total, page, pageSize };
}
createPhoneSegment(data: CreatePhoneSegmentDto) {