scope niceid to the orgId

This commit is contained in:
Pallavi Kumari
2025-11-06 23:50:57 +05:30
parent abc5f8ec68
commit 0af51cebbe
2 changed files with 19 additions and 4 deletions

View File

@@ -242,7 +242,12 @@ async function updateHttpResource(
const [existingResource] = await db const [existingResource] = await db
.select() .select()
.from(resources) .from(resources)
.where(eq(resources.niceId, updateData.niceId)); .where(
and(
eq(resources.niceId, updateData.niceId),
eq(resources.orgId, resource.orgId)
)
);
if ( if (
existingResource && existingResource &&
@@ -387,7 +392,12 @@ async function updateRawResource(
const [existingResource] = await db const [existingResource] = await db
.select() .select()
.from(resources) .from(resources)
.where(eq(resources.niceId, updateData.niceId)); .where(
and(
eq(resources.niceId, updateData.niceId),
eq(resources.orgId, resource.orgId)
)
);
if ( if (
existingResource && existingResource &&

View File

@@ -2,7 +2,7 @@ import { Request, Response, NextFunction } from "express";
import { z } from "zod"; import { z } from "zod";
import { db } from "@server/db"; import { db } from "@server/db";
import { sites } from "@server/db"; import { sites } from "@server/db";
import { eq } from "drizzle-orm"; import { eq, and } from "drizzle-orm";
import response from "@server/lib/response"; import response from "@server/lib/response";
import HttpCode from "@server/types/HttpCode"; import HttpCode from "@server/types/HttpCode";
import createHttpError from "http-errors"; import createHttpError from "http-errors";
@@ -95,7 +95,12 @@ export async function updateSite(
const existingSite = await db const existingSite = await db
.select() .select()
.from(sites) .from(sites)
.where(eq(sites.niceId, updateData.niceId)) .where(
and(
eq(sites.niceId, updateData.niceId),
eq(sites.orgId, sites.orgId)
)
)
.limit(1); .limit(1);
if (existingSite.length > 0 && existingSite[0].siteId !== siteId) { if (existingSite.length > 0 && existingSite[0].siteId !== siteId) {