18 lines
521 B
TypeScript
18 lines
521 B
TypeScript
import type { Prisma } from '../generated/prisma/client';
|
|
import type { CatalogQuery } from './catalog.schemas';
|
|
|
|
export function catalogWhere(
|
|
organizationId: string,
|
|
query: CatalogQuery,
|
|
publishedOnly = false,
|
|
): Prisma.ProductWhereInput {
|
|
return {
|
|
organizationId,
|
|
...(publishedOnly ? { status: 'PUBLISHED' } : {}),
|
|
...(query.search
|
|
? { name: { contains: query.search, mode: 'insensitive' } }
|
|
: {}),
|
|
...(query.groupId ? { groups: { some: { groupId: query.groupId } } } : {}),
|
|
};
|
|
}
|