This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
import { db } from "../db";
|
||||
import { clients, tags as tagsTable } from "../db/schema";
|
||||
import { eq, and, inArray } from "drizzle-orm";
|
||||
import { eq, and } from "drizzle-orm";
|
||||
|
||||
export async function validateTimeEntryResources({
|
||||
organizationId,
|
||||
clientId,
|
||||
tagIds,
|
||||
tagId,
|
||||
}: {
|
||||
organizationId: string;
|
||||
clientId: string;
|
||||
tagIds?: string[];
|
||||
tagId?: string | null;
|
||||
}) {
|
||||
const client = await db
|
||||
.select()
|
||||
@@ -23,20 +23,20 @@ export async function validateTimeEntryResources({
|
||||
return { valid: false, error: "Invalid client" };
|
||||
}
|
||||
|
||||
if (tagIds && tagIds.length > 0) {
|
||||
const validTags = await db
|
||||
if (tagId) {
|
||||
const validTag = await db
|
||||
.select()
|
||||
.from(tagsTable)
|
||||
.where(
|
||||
and(
|
||||
inArray(tagsTable.id, tagIds),
|
||||
eq(tagsTable.id, tagId),
|
||||
eq(tagsTable.organizationId, organizationId),
|
||||
),
|
||||
)
|
||||
.all();
|
||||
.get();
|
||||
|
||||
if (validTags.length !== tagIds.length) {
|
||||
return { valid: false, error: "Invalid tags" };
|
||||
if (!validTag) {
|
||||
return { valid: false, error: "Invalid tag" };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user