Skip to content

Commit

Permalink
feat: product template relationship (#522)
Browse files Browse the repository at this point in the history
* feat: PCMTempalte type and endpoint

* add extentions to PCMproduct type
  • Loading branch information
yasiloghmani committed Aug 18, 2021
1 parent 111d192 commit bd1918f
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/endpoints/pcm-template-relationship.js
@@ -0,0 +1,35 @@
import RequestFactory from '../factories/request'
import { buildRelationshipData } from '../utils/helpers'

class PCMTemplateRelationshipEndpoint {
constructor(endpoint) {
const config = { ...endpoint } // Need to clone config so it is only updated in PCM
this.request = new RequestFactory(config)
config.version = 'pcm'
this.endpoint = 'relationships/templates'
}

All(productId) {
return this.request.send(`products/${productId}/${this.endpoint}`, 'GET')
}

Create(productId, resources) {
const body = buildRelationshipData('template', resources)
return this.request.send(
`products/${productId}/${this.endpoint}`,
'POST',
body
)
}

Delete(productId, resources) {
const body = buildRelationshipData('template', resources)
return this.request.send(
`products/${productId}/${this.endpoint}`,
'DELETE',
body
)
}
}

export default PCMTemplateRelationshipEndpoint
2 changes: 2 additions & 0 deletions src/endpoints/pcm.js
@@ -1,5 +1,6 @@
import CRUDExtend from '../extends/crud'
import PCMFileRelationshipEndpoint from './pcm-file-relationship'
import Pcmtemplaterealationshipendpoint from './pcm-template-relationship'

class PCMEndpoint extends CRUDExtend {
constructor(endpoint) {
Expand All @@ -8,6 +9,7 @@ class PCMEndpoint extends CRUDExtend {
super(config)

this.FileRelationships = new PCMFileRelationshipEndpoint(config)
this.TemplateRelationships = new Pcmtemplaterealationshipendpoint(config)

this.endpoint = 'products'
}
Expand Down
1 change: 1 addition & 0 deletions src/moltin.d.ts
Expand Up @@ -81,6 +81,7 @@ export * from './types/price-book-prices'
export * from './types/node-relationships'
export * from './types/merchant-realm-mappings'
export * from "./types/pcm-file-relationship"
export * from './types/pcm-template-relationship'
export * from './types/accounts'
export * from './types/account-authentication-settings'
export * from './types/account-members'
Expand Down
50 changes: 50 additions & 0 deletions src/types/pcm-template-relationship.ts
@@ -0,0 +1,50 @@
/**
* Products templates relationship
*/
import { Identifiable, ResourceList } from './core'

export interface PcmTemplateRelationship extends Identifiable {
meta: {
created_at: string
tags?: string[]
}
type: string
}

export type ProductTemplateRelationshipResource = string | { id: string; meta: { tags: string[] } }

export interface PcmTemplateRelationshipEndpoint {
endpoint: 'relationships/templates'

/**
* Get all product template relationships
* Description:
* @param productId
* @constructor
*/
All(productId: string): Promise<ResourceList<PcmTemplateRelationship>>

/**
* Create a product template relationship
* Description:
* @param productId
* @param resources
* @constructor
*/
Create(
productId: string,
resources?: string | ProductTemplateRelationshipResource[]
): Promise<void>

/**
* Delete a product template relationship
* Description:
* @param productId
* @param resources
* @constructor
*/
Delete(
productId: string,
resources?: string | string[]
): Promise<void>
}
3 changes: 3 additions & 0 deletions src/types/pcm.d.ts
Expand Up @@ -7,6 +7,7 @@ import {
CrudQueryableResource
} from './core'
import { PcmFileRelationshipEndpoint } from "./pcm-file-relationship";
import { PcmTemplateRelationshipEndpoint } from './pcm-template-relationship'

/**
* Core PCM Product Base Interface
Expand All @@ -23,6 +24,7 @@ export interface PcmProductBase {
commodity_type?: string
upc_ean?: string | null
mpn?: string | null
extensions?: Object
}
}

Expand Down Expand Up @@ -56,4 +58,5 @@ export interface PcmProductsEndpoint
endpoint: 'products'

FileRelationships: PcmFileRelationshipEndpoint
TemplateRelationships: PcmTemplateRelationshipEndpoint
}

0 comments on commit bd1918f

Please sign in to comment.