mirror of
https://github.com/fosrl/pangolin.git
synced 2026-05-28 03:32:20 +00:00
✨ attach label to item
This commit is contained in:
@@ -16,14 +16,13 @@ import {
|
||||
resourceLabels,
|
||||
resources,
|
||||
siteLabels,
|
||||
sites,
|
||||
type Label
|
||||
sites
|
||||
} from "@server/db";
|
||||
import response from "@server/lib/response";
|
||||
import logger from "@server/logger";
|
||||
import type { CreateOrEditLabelResponse } from "@server/routers/labels/types";
|
||||
import HttpCode from "@server/types/HttpCode";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import createHttpError from "http-errors";
|
||||
import { z } from "zod";
|
||||
@@ -74,7 +73,10 @@ export async function createOrgLabel(
|
||||
const { name, color, siteId, resourceId } = parsedBody.data;
|
||||
|
||||
if (siteId) {
|
||||
const siteCount = await db.$count(sites, eq(sites.siteId, siteId));
|
||||
const siteCount = await db.$count(
|
||||
sites,
|
||||
and(eq(sites.siteId, siteId), eq(sites.orgId, orgId))
|
||||
);
|
||||
|
||||
if (siteCount === 0) {
|
||||
return next(
|
||||
@@ -88,8 +90,11 @@ export async function createOrgLabel(
|
||||
|
||||
if (resourceId) {
|
||||
const resourceCount = await db.$count(
|
||||
sites,
|
||||
eq(resources.resourceId, resourceId)
|
||||
resources,
|
||||
and(
|
||||
eq(resources.resourceId, resourceId),
|
||||
eq(resources.orgId, orgId)
|
||||
)
|
||||
);
|
||||
|
||||
if (resourceCount === 0) {
|
||||
|
||||
Reference in New Issue
Block a user