grand commit
This commit is contained in:
22
lib/data/models/category.ts
Normal file
22
lib/data/models/category.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
'use server'
|
||||
|
||||
import {CategoryLocale} from '@prisma/client'
|
||||
|
||||
import {STORE_ID} from '@/lib/config/constants'
|
||||
import {db} from '@/lib/db/prisma/client'
|
||||
|
||||
export const getCategoryBySlug = async (slug: string) => {
|
||||
return db.categoryLocale.findFirst({
|
||||
where: {
|
||||
slug
|
||||
},
|
||||
select: {
|
||||
category: {
|
||||
include: {
|
||||
locales: true,
|
||||
categoriesOnProducts: true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
23
lib/data/models/sqlSchemas.ts
Normal file
23
lib/data/models/sqlSchemas.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import Decimal from 'decimal.js'
|
||||
|
||||
import {i18nLocalesCodes} from '@/i18n-config'
|
||||
import {locales} from '@/i18n/routing'
|
||||
|
||||
export type CategoryPageSqlSchema = {
|
||||
productId: number
|
||||
lang: string
|
||||
slug?: string | null | undefined
|
||||
image?: string | null | undefined
|
||||
imageWidth?: number | null | undefined
|
||||
imageHeight?: number | null | undefined
|
||||
categoryId?: number
|
||||
title: string
|
||||
shortTitle?: string | null | undefined
|
||||
description?: string | null | undefined
|
||||
content?: string | null | undefined
|
||||
headingTitle?: string | null | undefined
|
||||
instruction?: string | null | undefined
|
||||
categorySlug?: string | null | undefined
|
||||
categoryTitle?: string | null | undefined
|
||||
price?: string | null | Decimal
|
||||
}
|
||||
Reference in New Issue
Block a user