Skip to content

Commit 857dbcc

Browse files
committed
fix: notif stack, hackspace points for check in
1 parent 93b9a1f commit 857dbcc

5 files changed

Lines changed: 50 additions & 4 deletions

File tree

app/components/NotifStack.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</div>
66

77
<!-- Notif list -->
8-
<div class="flex w-full flex-col gap-2 text-lg">
8+
<div class="flex max-h-80 w-full flex-col gap-2 overflow-scroll text-lg">
99
<div
1010
v-if="!error"
1111
v-for="announcement in sortedAnnouncements"

scripts/checkInHackspacePoints.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { eq } from 'drizzle-orm';
2+
import { db } from '~~/server/src/drizzle';
3+
import { eventCheckIn } from '~~/server/src/event/schema';
4+
import { userHackspace } from '~~/server/src/hackspace/schema';
5+
6+
type Points = {
7+
[userId: string]: number;
8+
};
9+
10+
const allCheckIns = await db.select().from(eventCheckIn);
11+
12+
const hackspacePoints: Points = {};
13+
14+
for (const checkIn of allCheckIns) {
15+
const { userId } = checkIn;
16+
17+
hackspacePoints[userId] = (hackspacePoints[userId] || 0) + 5;
18+
}
19+
20+
for (const user of Object.keys(hackspacePoints)) {
21+
await db
22+
.update(userHackspace)
23+
.set({
24+
points: hackspacePoints[user]
25+
})
26+
.where(eq(userHackspace.userId, user));
27+
}

server/src/event/index.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { and, asc, eq } from 'drizzle-orm';
1212
import { z } from 'zod';
1313
import { simpleValidator } from '../validators';
1414
import { users } from '../auth/schema';
15+
import { userHackspace } from '../hackspace/schema';
1516

1617
const event = factory
1718
.createApp()
@@ -134,7 +135,24 @@ const event = factory
134135
.where(eq(users.id, body.userId));
135136
if (userExists.length === 0) return ctx.text('User does not exist.', 404);
136137

137-
await db.insert(eventCheckIn).values(body);
138+
// Get hackspace
139+
const hackspaces = await db
140+
.select()
141+
.from(userHackspace)
142+
.where(eq(userHackspace.userId, body.userId));
143+
144+
await db.transaction(async tx => {
145+
if (hackspaces.length === 1) {
146+
await tx
147+
.update(userHackspace)
148+
.set({
149+
points: hackspaces[0]!.points + 5
150+
})
151+
.where(eq(userHackspace.userId, body.userId));
152+
}
153+
154+
await tx.insert(eventCheckIn).values(body);
155+
});
138156

139157
return ctx.json(null, 201);
140158
}

server/src/profile/__tests__/getDiscord.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('Profiles module > GET /discord/:id', async () => {
5252
expect(res).toEqual({
5353
id: hackerId,
5454
name: 'Jay',
55-
hackspace: 'QTR'
55+
hackspace: null
5656
});
5757
});
5858

server/src/profile/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,11 @@ const profile = factory
433433
.select({
434434
id: profiles.id,
435435
name: users.name,
436-
hackspace: sql<string>`'QTR'`
436+
hackspace: userHackspace.hackspace
437437
})
438438
.from(profiles)
439439
.innerJoin(users, eq(users.id, profiles.id))
440+
.leftJoin(userHackspace, eq(users.id, userHackspace.userId))
440441
.where(eq(profiles.discord_id, discordId));
441442

442443
if (dbRes.length < 1) {

0 commit comments

Comments
 (0)