diff --git a/framework/commerce/api/operations.ts b/framework/commerce/api/operations.ts
index 34a549f2c..1fce40dc5 100644
--- a/framework/commerce/api/operations.ts
+++ b/framework/commerce/api/operations.ts
@@ -16,6 +16,9 @@ import type {
GetBlogDetailOperation,
GetRelevantBlogsOperation
} from '../types/blogs'
+import type {
+ GetAllRecipesOperation
+} from '../types/recipes'
import type { APIProvider, CommerceAPI } from '.'
import { GetAllCollectionsOperation } from '@commerce/types/collection';
@@ -39,7 +42,8 @@ export const OPERATIONS = [
'getFeaturedBlog',
'getAllBlogPaths',
'getBlogDetail',
- 'getRelevantBlogs'
+ 'getRelevantBlogs',
+ 'getAllRecipes'
] as const
export const defaultOperations = OPERATIONS.reduce((ops, k) => {
@@ -188,6 +192,22 @@ export type Operations
= {
): Promise
}
+ getAllRecipes: {
+ (opts: {
+ variables?: T['variables']
+ config?: P['config']
+ preview?: boolean
+ }): Promise
+
+ (
+ opts: {
+ variables?: T['variables']
+ config?: P['config']
+ preview?: boolean
+ } & OperationOptions
+ ): Promise
+ }
+
getRelevantBlogs: {
(opts: {
variables?: T['variables']
diff --git a/framework/commerce/types/recipes.ts b/framework/commerce/types/recipes.ts
new file mode 100644
index 000000000..ce143c434
--- /dev/null
+++ b/framework/commerce/types/recipes.ts
@@ -0,0 +1,32 @@
+import { Asset, BlogTranslation, Maybe, Product } from './../../vendure/schema.d';
+
+export type RecipeList = Node &{
+ id: string
+ featuredAsset?: Maybe
+ isPublish:Boolean
+ translations: Array
+ authorName: string
+ authorAvatarAsset:Array
+ relevantProducts: Product
+ link:String
+ minutes:Number
+ people:Number
+}
+export type RecipesType = {
+ items: RecipeList
+ totalItems: number
+}
+
+export enum SortType {
+ ASC = 'ASC',
+ DESC = 'DESC',
+}
+export type GetAllRecipesOperation = {
+ data: { items: T['items'][], totalItems: number }
+ variables: {
+ take?: number
+ sort?: {
+ id: SortType
+ }
+ }
+}
\ No newline at end of file
diff --git a/framework/vendure/api/operations/get-all-recipe.ts b/framework/vendure/api/operations/get-all-recipe.ts
new file mode 100644
index 000000000..78326308e
--- /dev/null
+++ b/framework/vendure/api/operations/get-all-recipe.ts
@@ -0,0 +1,68 @@
+import { OperationContext } from '@commerce/api/operations'
+import { Provider, VendureConfig } from '..'
+import { GetAllRecipesQuery,BlogList } from '../../schema'
+import { getAllBlogsQuery } from '../../utils/queries/get-all-blog-query'
+
+export type BlogVariables = {
+ excludeBlogIds?: string[],
+ take?: number,
+ skip?:number,
+ filter?:{
+ isFeatured?:{
+ eq?:Boolean
+ }
+ },
+}
+
+export default function getAllRecipesOperation({
+ commerce,
+}: OperationContext) {
+ async function getAllRecipes(opts?: {
+ variables?: BlogVariables
+ config?: Partial
+ preview?: boolean
+ }): Promise<{ recipes: GetAllRecipesQuery[],totalItems:number }>
+
+ async function getAllRecipes({
+ query = getAllBlogsQuery,
+ variables: { ...vars } = {},
+ config: cfg,
+ }: {
+ query?: string
+ variables?: BlogVariables
+ config?: Partial
+ preview?: boolean
+ } = {}): Promise<{ recipes: GetAllRecipesQuery[] | any[] ,totalItems?:number }> {
+
+ const config = commerce.getConfig(cfg)
+ const variables = {
+ excludeBlogIds: vars.excludeBlogIds,
+ options: {
+ take: vars.take,
+ filter: {
+ isFeatured: vars.filter?.isFeatured
+ }
+ },
+ }
+ const { data } = await config.fetch(query, {
+ variables,
+ })
+ return {
+ recipes: data?.blogs?.items?.map((val:BlogList)=>({
+ id: val.id,
+ title: val.translations[0]?.title,
+ imageSrc: val.featuredAsset?.preview ?? null,
+ slug: val.translations[0]?.slug,
+ description: val.translations[0]?.description,
+ isPublish: val.isPublish,
+ isFeatured: val.isFeatured,
+ authorName: val.authorName,
+ authorAvatarAsset : val.authorAvatarAsset?.preview ?? null,
+ createdAt: val.createdAt
+ })),
+ totalItems: data?.blogs?.totalItems || null
+ }
+ }
+
+ return getAllRecipes
+}
diff --git a/framework/vendure/schema.d.ts b/framework/vendure/schema.d.ts
index bde35416c..417fee519 100644
--- a/framework/vendure/schema.d.ts
+++ b/framework/vendure/schema.d.ts
@@ -2384,6 +2384,37 @@ export type BlogList = Node &{
isFeatured: Boolean
}
+export type RecipeList = Node &{
+ id: ID!
+ createdAt: DateTime!
+ updatedAt: DateTime!
+ featuredAsset?: Maybe
+ isPublish:Boolean
+ translations: Array
+ authorName: Scalars['String']
+ authorAvatarAsset:Asset
+ relevantProducts: Product[]
+ link:String
+ minutes:Number
+ people:Number
+}
+
+
+export type RecipeTranslation = {
+ __typename?: 'BlogTranslation'
+ id: Scalars['ID']
+ createdAt: Scalars['DateTime']
+ updatedAt: Scalars['DateTime']
+ languageCode: LanguageCode
+ title: Scalars['String']
+ slug: Scalars['String']
+ description: Scalars['String']
+ content: Scalars['String']
+ Ingredients:Scalars['String']
+ Preparation:Scalars['String']
+}
+
+
export type GetBlogQuery = { __typename?: 'Query' } & {
blog?: Maybe<
{ __typename?: 'Blog' } & BlogList
@@ -2391,8 +2422,6 @@ export type GetBlogQuery = { __typename?: 'Query' } & {
}
-
-
export type BlogTranslation = {
__typename?: 'BlogTranslation'
id: Scalars['ID']
@@ -2412,6 +2441,14 @@ export type GetAllBlogsQuery = PaginatedList & {
}
}
+export type GetAllRecipesQuery = PaginatedList & {
+ recipes: { __typename?: 'RecipeList' } & {
+ items: Array<{ __typename?: 'Recipe' } & RecipeList!>,
+ 'totalItems'
+ }
+}
+
+
export type GetRelevantBlogsQuery = PaginatedList & {
relevantBlogs: { __typename?: 'BlogList' } & {
items: Array<{ __typename?: 'Blog' } & BlogList!>,
diff --git a/pages/recipes.tsx b/pages/recipes.tsx
index a4acece13..88dd8a18e 100644
--- a/pages/recipes.tsx
+++ b/pages/recipes.tsx
@@ -1,8 +1,11 @@
import { Layout } from 'src/components/common';
import RecipeListBanner from 'src/components/modules/recipes-list/RecipeListBanner/RecipeListBanner';
import RecipesList from 'src/components/modules/recipes-list/RecipesList/RecipesList';
-
-
+import { GetStaticPropsContext } from 'next';
+import { PromiseWithKey } from 'src/utils/types.utils';
+import { DEFAULT_BLOG_PAGE_SIZE } from "src/utils/constanst.utils";
+import commerce from '@lib/api/commerce';
+import { getAllPromies } from 'src/utils/funtion.utils';
export default function RecipeListPage() {
return (
<>
@@ -12,4 +15,50 @@ export default function RecipeListPage() {
)
}
+export async function getStaticProps({
+ preview,
+ locale,
+ locales,
+}: GetStaticPropsContext) {
+
+ const config = { locale, locales }
+ let promisesWithKey = [] as PromiseWithKey[]
+ let props = {} as any;
+
+
+ const blogsPromise = commerce.getAllBlogs({
+ variables: {
+ excludeBlogIds: [],
+ take: DEFAULT_BLOG_PAGE_SIZE,
+ filter: {
+ isFeatured: {
+ eq:false
+ }
+ }
+ },
+ config,
+ preview,
+ })
+ promisesWithKey.push({ key: 'blogsResult', promise: blogsPromise })
+
+
+ try {
+ const promises = getAllPromies(promisesWithKey)
+ const rs = await Promise.all(promises)
+
+ promisesWithKey.map((item, index) => {
+ props[item.key] = item.keyResult ? rs[index][item.keyResult] : rs[index]
+ return null
+ })
+ console.log(props);
+ return {
+ props,
+ revalidate: 60
+ }
+ } catch (err) {
+
+ }
+}
+
+
RecipeListPage.Layout = Layout