55 lines
990 B
TypeScript
55 lines
990 B
TypeScript
'use server'
|
|
|
|
import {Lang, Product, ProductLocale, ProductToStore} from '@prisma/client'
|
|
|
|
import {db, dbQueryLog} from '@/lib/db/prisma/client'
|
|
|
|
export interface ProductProps extends Product {
|
|
locales: ProductLocale[]
|
|
toStore: ProductToStore[]
|
|
}
|
|
|
|
export const getProductBySlug = async (data: {
|
|
slug: string
|
|
lang: string
|
|
}): Promise<ProductLocale | null> => {
|
|
return db.productLocale.findFirst({
|
|
where: {
|
|
slug: data.slug,
|
|
lang: data.lang as Lang
|
|
}
|
|
})
|
|
}
|
|
|
|
export const getProductById = async (id: unknown): Promise<Product | null> => {
|
|
return db.product.findUnique({
|
|
where: {id: id as number},
|
|
include: {
|
|
locales: {
|
|
include: {
|
|
meta: true
|
|
}
|
|
},
|
|
toStore: true
|
|
}
|
|
})
|
|
}
|
|
|
|
export const getProducts = async (): Promise<Product[] | null> => {
|
|
return db.product.findMany({
|
|
include: {
|
|
locales: {
|
|
omit: {
|
|
description: true,
|
|
content: true,
|
|
instruction: true
|
|
},
|
|
include: {
|
|
meta: true
|
|
}
|
|
},
|
|
toStore: true
|
|
}
|
|
})
|
|
}
|