Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiAbdou committed Jul 26, 2024
1 parent 7003288 commit 11cc39f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ import { Route } from '@/shared/constants';
import { ensureUserAuthenticated, user } from '@/shared/session.server';

export async function loader({ params, request }: LoaderFunctionArgs) {
await ensureUserAuthenticated(request);
const session = await ensureUserAuthenticated(request);

const event = await getEvent(
params.id as string,
['events.endTime', 'events.name', 'events.startTime'],
{
include: ['isCheckedIn'],
memberId: user(session),
type: 'irl',
}
);
Expand Down
7 changes: 2 additions & 5 deletions packages/core/src/modules/event/event.core.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { sql } from 'kysely';

import { job } from '@/infrastructure/bull/use-cases/job';
import { db } from '@/infrastructure/database';

Expand Down Expand Up @@ -27,11 +25,10 @@ export async function checkIntoEvent({
name: member.firstName + ' ' + member.lastName,
studentId: memberId,
})
.returning(sql<boolean>`xmax = 0`.as('inserted'))
.onConflict((oc) => oc.doNothing())
.executeTakeFirstOrThrow();
.executeTakeFirst();

return record.inserted;
return !!Number(record.numInsertedOrUpdatedRows);
});

if (isNewCheckIn) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/modules/event/queries/get-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function getEvent<
>(
id: string,
selections: Selection[],
{ include, memberId, type, withIsRegistered }: GetEventOptions = {}
{ include = [], memberId, type, withIsRegistered }: GetEventOptions = {}
) {
const result = await db
.selectFrom('events')
Expand All @@ -34,7 +34,7 @@ export async function getEvent<
.as('isRegistered');
});
})
.$if(!!include?.includes('isCheckedIn') && !!memberId, (qb) => {
.$if(include.includes('isCheckedIn') && !!memberId, (qb) => {
return qb.select((eb) => {
return eb
.exists(
Expand Down

0 comments on commit 11cc39f

Please sign in to comment.