Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions apps/web/actions/organizations/add-videos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
videos,
} from "@cap/database/schema";
import type { Organisation, Video } from "@cap/web-domain";
import { and, eq, inArray } from "drizzle-orm";
import { and, eq, inArray, isNull } from "drizzle-orm";
import { revalidatePath } from "next/cache";

export async function addVideosToOrganization(
Expand All @@ -31,7 +31,12 @@ export async function addVideosToOrganization(
const [organization] = await db()
.select()
.from(organizations)
.where(eq(organizations.id, organizationId));
.where(
and(
eq(organizations.id, organizationId),
isNull(organizations.tombstoneAt),
),
);

if (!organization) {
throw new Error("Organization not found");
Expand Down
13 changes: 10 additions & 3 deletions apps/web/actions/spaces/get-user-videos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getCurrentUser } from "@cap/database/auth/session";
import {
comments,
folders,
organizations,
sharedVideos,
spaces,
spaceVideos,
Expand All @@ -13,7 +14,7 @@ import {
videoUploads,
} from "@cap/database/schema";
import type { Space } from "@cap/web-domain";
import { and, desc, eq, sql } from "drizzle-orm";
import { and, desc, eq, isNull, sql } from "drizzle-orm";

export async function getUserVideos(spaceId: Space.SpaceIdOrOrganisationId) {
try {
Expand Down Expand Up @@ -64,7 +65,10 @@ export async function getUserVideos(spaceId: Space.SpaceIdOrOrganisationId) {
)
.leftJoin(folders, eq(sharedVideos.folderId, folders.id))
.leftJoin(spaces, eq(folders.spaceId, spaces.id))
.where(eq(videos.ownerId, userId))
.leftJoin(organizations, eq(videos.orgId, organizations.id))
.where(
and(eq(videos.ownerId, userId), isNull(organizations.tombstoneAt)),
)
.groupBy(
videos.id,
videos.ownerId,
Expand Down Expand Up @@ -98,7 +102,10 @@ export async function getUserVideos(spaceId: Space.SpaceIdOrOrganisationId) {
)
.leftJoin(folders, eq(spaceVideos.folderId, folders.id))
.leftJoin(spaces, eq(folders.spaceId, spaces.id))
.where(eq(videos.ownerId, userId))
.leftJoin(organizations, eq(videos.orgId, organizations.id))
.where(
and(eq(videos.ownerId, userId), isNull(organizations.tombstoneAt)),
)
.groupBy(
videos.id,
videos.ownerId,
Expand Down
2 changes: 2 additions & 0 deletions apps/web/app/(org)/dashboard/caps/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export default async function CapsPage(props: PageProps<"/dashboard/caps">) {
and(
eq(videos.ownerId, userId),
eq(organizations.id, user.activeOrganizationId),
isNull(organizations.tombstoneAt),
),
);

Expand Down Expand Up @@ -185,6 +186,7 @@ export default async function CapsPage(props: PageProps<"/dashboard/caps">) {
eq(videos.ownerId, userId),
eq(videos.orgId, user.activeOrganizationId),
isNull(videos.folderId),
isNull(organizations.tombstoneAt),
),
)
.groupBy(
Expand Down
8 changes: 7 additions & 1 deletion apps/web/app/(org)/dashboard/spaces/[spaceId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
comments,
folders,
organizationMembers,
organizations,
sharedVideos,
spaceMembers,
spaceVideos,
Expand Down Expand Up @@ -201,8 +202,13 @@ export default async function SharedCapsPage(props: {
.leftJoin(comments, eq(videos.id, comments.videoId))
.leftJoin(users, eq(videos.ownerId, users.id))
.leftJoin(videoUploads, eq(videos.id, videoUploads.videoId))
.leftJoin(organizations, eq(videos.orgId, organizations.id))
.where(
and(eq(spaceVideos.spaceId, spaceId), isNull(spaceVideos.folderId)),
and(
eq(spaceVideos.spaceId, spaceId),
isNull(spaceVideos.folderId),
isNull(organizations.tombstoneAt),
),
)
.groupBy(
videos.id,
Expand Down
13 changes: 9 additions & 4 deletions apps/web/lib/folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ import {
import { Database, ImageUploads } from "@cap/web-backend";
import type { ImageUpload, Organisation, Space, Video } from "@cap/web-domain";
import { CurrentUser, Folder } from "@cap/web-domain";
import { and, desc, eq } from "drizzle-orm";
import { and, desc, eq, isNull } from "drizzle-orm";
import { sql } from "drizzle-orm/sql";
import { Effect } from "effect";
import { runPromise } from "./server";

export const getFolderById = Effect.fn(function* (folderId: string) {
if (!folderId) throw new Error("Folder ID is required");
Expand Down Expand Up @@ -221,9 +220,15 @@ export const getVideosByFolderId = Effect.fn(function* (
.leftJoin(videoUploads, eq(videos.id, videoUploads.videoId))
.where(
root.variant === "space"
? eq(spaceVideos.folderId, folderId)
? and(
eq(spaceVideos.folderId, folderId),
isNull(organizations.tombstoneAt),
)
: root.variant === "org"
? eq(sharedVideos.folderId, folderId)
? and(
eq(sharedVideos.folderId, folderId),
isNull(organizations.tombstoneAt),
)
: eq(videos.folderId, folderId),
)
.groupBy(
Expand Down