feat: add search functionality to campaigns list with debounce effect

This commit is contained in:
Dries Augustyns
2026-05-09 09:10:17 +02:00
parent fadc19d139
commit d11495061d
3 changed files with 115 additions and 80 deletions
+2
View File
@@ -64,6 +64,7 @@ export class Campaigns {
private async list(req: Request, res: Response, _next: NextFunction) {
const auth = res.locals.auth;
const status = req.query.status as CampaignStatus | undefined;
const search = typeof req.query.search === 'string' ? req.query.search.trim() || undefined : undefined;
const page = parseInt(req.query.page as string) || 1;
const pageSize = parseInt(req.query.pageSize as string) || 20;
@@ -74,6 +75,7 @@ export class Campaigns {
const result = await CampaignService.list(auth.projectId, {
status,
search,
page,
pageSize,
});
+11 -1
View File
@@ -186,16 +186,26 @@ export class CampaignService {
projectId: string,
options: {
status?: CampaignStatus;
search?: string;
page?: number;
pageSize?: number;
} = {},
): Promise<PaginatedResponse<Campaign>> {
const {status, page = 1, pageSize = 20} = options;
const {status, search, page = 1, pageSize = 20} = options;
const skip = (page - 1) * pageSize;
const where: Prisma.CampaignWhereInput = {
projectId,
...(status ? {status} : {}),
...(search
? {
OR: [
{name: {contains: search, mode: 'insensitive' as const}},
{subject: {contains: search, mode: 'insensitive' as const}},
{from: {contains: search, mode: 'insensitive' as const}},
],
}
: {}),
};
const [campaigns, total] = await Promise.all([