Skip to content

Commit

Permalink
🚑 Hotfix for currentStages to stay always > 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario-SO committed Jan 24, 2025
1 parent 55d011b commit ab60757
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
12 changes: 4 additions & 8 deletions packages/app/app/studio/[organization]/(root)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use server';

import TableSkeleton from '@/components/misc/Table/TableSkeleton';
import { LivestreamPageParams, eSort } from '@/lib/types';
import { LivestreamPageParams } from '@/lib/types';
import CreateLivestreamModal from './livestreams/components/CreateLivestreamModal';
import { Suspense } from 'react';
import { fetchOrganization } from '@/lib/services/organizationService';
Expand All @@ -26,8 +24,6 @@ export default async function OrganizationPage({

if (!organization) return notFound();

const hasFeatures = isFeatureAvailable(organization.expirationDate);

// Calculate the start of the current day
const startOfDay = new Date();
startOfDay.setHours(0, 0, 0, 0);
Expand All @@ -37,7 +33,7 @@ export default async function OrganizationPage({
<div className="flex w-full flex-col p-2">
<h2 className="text-lg font-bold">Create</h2>
<div className="flex items-center gap-4 p-4">
{hasFeatures ? (
{isFeatureAvailable(organization.expirationDate) ? (
<CreateLivestreamModal
variant="primary"
show={searchParams?.show}
Expand All @@ -54,7 +50,7 @@ export default async function OrganizationPage({
</FeatureButton>
)}

{hasFeatures ? (
{isFeatureAvailable(organization.expirationDate) ? (
<UploadVideoDialog organizationId={organization._id.toString()} />
) : (
<FeatureButton
Expand All @@ -67,7 +63,7 @@ export default async function OrganizationPage({
</FeatureButton>
)}

{hasFeatures ? (
{isFeatureAvailable(organization.expirationDate) ? (
<Link
href={`/studio/${organization.slug}/library?layout=list&page=1&limit=20&clipable=true`}
>
Expand Down
5 changes: 2 additions & 3 deletions packages/app/components/Layout/NavbarStudio.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import React from 'react';
import Image from 'next/image';
import SearchBar from '@/components/misc/SearchBar';
import Link from 'next/link';
import { NavigationMenu } from '@/components/ui/navigation-menu';
import { IExtendedOrganization } from '@/lib/types';
import UserProfile from '@/components/misc/UserProfile';
import CreateLivestreamModal from '@/app/studio/[organization]/(root)/livestreams/components/CreateLivestreamModal';
import UploadVideoDialog from '@/app/studio/[organization]/(root)/library/components/UploadVideoDialog';
import LogoDark from '@/public/logo_dark.png';
import FeatureButton from '../ui/feature-button';
import { Radio, FileUp } from 'lucide-react';
import { isFeatureAvailable } from '@/lib/utils/utils';
import { notFound } from 'next/navigation';

const NavbarStudio = ({
showSearchBar = true,
Expand All @@ -28,7 +27,7 @@ const NavbarStudio = ({
);

if (!organization) {
return null;
return notFound();
}

return (
Expand Down
5 changes: 5 additions & 0 deletions packages/server/src/services/organization.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export default class OrganizationService {
throw new HttpException(404, 'Organization not found');
}

// Prevent currentStages from going below zero
if (typeof organizationUpdate.currentStages === 'number') {
organizationUpdate.currentStages = Math.max(0, organizationUpdate.currentStages);
}

// Merge current org with updates
const updatedOrg: IOrganization = {
...currentOrg,
Expand Down
13 changes: 8 additions & 5 deletions packages/server/src/services/stage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,14 @@ export default class StageService {
const stage = await this.get(stageId);
await deleteStream(stage.streamSettings.streamId);

// Decrement currentStages for the organization
await Organization.findByIdAndUpdate(
stage.organizationId,
{ $inc: { currentStages: -1 } }
);
// Get organization and only decrement if currentStages > 0
const organization = await Organization.findById(stage.organizationId);
if (organization && organization.currentStages > 0) {
await Organization.findByIdAndUpdate(
stage.organizationId,
{ $inc: { currentStages: -1 } }
);
}

return await this.controller.store.delete(stageId);
}
Expand Down

0 comments on commit ab60757

Please sign in to comment.