Skip to content

Commit 0211831

Browse files
authored
fix: update queries with tombStone check (#1340)
* update some queries * formatting * Update page.tsx * Update folder.ts
1 parent 722fd2f commit 0211831

File tree

5 files changed

+35
-10
lines changed

5 files changed

+35
-10
lines changed

apps/web/actions/organizations/add-videos.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
videos,
1111
} from "@cap/database/schema";
1212
import type { Organisation, Video } from "@cap/web-domain";
13-
import { and, eq, inArray } from "drizzle-orm";
13+
import { and, eq, inArray, isNull } from "drizzle-orm";
1414
import { revalidatePath } from "next/cache";
1515

1616
export async function addVideosToOrganization(
@@ -31,7 +31,12 @@ export async function addVideosToOrganization(
3131
const [organization] = await db()
3232
.select()
3333
.from(organizations)
34-
.where(eq(organizations.id, organizationId));
34+
.where(
35+
and(
36+
eq(organizations.id, organizationId),
37+
isNull(organizations.tombstoneAt),
38+
),
39+
);
3540

3641
if (!organization) {
3742
throw new Error("Organization not found");

apps/web/actions/spaces/get-user-videos.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getCurrentUser } from "@cap/database/auth/session";
55
import {
66
comments,
77
folders,
8+
organizations,
89
sharedVideos,
910
spaces,
1011
spaceVideos,
@@ -13,7 +14,7 @@ import {
1314
videoUploads,
1415
} from "@cap/database/schema";
1516
import type { Space } from "@cap/web-domain";
16-
import { and, desc, eq, sql } from "drizzle-orm";
17+
import { and, desc, eq, isNull, sql } from "drizzle-orm";
1718

1819
export async function getUserVideos(spaceId: Space.SpaceIdOrOrganisationId) {
1920
try {
@@ -64,7 +65,10 @@ export async function getUserVideos(spaceId: Space.SpaceIdOrOrganisationId) {
6465
)
6566
.leftJoin(folders, eq(sharedVideos.folderId, folders.id))
6667
.leftJoin(spaces, eq(folders.spaceId, spaces.id))
67-
.where(eq(videos.ownerId, userId))
68+
.leftJoin(organizations, eq(videos.orgId, organizations.id))
69+
.where(
70+
and(eq(videos.ownerId, userId), isNull(organizations.tombstoneAt)),
71+
)
6872
.groupBy(
6973
videos.id,
7074
videos.ownerId,
@@ -98,7 +102,10 @@ export async function getUserVideos(spaceId: Space.SpaceIdOrOrganisationId) {
98102
)
99103
.leftJoin(folders, eq(spaceVideos.folderId, folders.id))
100104
.leftJoin(spaces, eq(folders.spaceId, spaces.id))
101-
.where(eq(videos.ownerId, userId))
105+
.leftJoin(organizations, eq(videos.orgId, organizations.id))
106+
.where(
107+
and(eq(videos.ownerId, userId), isNull(organizations.tombstoneAt)),
108+
)
102109
.groupBy(
103110
videos.id,
104111
videos.ownerId,

apps/web/app/(org)/dashboard/caps/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ export default async function CapsPage(props: PageProps<"/dashboard/caps">) {
128128
and(
129129
eq(videos.ownerId, userId),
130130
eq(organizations.id, user.activeOrganizationId),
131+
isNull(organizations.tombstoneAt),
131132
),
132133
);
133134

@@ -185,6 +186,7 @@ export default async function CapsPage(props: PageProps<"/dashboard/caps">) {
185186
eq(videos.ownerId, userId),
186187
eq(videos.orgId, user.activeOrganizationId),
187188
isNull(videos.folderId),
189+
isNull(organizations.tombstoneAt),
188190
),
189191
)
190192
.groupBy(

apps/web/app/(org)/dashboard/spaces/[spaceId]/page.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
comments,
55
folders,
66
organizationMembers,
7+
organizations,
78
sharedVideos,
89
spaceMembers,
910
spaceVideos,
@@ -201,8 +202,13 @@ export default async function SharedCapsPage(props: {
201202
.leftJoin(comments, eq(videos.id, comments.videoId))
202203
.leftJoin(users, eq(videos.ownerId, users.id))
203204
.leftJoin(videoUploads, eq(videos.id, videoUploads.videoId))
205+
.leftJoin(organizations, eq(videos.orgId, organizations.id))
204206
.where(
205-
and(eq(spaceVideos.spaceId, spaceId), isNull(spaceVideos.folderId)),
207+
and(
208+
eq(spaceVideos.spaceId, spaceId),
209+
isNull(spaceVideos.folderId),
210+
isNull(organizations.tombstoneAt),
211+
),
206212
)
207213
.groupBy(
208214
videos.id,

apps/web/lib/folder.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ import {
1414
import { Database, ImageUploads } from "@cap/web-backend";
1515
import type { ImageUpload, Organisation, Space, Video } from "@cap/web-domain";
1616
import { CurrentUser, Folder } from "@cap/web-domain";
17-
import { and, desc, eq } from "drizzle-orm";
17+
import { and, desc, eq, isNull } from "drizzle-orm";
1818
import { sql } from "drizzle-orm/sql";
1919
import { Effect } from "effect";
20-
import { runPromise } from "./server";
2120

2221
export const getFolderById = Effect.fn(function* (folderId: string) {
2322
if (!folderId) throw new Error("Folder ID is required");
@@ -221,9 +220,15 @@ export const getVideosByFolderId = Effect.fn(function* (
221220
.leftJoin(videoUploads, eq(videos.id, videoUploads.videoId))
222221
.where(
223222
root.variant === "space"
224-
? eq(spaceVideos.folderId, folderId)
223+
? and(
224+
eq(spaceVideos.folderId, folderId),
225+
isNull(organizations.tombstoneAt),
226+
)
225227
: root.variant === "org"
226-
? eq(sharedVideos.folderId, folderId)
228+
? and(
229+
eq(sharedVideos.folderId, folderId),
230+
isNull(organizations.tombstoneAt),
231+
)
227232
: eq(videos.folderId, folderId),
228233
)
229234
.groupBy(

0 commit comments

Comments
 (0)