Skip to content

Commit a7c649a

Browse files
committed
chore: remove postinstall script
1 parent 28e5390 commit a7c649a

File tree

9 files changed

+564
-146
lines changed

9 files changed

+564
-146
lines changed

apps/rpc/src/modules/event/event-repository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { DBHandle, Prisma, findFeaturedEvents } from "@dotkomonline/db"
1+
import { type DBHandle, type Prisma, sql } from "@dotkomonline/db"
22
import {
33
type AttendanceId,
44
type BaseEvent,
@@ -333,7 +333,7 @@ export function getEventRepository(): EventRepository {
333333
Past events are not featured. We would rather have no featured events than "stale" events.
334334
*/
335335

336-
const events = await handle.$queryRawTyped(findFeaturedEvents(offset, limit))
336+
const events = await handle.$queryRawTyped(sql.findFeaturedEvents(offset, limit))
337337

338338
return parseOrReport(
339339
z.preprocess((data) => snakeCaseToCamelCase(data), BaseEventSchema.array()),

packages/db/generated/prisma/internal/class.ts

Lines changed: 13 additions & 2 deletions
Large diffs are not rendered by default.

packages/db/generated/prisma/internal/prismaNamespace.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2974,6 +2974,10 @@ export type TypeMap<ExtArgs extends runtime.Types.Extensions.InternalArgs = runt
29742974
args: [query: string, ...values: any[]],
29752975
result: any
29762976
}
2977+
$queryRawTyped: {
2978+
args: runtime.UnknownTypedSql,
2979+
result: JsonObject
2980+
}
29772981
}
29782982
}
29792983
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
/* !!! This is code generated by Prisma. Do not edit directly. !!! */
3+
/* eslint-disable */
4+
// biome-ignore-all lint: generated file
5+
// @ts-nocheck
6+
export { type $DbEnums } from "./sql/$DbEnums"
7+
8+
export * from "./sql/findFeaturedEvents"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
/* !!! This is code generated by Prisma. Do not edit directly. !!! */
3+
/* eslint-disable */
4+
// biome-ignore-all lint: generated file
5+
// @ts-nocheck
6+
export interface $DbEnums {
7+
membership_type: "BACHELOR_STUDENT" | "MASTER_STUDENT" | "PHD_STUDENT" | "KNIGHT" | "SOCIAL_MEMBER" | "OTHER"
8+
membership_specialization: "ARTIFICIAL_INTELLIGENCE" | "DATABASE_AND_SEARCH" | "INTERACTION_DESIGN" | "SOFTWARE_ENGINEERING" | "UNKNOWN"
9+
group_type: "COMMITTEE" | "NODE_COMMITTEE" | "ASSOCIATED" | "INTEREST_GROUP"
10+
group_member_visibility: "ALL_MEMBERS" | "WITH_ROLES" | "LEADER" | "NONE"
11+
GroupRecruitmentMethod: "NONE" | "SPRING_APPLICATION" | "AUTUMN_APPLICATION" | "GENERAL_ASSEMBLY" | "NOMINATION" | "OTHER"
12+
group_role_type: "LEADER" | "PUNISHER" | "TREASURER" | "COSMETIC" | "DEPUTY_LEADER" | "TRUSTEE" | "EMAIL_ONLY"
13+
event_status: "DRAFT" | "PUBLIC" | "DELETED"
14+
event_type: "GENERAL_ASSEMBLY" | "COMPANY" | "ACADEMIC" | "SOCIAL" | "INTERNAL" | "OTHER" | "WELCOME"
15+
MarkType: "MANUAL" | "LATE_ATTENDANCE" | "MISSED_ATTENDANCE" | "MISSING_FEEDBACK" | "MISSING_PAYMENT"
16+
employment_type: "PARTTIME" | "FULLTIME" | "SUMMER_INTERNSHIP" | "OTHER"
17+
task_type: "RESERVE_ATTENDEE" | "CHARGE_ATTENDEE" | "MERGE_ATTENDANCE_POOLS" | "VERIFY_PAYMENT" | "VERIFY_FEEDBACK_ANSWERED" | "SEND_FEEDBACK_FORM_EMAILS" | "VERIFY_ATTENDEE_ATTENDED"
18+
task_status: "PENDING" | "RUNNING" | "COMPLETED" | "FAILED" | "CANCELED"
19+
feedback_question_type: "TEXT" | "LONGTEXT" | "RATING" | "CHECKBOX" | "SELECT" | "MULTISELECT"
20+
deregister_reason_type: "SCHOOL" | "WORK" | "ECONOMY" | "TIME" | "SICK" | "NO_FAMILIAR_FACES" | "OTHER"
21+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
/* !!! This is code generated by Prisma. Do not edit directly. !!! */
3+
/* eslint-disable */
4+
// biome-ignore-all lint: generated file
5+
// @ts-nocheck
6+
import * as $runtime from "@prisma/client/runtime/client"
7+
import { type $DbEnums } from "./$DbEnums"
8+
9+
/**
10+
* @param offset
11+
* @param limit
12+
*/
13+
export const findFeaturedEvents = $runtime.makeTypedQueryFactory("\n\n\n\nWITH\ncapacities AS (\nSELECT\n\"attendanceId\",\nSUM(\"capacity\") AS sum\nFROM \"attendance_pool\"\nGROUP BY \"attendanceId\"\n),\n\nattendees AS (\nSELECT\n\"attendanceId\",\nCOUNT(*) AS count\nFROM \"attendee\"\nGROUP BY \"attendanceId\"\n)\n\nSELECT\n\"event\".*,\nCOALESCE(capacities.sum, 0) AS \"totalCapacity\",\nCOALESCE(attendees.count, 0) AS \"attendeeCount\",\n\nCASE \"event\".\"type\"\nWHEN 'GENERAL_ASSEMBLY' THEN 1\nWHEN 'COMPANY' THEN 2\nWHEN 'ACADEMIC' THEN 2\nELSE 3\nEND AS \"typeRank\",\n\nCASE\nWHEN \"event\".\"attendanceId\" IS NOT NULL\nAND NOW() BETWEEN attendance.\"registerStart\" AND attendance.\"registerEnd\"\nAND COALESCE(capacities.sum, 0) > 0\nAND COALESCE(attendees.count, 0) < COALESCE(capacities.sum, 0)\nTHEN 1\n\nWHEN \"event\".\"attendanceId\" IS NOT NULL\nAND NOW() < attendance.\"registerStart\"\nTHEN 2\n\nWHEN \"event\".\"attendanceId\" IS NULL\nOR COALESCE(capacities.sum, 0) = 0\nTHEN 3\n\nWHEN \"event\".\"attendanceId\" IS NOT NULL\nAND COALESCE(capacities.sum, 0) > 0\nAND COALESCE(attendees.count, 0) >= COALESCE(capacities.sum, 0)\nTHEN 4\n\nELSE 4\nEND AS \"registrationBucket\"\n\nFROM \"event\"\nLEFT JOIN \"attendance\"\nON \"attendance\".\"id\" = \"event\".\"attendanceId\"\nLEFT JOIN capacities\nON capacities.\"attendanceId\" = \"event\".\"attendanceId\"\nLEFT JOIN attendees\nON attendees.\"attendanceId\" = \"event\".\"attendanceId\"\n\nWHERE\n\"event\".\"status\" = 'PUBLIC'\nAND \"event\".\"start\" > NOW()\n\nORDER BY\n\"typeRank\" ASC,\n\"registrationBucket\" ASC,\n\"event\".\"start\" ASC\n\nOFFSET $1\nLIMIT $2;") as (offset: number, limit: number) => $runtime.TypedSql<findFeaturedEvents.Parameters, findFeaturedEvents.Result>
14+
15+
export namespace findFeaturedEvents {
16+
export type Parameters = [offset: number, limit: number]
17+
export type Result = {
18+
id: string
19+
title: string
20+
start: Date
21+
end: Date
22+
status: $DbEnums["event_status"]
23+
description: string
24+
shortDescription: string | null
25+
imageUrl: string | null
26+
locationTitle: string | null
27+
locationAddress: string | null
28+
locationLink: string | null
29+
attendanceId: string | null
30+
type: $DbEnums["event_type"]
31+
createdAt: Date
32+
updatedAt: Date
33+
metadataImportId: number | null
34+
parentId: string | null
35+
markForMissedAttendance: boolean
36+
totalCapacity: bigint | null
37+
attendeeCount: bigint | null
38+
typeRank: number | null
39+
registrationBucket: number | null
40+
}
41+
}

packages/db/prisma/sql/findFeaturedEvents.sql

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,80 +22,80 @@
2222
WITH
2323
capacities AS (
2424
SELECT
25-
"attendanceId",
25+
attendance_id,
2626
SUM("capacity") AS sum
27-
FROM "attendance_pool"
28-
GROUP BY "attendanceId"
27+
FROM attendance_pool
28+
GROUP BY attendance_id
2929
),
3030

3131
attendees AS (
3232
SELECT
33-
"attendanceId",
33+
attendance_id,
3434
COUNT(*) AS count
35-
FROM "attendee"
36-
GROUP BY "attendanceId"
35+
FROM attendee
36+
GROUP BY attendance_id
3737
)
3838

3939
SELECT
40-
"event".*,
41-
COALESCE(capacities.sum, 0) AS "totalCapacity",
42-
COALESCE(attendees.count, 0) AS "attendeeCount",
40+
event.*,
41+
COALESCE(capacities.sum, 0) AS total_capacity,
42+
COALESCE(attendees.count, 0) AS attendee_count,
4343

4444
-- 1,2,3: event type buckets
45-
CASE "event"."type"
45+
CASE event."type"
4646
WHEN 'GENERAL_ASSEMBLY' THEN 1
4747
WHEN 'COMPANY' THEN 2
4848
WHEN 'ACADEMIC' THEN 2
4949
ELSE 3
50-
END AS "typeRank",
50+
END AS type_rank,
5151

5252
-- 1-4: registration buckets
5353
CASE
5454
-- 1. Future, registration open and not full AND capacities limited (> 0)
55-
WHEN "event"."attendanceId" IS NOT NULL
56-
AND NOW() BETWEEN attendance."registerStart" AND attendance."registerEnd"
55+
WHEN event.attendance_id IS NOT NULL
56+
AND NOW() BETWEEN attendance.register_start AND attendance.register_end
5757
AND COALESCE(capacities.sum, 0) > 0
5858
AND COALESCE(attendees.count, 0) < COALESCE(capacities.sum, 0)
5959
THEN 1
6060

6161
-- 2. Future, registration not started yet (capacities doesn't matter)
62-
WHEN "event"."attendanceId" IS NOT NULL
63-
AND NOW() < attendance."registerStart"
62+
WHEN event.attendance_id IS NOT NULL
63+
AND NOW() < attendance.register_start
6464
THEN 2
6565

6666
-- 3. Future, no registration OR unlimited capacities (total capacities = 0)
67-
WHEN "event"."attendanceId" IS NULL
67+
WHEN event.attendance_id IS NULL
6868
OR COALESCE(capacities.sum, 0) = 0
6969
THEN 3
7070

7171
-- 4. Future, registration full (status doesn't matter)
72-
WHEN "event"."attendanceId" IS NOT NULL
72+
WHEN event.attendance_id IS NOT NULL
7373
AND COALESCE(capacities.sum, 0) > 0
7474
AND COALESCE(attendees.count, 0) >= COALESCE(capacities.sum, 0)
7575
THEN 4
7676

7777
-- Fallback: treat as bucket 4
7878
ELSE 4
79-
END AS "registrationBucket"
79+
END AS registration_bucket
8080

81-
FROM "event"
81+
FROM event
8282
LEFT JOIN "attendance"
83-
ON "attendance"."id" = "event"."attendanceId"
83+
ON "attendance"."id" = event.attendance_id
8484
LEFT JOIN capacities
85-
ON capacities."attendanceId" = "event"."attendanceId"
85+
ON capacities.attendance_id = event.attendance_id
8686
LEFT JOIN attendees
87-
ON attendees."attendanceId" = "event"."attendanceId"
87+
ON attendees.attendance_id = event.attendance_id
8888

8989
WHERE
90-
"event"."status" = 'PUBLIC'
90+
event.status = 'PUBLIC'
9191
-- Past events are not featured
92-
AND "event"."start" > NOW()
92+
AND event.start > NOW()
9393

9494
ORDER BY
95-
"typeRank" ASC,
96-
"registrationBucket" ASC,
95+
type_rank ASC,
96+
registration_bucket ASC,
9797
-- Tie breaker with earlier events first
98-
"event"."start" ASC
98+
event."start" ASC
9999

100100
OFFSET $1
101101
LIMIT $2;

packages/db/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export const createPrisma = (databaseUrl: string) => {
1010
return new PrismaClient({ adapter })
1111
}
1212

13+
export * as sql from "../generated/prisma/sql"
1314
export * from "../generated/prisma/client"

0 commit comments

Comments
 (0)