mirror of
https://github.com/vercel/commerce.git
synced 2025-07-26 19:51:23 +00:00
🐛 bug: fix code follow by review Ly Tran
:%s
This commit is contained in:
@@ -11,7 +11,7 @@ import type {
|
||||
} from '../types/product'
|
||||
import type {
|
||||
GetAllBlogsOperation,
|
||||
GetFeaturedOperation
|
||||
GetFeaturedBlogsOperation
|
||||
} from '../types/blogs'
|
||||
import type { APIProvider, CommerceAPI } from '.'
|
||||
import { GetAllCollectionsOperation } from '@commerce/types/collection';
|
||||
@@ -167,13 +167,13 @@ export type Operations<P extends APIProvider> = {
|
||||
}
|
||||
|
||||
getFeaturedBlog: {
|
||||
<T extends GetFeaturedOperation>(opts: {
|
||||
<T extends GetFeaturedBlogsOperation>(opts: {
|
||||
variables?: T['variables']
|
||||
config?: P['config']
|
||||
preview?: boolean
|
||||
}): Promise<T['data']>
|
||||
|
||||
<T extends GetFeaturedOperation>(
|
||||
<T extends GetFeaturedBlogsOperation>(
|
||||
opts: {
|
||||
variables?: T['variables']
|
||||
config?: P['config']
|
||||
|
@@ -1,13 +1,12 @@
|
||||
import { SearchResultSortParameter } from "@framework/schema";
|
||||
import { Asset, BlogTranslation, Maybe, Product } from './../../vendure/schema.d';
|
||||
|
||||
export type BlogList = Node &{
|
||||
id: string
|
||||
featuredAsset?: Maybe<Asset>
|
||||
isPublic:Boolean
|
||||
translations: Array<BlogTranslation>
|
||||
translations: BlogTranslation[]
|
||||
authorName: string
|
||||
authorAvatarAsset:Array<Asset>
|
||||
authorAvatarAsset:Asset[]
|
||||
relevantProducts: Product
|
||||
}
|
||||
export type BlogsType = {
|
||||
@@ -23,7 +22,7 @@ export type GetAllBlogsOperation<T extends BlogsType = BlogsType> = {
|
||||
}
|
||||
|
||||
|
||||
export type GetFeaturedOperation<T extends BlogsType = BlogsType> = {
|
||||
export type GetFeaturedBlogsOperation<T extends BlogsType = BlogsType> = {
|
||||
data: { items: T['items'][] }
|
||||
variables: {
|
||||
take?: number
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { OperationContext } from '@commerce/api/operations'
|
||||
import { Provider, VendureConfig } from '..'
|
||||
import { GetFeaturedBlogQuery,BlogList } from '../../schema'
|
||||
import { getFeatuedBlogQuery } from '../../utils/queries/get-featued-query'
|
||||
import { getFeatuedBlogsQuery } from '../../utils/queries/get-featued-query'
|
||||
|
||||
export type BlogVariables = {
|
||||
take?: number,
|
||||
@@ -18,7 +18,7 @@ export default function getFeaturedBlogOperation({
|
||||
}): Promise<{ featuredBlogs: GetFeaturedBlogQuery[],totalItems:number }>
|
||||
|
||||
async function getFeaturedBlog({
|
||||
query = getFeatuedBlogQuery,
|
||||
query = getFeatuedBlogsQuery,
|
||||
variables: { ...vars } = {},
|
||||
config: cfg,
|
||||
}: {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { Cart } from '@commerce/types/cart'
|
||||
import { ProductCard, Product } from '@commerce/types/product'
|
||||
import { CartFragment, SearchResultFragment,Favorite } from '../schema'
|
||||
import { CartFragment, SearchResultFragment,Favorite, BlogList } from '../schema'
|
||||
|
||||
export function normalizeSearchResult(item: SearchResultFragment): ProductCard {
|
||||
return {
|
||||
@@ -83,4 +83,19 @@ export function normalizeProductCard(product: Product): ProductCard {
|
||||
facetValueIds: product.facetValueIds,
|
||||
collectionIds: product.collectionIds,
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeBlogList(blog: BlogList) {
|
||||
return {
|
||||
id: blog.id,
|
||||
title: blog.translations[0]?.title,
|
||||
imageSrc: blog.featuredAsset?.preview ?? null,
|
||||
slug: blog.translations[0]?.slug,
|
||||
description: blog.translations[0]?.description,
|
||||
isPublish: blog.isPublish,
|
||||
isFeatured:blog.isFeatured,
|
||||
authorName: blog.authorName,
|
||||
authorAvatarAsset : blog.authorAvatarAsset?.preview,
|
||||
createdAt: blog.createdAt
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
export const getFeatuedBlogQuery = /* GraphQL */ `
|
||||
query GetFeaturedBlog($options: BlogListOptions) {
|
||||
export const getFeatuedBlogsQuery = /* GraphQL */ `
|
||||
query GetFeaturedBlogs($options: BlogListOptions) {
|
||||
featuredBlogs( options: $options){
|
||||
items {
|
||||
id
|
||||
|
Reference in New Issue
Block a user