Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add query by date #664

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/entities/Event/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,13 @@ export default class EventModel extends Model<DeprecatedEventAttributes> {
options.list === EventListType.Upcoming,
SQL`AND e.next_finish_at > now() AND e.next_start_at > now()`
)}
${conditional(
!!options.date,
SQL`
AND e.start_at >= '${date}T00:00:00.000Z
AND e.start_at < '${date}T23:59:59.000Z'
Comment on lines +253 to +254
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is date?

`
)}
${conditional(!!options.search, SQL`AND "rank" > 0`)}
${conditional(
!!options.creator,
Expand Down
9 changes: 9 additions & 0 deletions src/entities/Event/routes/getEventList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ export async function getEventList(req: WithAuth) {
options.schedule = query.schedule
}

if (query.date) {
if (isNaN(new Date(query.date))) {
//out of bound
return []
} else {
options.date = query.date
}
}
Comment on lines +52 to +59
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do not nest.


if (query.position) {
const [x, y] = query.position.split(",").slice(0, 2).map(Number) as [
number,
Expand Down
1 change: 1 addition & 0 deletions src/entities/Event/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export type EventListOptions = {
limit?: number
offset?: number
order?: "asc" | "desc"
date?: string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use a more specific name for the variable like dateRange

}

export const editEventAttributes = [
Expand Down