Skip to content

Commit 7202a9f

Browse files
committed
feat: Allow user scope to view old events
1 parent cf0a1fd commit 7202a9f

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

packages/ilmomasiina-backend/src/models/event.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -211,20 +211,6 @@ export default function setupEventModel(sequelize: Sequelize) {
211211
[Op.and]: {
212212
// are not drafts,
213213
draft: false,
214-
// and either:
215-
[Op.or]: {
216-
// closed less than a week ago
217-
registrationEndDate: {
218-
[Op.gt]: moment().subtract(7, "days").toDate(),
219-
},
220-
// or happened less than a week ago
221-
date: {
222-
[Op.gt]: moment().subtract(7, "days").toDate(),
223-
},
224-
endDate: {
225-
[Op.gt]: moment().subtract(7, "days").toDate(),
226-
},
227-
},
228214
},
229215
},
230216
}),

packages/ilmomasiina-backend/src/routes/events/getEventDetails.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { FastifyReply, FastifyRequest } from "fastify";
22
import { NotFound } from "http-errors";
3+
import moment from "moment";
34
import { Op } from "sequelize";
45

56
import type {
@@ -32,7 +33,25 @@ export const basicEventInfoCached = createCache({
3233
async get(eventSlug: EventSlug) {
3334
// First query general event information
3435
const event = await Event.scope("user").findOne({
35-
where: { slug: eventSlug },
36+
where: {
37+
slug: eventSlug,
38+
// are not drafts,
39+
draft: false,
40+
// and either:
41+
[Op.or]: {
42+
// closed less than a week ago
43+
registrationEndDate: {
44+
[Op.gt]: moment().subtract(7, "days").toDate(),
45+
},
46+
// or happened less than a week ago
47+
date: {
48+
[Op.gt]: moment().subtract(7, "days").toDate(),
49+
},
50+
endDate: {
51+
[Op.gt]: moment().subtract(7, "days").toDate(),
52+
},
53+
},
54+
},
3655
attributes: eventGetEventAttrs,
3756
include: [
3857
{

packages/ilmomasiina-backend/src/routes/events/getEventsList.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
2-
import { col, fn, Order } from "sequelize";
2+
import { col, fn, Op, Order, WhereOptions } from "sequelize";
33

44
import type { AdminEventListResponse, EventListQuery, UserEventListResponse } from "@tietokilta/ilmomasiina-models";
55
import { adminEventListEventAttrs, eventListEventAttrs } from "@tietokilta/ilmomasiina-models/dist/attrs/event";
@@ -24,8 +24,19 @@ function eventOrder(): Order {
2424
export const eventsListForUserCached = createCache({
2525
maxAgeMs: 1000,
2626
maxPendingAgeMs: 2000,
27-
async get(category?: string) {
28-
const where = category ? { category } : {};
27+
async get(category?: string, since?: Date) {
28+
const filters: WhereOptions = {};
29+
if (category) {
30+
filters.category = category;
31+
}
32+
if (since) {
33+
filters.date = {
34+
[Op.gt]: since,
35+
};
36+
}
37+
const where = {
38+
[Op.and]: filters,
39+
};
2940

3041
const events = await Event.scope("user").findAll({
3142
attributes: eventListEventAttrs,

0 commit comments

Comments
 (0)