Skip to content

feat!: Custom relationship type updates #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/types/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,11 @@ export interface CrudQueryableResource<R, C, U, F, S, I>

Link(url: string): Promise<Resource<R>>
}

export interface SimpleResourcePageResponse<T> extends ResourceList<T> {
meta: {
results: {
total: number
}
}
}
22 changes: 7 additions & 15 deletions src/types/pcm-custom-relationship.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Product Custom Relationships
*/
import { Identifiable, Resource, ResourceList } from './core'
import { Identifiable, SimpleResourcePageResponse } from './core'
import {
CustomRelationship,
CustomRelationshipsListResponse
Expand All @@ -17,22 +17,14 @@ export interface CustomRelationshipEntry {
slug: string
}

export interface PcmRelatedProductResponse<T> extends ResourceList<T> {
meta: {
results: {
total: number
}
}
}

export interface NonAssociatedProductEntry extends Identifiable {
details: string
}

export interface ProductAssociationResponse {
meta: {
associated_products: string[]
products_not_associated: NonAssociatedProductEntry[]
associated_products?: string[]
products_not_associated?: NonAssociatedProductEntry[]
owner: 'organization' | 'store'
timestamps: {
created_at: string
Expand Down Expand Up @@ -61,8 +53,8 @@ export interface PcmCustomRelationshipEndpoint {
*/
AttachCustomRelationship(
productId: string,
body: CustomRelationshipEntry
): Promise<Resource<CustomRelationship>>
body: CustomRelationshipEntry[]
): Promise<SimpleResourcePageResponse<CustomRelationship>>

/**
* Detach one or multiple custom relationships from a product
Expand Down Expand Up @@ -107,7 +99,7 @@ export interface PcmCustomRelationshipEndpoint {
GetProductsForCustomRelationship(
productId: string,
customRelationshipSlug: string
): Promise<PcmRelatedProductResponse<PcmProduct>>
): Promise<SimpleResourcePageResponse<PcmProduct>>

/**
* Get all IDs of a product's related products under a custom relationship
Expand All @@ -118,5 +110,5 @@ export interface PcmCustomRelationshipEndpoint {
GetProductIdsForCustomRelationship(
productId: string,
customRelationshipSlug: string
): Promise<PcmRelatedProductResponse<PcmProductEntry>>
): Promise<SimpleResourcePageResponse<PcmProductEntry>>
}
10 changes: 10 additions & 0 deletions src/types/pcm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ type productType = 'standard' | 'parent' | 'child'| 'bundle'

export interface PcmProduct extends Identifiable, PcmProductBase {
meta: {
created_at: string
updated_at: string
variation_matrix: { [key: string]: string } | {}
owner?: 'organization' | 'store'
product_types?: productType[]
custom_relationships?: string[]
}
}

Expand All @@ -120,6 +123,13 @@ export interface PcmProductRelationships {
id: string
}
}
custom_relationships?: {
data?: Array<unknown> | null
links?: {
[key: string]: string
self: string
}
}
}
}

Expand Down
Loading