grand commit
This commit is contained in:
@@ -1,12 +1,23 @@
|
||||
'use server'
|
||||
|
||||
import {Lang, Product, ProductLocale, ProductToStore} from '@prisma/client'
|
||||
import {
|
||||
CategoriesOnProducts,
|
||||
CategoryLocale,
|
||||
Lang,
|
||||
Product,
|
||||
ProductLocale,
|
||||
ProductResource,
|
||||
ProductToStore
|
||||
} from '@prisma/client'
|
||||
|
||||
import {STORE_ID} from '@/lib/config/constants'
|
||||
import {db, dbQueryLog} from '@/lib/db/prisma/client'
|
||||
|
||||
export interface ProductProps extends Product {
|
||||
locales: ProductLocale[]
|
||||
toStore: ProductToStore[]
|
||||
categoriesOnProducts: CategoriesOnProducts[]
|
||||
resources: ProductResource[]
|
||||
}
|
||||
|
||||
export const getProductBySlug = async (data: {
|
||||
@@ -25,7 +36,27 @@ export const getProductById = async (id: unknown): Promise<Product | null> => {
|
||||
return db.product.findUnique({
|
||||
where: {id: id as number},
|
||||
include: {
|
||||
resources: true,
|
||||
categoriesOnProducts: {
|
||||
where: {
|
||||
storeId: STORE_ID
|
||||
},
|
||||
include: {
|
||||
category: {
|
||||
include: {
|
||||
locales: {
|
||||
orderBy: {
|
||||
lang: 'asc'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
locales: {
|
||||
orderBy: {
|
||||
lang: 'asc'
|
||||
},
|
||||
include: {
|
||||
meta: true
|
||||
}
|
||||
@@ -39,6 +70,9 @@ export const getProducts = async (): Promise<Product[] | null> => {
|
||||
return db.product.findMany({
|
||||
include: {
|
||||
locales: {
|
||||
orderBy: {
|
||||
lang: 'asc'
|
||||
},
|
||||
omit: {
|
||||
description: true,
|
||||
content: true,
|
||||
@@ -52,3 +86,13 @@ export const getProducts = async (): Promise<Product[] | null> => {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const getProductResources = async (
|
||||
productId: number | null
|
||||
): Promise<ProductResource[] | null> => {
|
||||
return db.productResource.findMany({
|
||||
where: {
|
||||
productId: productId
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user