Skip to content

Commit 374f887

Browse files
committed
fix(hyperboards): make hyperboards queryable by admin_address using view
1 parent 27ff7c3 commit 374f887

File tree

8 files changed

+161
-7
lines changed

8 files changed

+161
-7
lines changed

src/controllers/HyperboardController.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,14 @@ export class HyperboardController extends Controller {
630630
}
631631

632632
const { signature, adminAddress } = parsedBody.data;
633-
const chainId = hyperboard.chain_ids[0];
633+
const chainId = hyperboard.chain_ids?.[0];
634+
if (!chainId) {
635+
this.setStatus(400);
636+
return {
637+
success: false,
638+
message: "Hyperboard must have a chain id",
639+
};
640+
}
634641
const success = await verifyAuthSignedData({
635642
address: adminAddress as `0x${string}`,
636643
signature: signature as `0x${string}`,
@@ -700,6 +707,14 @@ export class HyperboardController extends Controller {
700707
};
701708
}
702709

710+
if (!hyperboard.chain_ids) {
711+
this.setStatus(400);
712+
return {
713+
success: false,
714+
message: "Hyperboard must have a chain id",
715+
};
716+
}
717+
703718
try {
704719
await this.hyperboardsService.upsertHyperboard([
705720
{
@@ -967,7 +982,14 @@ export class HyperboardController extends Controller {
967982
const { data: admins } =
968983
await this.hyperboardsService.getHyperboardAdmins(hyperboardId);
969984

970-
const chain_id = hyperboard.chain_ids[0];
985+
const chain_id = hyperboard.chain_ids?.[0];
986+
if (!chain_id) {
987+
this.setStatus(400);
988+
return {
989+
success: false,
990+
message: "Hyperboard must have a chain id",
991+
};
992+
}
971993

972994
if (
973995
!admins.find(

src/lib/graphql/whereFieldDefinitions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export const WhereFieldDefinitions = {
117117
fields: {
118118
id: "string",
119119
chain_ids: "numberArray",
120+
admin_address: "string",
120121
},
121122
},
122123
Metadata: {

src/services/database/entities/HyperboardEntityService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export type HyperboardBlueprintMetadataInsert = Insertable<
5050
@injectable()
5151
export class HyperboardService {
5252
private entityService: EntityService<
53-
DataDatabase["hyperboards"],
53+
DataDatabase["hyperboards_with_admins"],
5454
GetHyperboardsArgs
5555
>;
5656

@@ -61,9 +61,9 @@ export class HyperboardService {
6161
) {
6262
this.entityService = createEntityService<
6363
DataDatabase,
64-
"hyperboards",
64+
"hyperboards_with_admins",
6565
GetHyperboardsArgs
66-
>("hyperboards", "HyperboardEntityService", kyselyData);
66+
>("hyperboards_with_admins", "HyperboardEntityService", kyselyData);
6767
}
6868

6969
/**

src/services/database/strategies/HyperboardsQueryStrategy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import { QueryStrategy } from "./QueryStrategy.js";
2323
*/
2424
export class HyperboardsQueryStrategy extends QueryStrategy<
2525
DataDatabase,
26-
"hyperboards",
26+
"hyperboards_with_admins",
2727
GetHyperboardsArgs
2828
> {
29-
protected readonly tableName = "hyperboards" as const;
29+
protected readonly tableName = "hyperboards_with_admins" as const;
3030

3131
/**
3232
* Builds a query to retrieve hyperboard data.

src/services/database/strategies/QueryStrategyFactory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export class QueryStrategyFactory {
7373
fractions: FractionsQueryStrategy,
7474
fractions_view: FractionsQueryStrategy,
7575
hyperboards: HyperboardsQueryStrategy,
76+
hyperboards_with_admins: HyperboardsQueryStrategy,
7677
metadata: MetadataQueryStrategy,
7778
orders: MarketplaceOrdersQueryStrategy,
7879
marketplace_orders: MarketplaceOrdersQueryStrategy,

src/types/supabaseData.ts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ export type Database = {
132132
referencedRelation: "collections";
133133
referencedColumns: ["id"];
134134
},
135+
{
136+
foreignKeyName: "collection_admins_collection_id_fkey";
137+
columns: ["collection_id"];
138+
isOneToOne: false;
139+
referencedRelation: "collections_with_admins";
140+
referencedColumns: ["id"];
141+
},
135142
];
136143
};
137144
collection_blueprints: {
@@ -172,6 +179,13 @@ export type Database = {
172179
referencedRelation: "collections";
173180
referencedColumns: ["id"];
174181
},
182+
{
183+
foreignKeyName: "collection_blueprints_collection_id_fkey";
184+
columns: ["collection_id"];
185+
isOneToOne: false;
186+
referencedRelation: "collections_with_admins";
187+
referencedColumns: ["id"];
188+
},
175189
];
176190
};
177191
collections: {
@@ -307,6 +321,13 @@ export type Database = {
307321
referencedRelation: "hyperboards";
308322
referencedColumns: ["id"];
309323
},
324+
{
325+
foreignKeyName: "hyperboard_admins_hyperboard_id_fkey";
326+
columns: ["hyperboard_id"];
327+
isOneToOne: false;
328+
referencedRelation: "hyperboards_with_admins";
329+
referencedColumns: ["id"];
330+
},
310331
];
311332
};
312333
hyperboard_blueprint_metadata: {
@@ -346,13 +367,27 @@ export type Database = {
346367
referencedRelation: "collections";
347368
referencedColumns: ["id"];
348369
},
370+
{
371+
foreignKeyName: "hyperboard_blueprint_metadata_collection_id_fkey";
372+
columns: ["collection_id"];
373+
isOneToOne: false;
374+
referencedRelation: "collections_with_admins";
375+
referencedColumns: ["id"];
376+
},
349377
{
350378
foreignKeyName: "hyperboard_blueprint_metadata_hyperboard_id_fkey";
351379
columns: ["hyperboard_id"];
352380
isOneToOne: false;
353381
referencedRelation: "hyperboards";
354382
referencedColumns: ["id"];
355383
},
384+
{
385+
foreignKeyName: "hyperboard_blueprint_metadata_hyperboard_id_fkey";
386+
columns: ["hyperboard_id"];
387+
isOneToOne: false;
388+
referencedRelation: "hyperboards_with_admins";
389+
referencedColumns: ["id"];
390+
},
356391
];
357392
};
358393
hyperboard_collections: {
@@ -385,13 +420,27 @@ export type Database = {
385420
referencedRelation: "hyperboards";
386421
referencedColumns: ["id"];
387422
},
423+
{
424+
foreignKeyName: "hyperboard_registries_hyperboard_id_fkey";
425+
columns: ["hyperboard_id"];
426+
isOneToOne: false;
427+
referencedRelation: "hyperboards_with_admins";
428+
referencedColumns: ["id"];
429+
},
388430
{
389431
foreignKeyName: "hyperboard_registries_registries_id_fk";
390432
columns: ["collection_id"];
391433
isOneToOne: false;
392434
referencedRelation: "collections";
393435
referencedColumns: ["id"];
394436
},
437+
{
438+
foreignKeyName: "hyperboard_registries_registries_id_fk";
439+
columns: ["collection_id"];
440+
isOneToOne: false;
441+
referencedRelation: "collections_with_admins";
442+
referencedColumns: ["id"];
443+
},
395444
];
396445
};
397446
hyperboard_hypercert_metadata: {
@@ -424,13 +473,27 @@ export type Database = {
424473
referencedRelation: "collections";
425474
referencedColumns: ["id"];
426475
},
476+
{
477+
foreignKeyName: "hyperboard_hypercert_metadata_collection_id_fkey";
478+
columns: ["collection_id"];
479+
isOneToOne: false;
480+
referencedRelation: "collections_with_admins";
481+
referencedColumns: ["id"];
482+
},
427483
{
428484
foreignKeyName: "hyperboard_hypercert_metadata_hyperboard_id_fkey";
429485
columns: ["hyperboard_id"];
430486
isOneToOne: false;
431487
referencedRelation: "hyperboards";
432488
referencedColumns: ["id"];
433489
},
490+
{
491+
foreignKeyName: "hyperboard_hypercert_metadata_hyperboard_id_fkey";
492+
columns: ["hyperboard_id"];
493+
isOneToOne: false;
494+
referencedRelation: "hyperboards_with_admins";
495+
referencedColumns: ["id"];
496+
},
434497
{
435498
foreignKeyName: "hyperboard_hypercert_metadata_hypercert_id_collection_id_fkey";
436499
columns: ["hypercert_id", "collection_id"];
@@ -494,6 +557,13 @@ export type Database = {
494557
referencedRelation: "collections";
495558
referencedColumns: ["id"];
496559
},
560+
{
561+
foreignKeyName: "claims_registry_id_fkey";
562+
columns: ["collection_id"];
563+
isOneToOne: false;
564+
referencedRelation: "collections_with_admins";
565+
referencedColumns: ["id"];
566+
},
497567
];
498568
};
499569
marketplace_order_nonces: {
@@ -690,6 +760,37 @@ export type Database = {
690760
};
691761
Relationships: [];
692762
};
763+
collections_with_admins: {
764+
Row: {
765+
admin_address: string | null;
766+
admin_chain_id: number | null;
767+
avatar: string | null;
768+
chain_ids: number[] | null;
769+
created_at: string | null;
770+
description: string | null;
771+
display_name: string | null;
772+
hidden: boolean | null;
773+
id: string | null;
774+
name: string | null;
775+
};
776+
Relationships: [];
777+
};
778+
hyperboards_with_admins: {
779+
Row: {
780+
admin_address: string | null;
781+
admin_chain_id: number | null;
782+
avatar: string | null;
783+
background_image: string | null;
784+
chain_ids: number[] | null;
785+
created_at: string | null;
786+
display_name: string | null;
787+
grayscale_images: boolean | null;
788+
id: string | null;
789+
name: string | null;
790+
tile_border_color: string | null;
791+
};
792+
Relationships: [];
793+
};
693794
};
694795
Functions: {
695796
default_sponsor_metadata_by_address: {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
create view hyperboards_with_admins as
2+
select hyperboards.id,
3+
hyperboards.created_at,
4+
hyperboards.name,
5+
hyperboards.background_image,
6+
hyperboards.grayscale_images,
7+
hyperboards.tile_border_color,
8+
hyperboards.chain_ids,
9+
u.address AS admin_address,
10+
u.chain_id AS admin_chain_id,
11+
u.avatar,
12+
u.display_name
13+
from public.hyperboards
14+
join public.hyperboard_admins ha on hyperboards.id = ha.hyperboard_id
15+
join public.users u on ha.user_id = u.id
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
create view collections_with_admins as
2+
select collections.id,
3+
collections.created_at,
4+
collections.name,
5+
collections.description,
6+
collections.hidden,
7+
collections.chain_ids,
8+
u.address AS admin_address,
9+
u.chain_id AS admin_chain_id,
10+
u.avatar,
11+
u.display_name
12+
from public.collections
13+
join public.collection_admins ca on collections.id = ca.collection_id
14+
join public.users u on ca.user_id = u.id

0 commit comments

Comments
 (0)