Skip to content

Commit

Permalink
Merge pull request #80 from yeha98555/feature/search-activity
Browse files Browse the repository at this point in the history
feat: Add sellStart search params
  • Loading branch information
yurychang committed Jun 28, 2023
2 parents f11120f + d4dbc4c commit cb21ff2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/routes/activity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Router } from 'express';
import z from 'zod';
import { processRequestQuery, validateRequestParams } from '@/middleware/paramsValidator';
import {
processRequestQuery,
validateRequestParams,
} from '@/middleware/paramsValidator';
import activityController from '@/controllers/activity';
import parseSortString from '@/utils/parseSortString';
import { Region } from '@/enums/region';
Expand All @@ -20,6 +23,8 @@ activityRouter.get(
.optional(),
startAfter: z.coerce.date().optional(),
startBefore: z.coerce.date().optional(),
sellStartAfter: z.coerce.date().optional(),
sellStartBefore: z.coerce.date().optional(),
q: z.string().optional(),
sort: z
.string()
Expand Down
14 changes: 14 additions & 0 deletions src/services/activity/searchActivities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ const searchActivities = async ({
region,
startAfter,
startBefore,
sellStartBefore,
sellStartAfter,
q,
sort,
}: {
Expand All @@ -141,12 +143,15 @@ const searchActivities = async ({
region?: Region;
startAfter?: Date;
startBefore?: Date;
sellStartBefore?: Date;
sellStartAfter?: Date;
q?: string;
sort?: SortRules;
}) => {
const filter: {
region?: Region;
start_at?: { $gte?: Date; $lt?: Date };
sell_at?: { $gte?: Date; $lt?: Date };
name?: { $regex: string };
} = {};

Expand All @@ -162,6 +167,15 @@ const searchActivities = async ({
$lt: d.add(startBefore, { days: 1 }),
};
}
if (sellStartAfter) {
filter.sell_at = { $gte: sellStartAfter };
}
if (sellStartBefore) {
filter.sell_at = {
...(filter.sell_at || {}),
$lt: d.add(sellStartBefore, { days: 1 }),
};
}

if (q) {
const exp =
Expand Down

0 comments on commit cb21ff2

Please sign in to comment.