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