Skip to content

Commit

Permalink
recursively view tournament registrations
Browse files Browse the repository at this point in the history
  • Loading branch information
kearfy committed Apr 14, 2024
1 parent c8d57f7 commit 5e64ec0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ function useData({
/* surql */ `
LET $event = <record<event>> $event;
SELECT * FROM $event<-attends
SELECT * FROM attends
WHERE $event IN tournament_path
START $start
LIMIT $limit
FETCH in, out, players.*;
SELECT count() FROM $event<-attends
SELECT count() FROM attends
WHERE $event IN tournament_path
GROUP ALL;
`,
{
Expand Down
6 changes: 6 additions & 0 deletions src/schema/relations/attends.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ const attends = /* surrealql */ `
};
DEFINE FIELD players.* ON attends TYPE record<user>;
DEFINE FIELD tournament_path ON attends TYPE array<record<event>>
READONLY
VALUE out.tournament_path
DEFAULT out.tournament_path;
DEFINE FIELD created ON attends TYPE datetime VALUE $before OR time::now() DEFAULT time::now();
DEFINE FIELD updated ON attends TYPE datetime VALUE time::now() DEFAULT time::now();
Expand Down Expand Up @@ -80,6 +85,7 @@ export const Attends = z.object({
out: record('event'),
confirmed: z.boolean(),
players: z.array(record('user')),
tournament_path: z.array(record('event')),
created: z.coerce.date(),
updated: z.coerce.date(),
});
Expand Down
9 changes: 9 additions & 0 deletions src/schema/resources/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const event = /* surrealql */ `
DEFINE FIELD discoverable ON event TYPE bool DEFAULT true;
DEFINE FIELD published ON event TYPE bool DEFAULT false;
DEFINE FIELD tournament ON event TYPE option<record<event>>;
DEFINE FIELD tournament_path ON event TYPE array<record<event>> DEFAULT [] PERMISSIONS FOR update NONE;
DEFINE FIELD is_tournament ON event VALUE {
RETURN IF id {
LET $id = meta::id(id);
Expand Down Expand Up @@ -84,6 +85,7 @@ export const Event = z.object({
discoverable: z.boolean(),
published: z.boolean(),
tournament: record('event').optional(),
tournament_path: z.array(record('event')),
root_for_org: z.boolean(),
is_tournament: z.boolean(),

Expand Down Expand Up @@ -159,6 +161,12 @@ const populate_initial_computed = /* surrealql */ `
};
`;

const populate_tournament_path = /* surrealql */ `
DEFINE EVENT populate_tournament_path ON event WHEN $event = "CREATE" THEN {
UPDATE $value.id SET computed = array::append(($value.tournament.tournament_path ?? []), $value.id);
};
`;

export default [
event,
log,
Expand All @@ -167,4 +175,5 @@ export default [
update_computed_self,
update_computed_nested,
populate_initial_computed,
populate_tournament_path,
].join('\n\n');

0 comments on commit 5e64ec0

Please sign in to comment.