Skip to content

Commit f8473bf

Browse files
committed
Corrections, linting, etc.
1 parent b06333c commit f8473bf

3 files changed

Lines changed: 17 additions & 23 deletions

File tree

apps/website/test/integration/list-group-members.test.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ const signedInClient = async (spaceId: number): Promise<DGSupabaseClient> => {
3333
describe("list group members flow", { tags: ["database"] }, () => {
3434
let spaceId1: number;
3535
let spaceId2: number;
36-
let spaceAccountId1: number;
3736
let spaceAccountUuid1: string;
38-
let spaceAccountId2: number;
3937
let spaceAccountUuid2: string;
4038
let client1: DGSupabaseClient;
4139
let client2: DGSupabaseClient;
@@ -64,7 +62,6 @@ describe("list group members flow", { tags: ["database"] }, () => {
6462
assert(!accountReq1.error);
6563
assert(accountReq1.data);
6664
assert(accountReq1.data.dg_account);
67-
spaceAccountId1 = accountReq1.data.id;
6865
spaceAccountUuid1 = accountReq1.data.dg_account;
6966
const s2 = await fetchOrCreateSpaceDirect({
7067
name: "vitest-s2",
@@ -88,7 +85,6 @@ describe("list group members flow", { tags: ["database"] }, () => {
8885
assert(!accountReq2.error);
8986
assert(accountReq2.data);
9087
assert(accountReq2.data.dg_account);
91-
spaceAccountId2 = accountReq2.data.id;
9288
spaceAccountUuid2 = accountReq2.data.dg_account;
9389
});
9490

@@ -109,14 +105,14 @@ describe("list group members flow", { tags: ["database"] }, () => {
109105
// Step 1: user1 creates a group
110106
const groupId = await createGroup(client1, "vitest-invite-group");
111107
assert(groupId !== null, "createGroup should return a group ID");
112-
createdGroupId = groupId!;
108+
createdGroupId = groupId;
113109

114110
// Step 2: Add another member
115111
const { error: errorAddMember } = await client1
116112
.from("group_membership")
117113
.insert({
118-
member_id: spaceAccountUuid2,
119-
group_id: groupId,
114+
member_id: spaceAccountUuid2, // eslint-disable-line @typescript-eslint/naming-convention
115+
group_id: groupId, // eslint-disable-line @typescript-eslint/naming-convention
120116
admin: false,
121117
});
122118
assert(!errorAddMember);
@@ -125,17 +121,17 @@ describe("list group members flow", { tags: ["database"] }, () => {
125121
const { error: errorPublishSpace1 } = await client1
126122
.from("SpaceAccess")
127123
.insert({
128-
space_id: spaceId1,
129-
account_uid: groupId,
124+
space_id: spaceId1, // eslint-disable-line @typescript-eslint/naming-convention
125+
account_uid: groupId, // eslint-disable-line @typescript-eslint/naming-convention
130126
permissions: "partial",
131127
});
132128
assert(!errorPublishSpace1);
133129

134130
const { error: errorPublishSpace2 } = await client2
135131
.from("SpaceAccess")
136132
.insert({
137-
space_id: spaceId2,
138-
account_uid: groupId,
133+
space_id: spaceId2, // eslint-disable-line @typescript-eslint/naming-convention
134+
account_uid: groupId, // eslint-disable-line @typescript-eslint/naming-convention
139135
permissions: "partial",
140136
});
141137
assert(!errorPublishSpace2);
@@ -145,8 +141,7 @@ describe("list group members flow", { tags: ["database"] }, () => {
145141
const { data: data1, error: error1 } = await client1.rpc(
146142
"spaces_in_group",
147143
{
148-
// eslint-disable-next-line @typescript-eslint/naming-convention
149-
p_group_id: createdGroupId,
144+
p_group_id: createdGroupId, // eslint-disable-line @typescript-eslint/naming-convention
150145
},
151146
);
152147
assert(error1 === null, error1 ? error1.message : "");
@@ -164,8 +159,7 @@ describe("list group members flow", { tags: ["database"] }, () => {
164159
const { data: data2, error: error2 } = await client2.rpc(
165160
"spaces_in_group",
166161
{
167-
// eslint-disable-next-line @typescript-eslint/naming-convention
168-
p_group_id: createdGroupId,
162+
p_group_id: createdGroupId, // eslint-disable-line @typescript-eslint/naming-convention
169163
},
170164
);
171165
assert(error2 === null, error2 ? error2.message : "");

packages/database/supabase/migrations/20260512130625_group_members_function.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ CREATE TYPE public.group_space_info AS (
3838
admin boolean
3939
);
4040

41-
CREATE OR REPLACE FUNCTION public.spaces_in_group(p_group_id UUID) RETURNS SETOF public."Space"
41+
CREATE OR REPLACE FUNCTION public.spaces_in_group(p_group_id UUID) RETURNS SETOF public.group_space_info
4242
STABLE
4343
SET search_path = ''
4444
LANGUAGE sql AS $$
4545
SELECT sp.id, sp.name, sp.platform, gm.admin FROM public."Space" AS sp
46-
JOIN public.my_pseudo_accounts AS pa ON (sp.id = space_id)
46+
JOIN public.my_pseudo_accounts AS pa ON (sp.id = pa.space_id)
4747
JOIN public.group_membership AS gm ON (gm.member_id = pa.dg_account)
48-
JOIN public.group_membership AS gm2 ON (gm2.member_id = auth.uid() AND gm2.group_id = gm.group_id)
49-
AND gm.group_id = p_group_id;
48+
JOIN public.group_membership AS gm2 ON (gm2.group_id = gm.group_id)
49+
AND gm.group_id = p_group_id AND gm2.member_id = auth.uid();
5050
$$;

packages/database/supabase/schemas/account.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,15 +477,15 @@ CREATE TYPE public.group_space_info AS (
477477
admin boolean
478478
);
479479

480-
CREATE OR REPLACE FUNCTION public.spaces_in_group(p_group_id UUID) RETURNS SETOF public."Space"
480+
CREATE OR REPLACE FUNCTION public.spaces_in_group(p_group_id UUID) RETURNS SETOF public.group_space_info
481481
STABLE
482482
SET search_path = ''
483483
LANGUAGE sql AS $$
484484
SELECT sp.id, sp.name, sp.platform, gm.admin FROM public."Space" AS sp
485-
JOIN public.my_pseudo_accounts AS pa ON (sp.id = space_id)
485+
JOIN public.my_pseudo_accounts AS pa ON (sp.id = pa.space_id)
486486
JOIN public.group_membership AS gm ON (gm.member_id = pa.dg_account)
487-
JOIN public.group_membership AS gm2 ON (gm2.member_id = auth.uid() AND gm2.group_id = gm.group_id)
488-
AND gm.group_id = p_group_id;
487+
JOIN public.group_membership AS gm2 ON (gm2.group_id = gm.group_id)
488+
AND gm.group_id = p_group_id AND gm2.member_id = auth.uid();
489489
$$;
490490

491491
DROP POLICY IF EXISTS platform_account_policy ON public."PlatformAccount";

0 commit comments

Comments
 (0)