Skip to content

Commit cbefb22

Browse files
authored
fix: fix order of operations when updating hyperboard (#173)
1 parent 8e2b2a3 commit cbefb22

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/controllers/HyperboardController.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,10 @@ export class HyperboardController extends Controller {
113113
}),
114114
),
115115
backgroundImg: z
116-
.string()
117-
.url("Background image URL is not valid")
116+
.union([
117+
z.string().url("Background image URL is not valid"),
118+
z.literal(""),
119+
])
118120
.optional(),
119121
borderColor: z
120122
.string()
@@ -437,8 +439,10 @@ export class HyperboardController extends Controller {
437439
}),
438440
),
439441
backgroundImg: z
440-
.string()
441-
.url("Background image URL is not valid")
442+
.union([
443+
z.string().url("Background image URL is not valid"),
444+
z.literal(""),
445+
])
442446
.optional(),
443447
borderColor: z
444448
.string()
@@ -587,16 +591,8 @@ export class HyperboardController extends Controller {
587591
collection.id,
588592
);
589593
}
590-
// Update metadata anyway because they are not collection specific
591-
await dataService.upsertHyperboardHypercertMetadata(
592-
collection.hypercerts.map((hc) => ({
593-
hypercert_id: hc.hypercertId,
594-
hyperboard_id: hyperboardId,
595-
collection_id: currentCollection.id,
596-
display_size: hc.factor,
597-
})),
598-
);
599594

595+
// Update metadata anyway because they are not collection specific
600596
const currentUserIsAdminForCollection =
601597
currentCollection.collection_admins
602598
.flatMap((x) => x.admins)
@@ -622,6 +618,15 @@ export class HyperboardController extends Controller {
622618
collection_id: currentCollection.id,
623619
})),
624620
);
621+
622+
await dataService.upsertHyperboardHypercertMetadata(
623+
collection.hypercerts.map((hc) => ({
624+
hypercert_id: hc.hypercertId,
625+
hyperboard_id: hyperboardId,
626+
collection_id: currentCollection.id,
627+
display_size: hc.factor,
628+
})),
629+
);
625630
}
626631
} catch (e) {
627632
console.error(e);

src/services/SupabaseDataService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,9 @@ export class SupabaseDataService {
304304
oc
305305
.columns(["hyperboard_id", "hypercert_id", "collection_id"])
306306
.doUpdateSet((eb) => ({
307-
hyperboard_id: eb.ref("excluded.hyperboard_id"),
308307
hypercert_id: eb.ref("excluded.hypercert_id"),
308+
collection_id: eb.ref("excluded.collection_id"),
309+
hyperboard_id: eb.ref("excluded.hyperboard_id"),
309310
display_size: eb.ref("excluded.display_size"),
310311
})),
311312
)

0 commit comments

Comments
 (0)