-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from Relewise/feat/content-and-categories
Feat: Content and Content categories updates
- Loading branch information
Showing
10 changed files
with
377 additions
and
2 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
packages/integrations/src/builders/content/contentAdministrativeActionBuilder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { ContentAdministrativeAction, FilterBuilder } from '@relewise/client'; | ||
|
||
export class ContentAdministrativeActionBuilder { | ||
private filterBuilder = new FilterBuilder(); | ||
private kind: 'Disable' | 'Enable' | 'Delete'; | ||
|
||
language: string | null | undefined; | ||
currency: string | null | undefined; | ||
|
||
constructor({ language, currency, kind, filters }: { | ||
currency?: string | null, | ||
language?: string | null, | ||
kind: 'Disable' | 'Enable' | 'Delete', | ||
filters: (filterBuilder: FilterBuilder) => void | ||
}) { | ||
this.language = language; | ||
this.currency = currency; | ||
this.kind = kind; | ||
|
||
filters(this.filterBuilder); | ||
} | ||
|
||
filters(filters: (filterBuilder: FilterBuilder) => void): this { | ||
filters(this.filterBuilder); | ||
|
||
return this; | ||
} | ||
|
||
build(): ContentAdministrativeAction { | ||
const filters = this.filterBuilder.build(); | ||
|
||
if (!filters || !filters.items || filters.items.length === 0) { | ||
throw new Error('No filters were provided for the content administrative action'); | ||
} | ||
|
||
return { | ||
$type: 'Relewise.Client.DataTypes.ContentAdministrativeAction, Relewise.Client', | ||
...(this.language && { language: { value: this.language } }), | ||
...(this.currency && { currency: { value: this.currency } }), | ||
filters: filters, | ||
kind: this.kind, | ||
}; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
packages/integrations/src/builders/content/contentUpdateBuilder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { DataValue,Content, ContentUpdate } from '@relewise/client'; | ||
import { CategoryPathBuilder } from '../categoryPathBuilder'; | ||
|
||
export class ContentUpdateBuilder { | ||
private content: Content; | ||
private updateKind: 'UpdateAndAppend' | 'ReplaceProvidedProperties' | 'ClearAndReplace'; | ||
|
||
constructor({ id, updateKind }: { | ||
id: string, | ||
updateKind: 'UpdateAndAppend' | 'ReplaceProvidedProperties' | 'ClearAndReplace', | ||
}) { | ||
this.content = { id: id }; | ||
this.updateKind = updateKind; | ||
} | ||
|
||
displayName(values: { | ||
value: string; | ||
language: string; | ||
}[]): this { | ||
this.content.displayName = { | ||
values: values.map(x => ({ text: x.value, language: { value: x.language } })), | ||
}; | ||
|
||
return this; | ||
} | ||
|
||
data(data: Record<string, DataValue | null>): this { | ||
this.content.data = data as Record<string, DataValue>; // TODO remove dirty hack | ||
|
||
return this; | ||
} | ||
|
||
/** | ||
* Add multiple category paths to a content. Start from the root to the lowest child. Example: Tools -> Outdoor -> Shovel | ||
* @param paths | ||
* @returns | ||
*/ | ||
categoryPaths(builder: (b: CategoryPathBuilder) => void): this { | ||
const b = new CategoryPathBuilder(); | ||
builder(b); | ||
this.content.categoryPaths = b.build(); | ||
|
||
return this; | ||
} | ||
|
||
assortments(assortments: number[]): this { | ||
this.content.assortments = assortments; | ||
|
||
return this; | ||
} | ||
|
||
|
||
build(): ContentUpdate { | ||
return { | ||
$type: 'Relewise.Client.DataTypes.ContentUpdate, Relewise.Client', | ||
content: this.content, | ||
kind: this.updateKind, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './contentUpdateBuilder'; | ||
export * from './contentAdministrativeActionBuilder'; |
44 changes: 44 additions & 0 deletions
44
...integrations/src/builders/contentcategories/contentCategoryAdministrativeActionBuilder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { ContentCategoryAdministrativeAction, FilterBuilder } from '@relewise/client'; | ||
|
||
export class ContentCategoryAdministrativeActionBuilder { | ||
private filterBuilder = new FilterBuilder(); | ||
private kind: 'Disable' | 'Enable' | 'Delete'; | ||
|
||
language: string | null | undefined; | ||
currency: string | null | undefined; | ||
|
||
constructor({ language, currency, kind, filters }: { | ||
currency?: string | null, | ||
language?: string | null, | ||
kind: 'Disable' | 'Enable' | 'Delete', | ||
filters: (filterBuilder: FilterBuilder) => void | ||
}) { | ||
this.language = language; | ||
this.currency = currency; | ||
this.kind = kind; | ||
|
||
filters(this.filterBuilder); | ||
} | ||
|
||
filters(filters: (filterBuilder: FilterBuilder) => void): this { | ||
filters(this.filterBuilder); | ||
|
||
return this; | ||
} | ||
|
||
build(): ContentCategoryAdministrativeAction { | ||
const filters = this.filterBuilder.build(); | ||
|
||
if (!filters || !filters.items || filters.items.length === 0) { | ||
throw new Error('No filters were provided for the product category administrative action'); | ||
} | ||
|
||
return { | ||
$type: 'Relewise.Client.DataTypes.ContentCategoryAdministrativeAction, Relewise.Client', | ||
...(this.language && { language: { value: this.language } }), | ||
...(this.currency && { currency: { value: this.currency } }), | ||
filters: filters, | ||
kind: this.kind, | ||
}; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
packages/integrations/src/builders/contentcategories/contentCategoryUpdateBuilder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { DataValue, ContentCategoryUpdate, ContentCategory } from '@relewise/client'; | ||
import { CategoryPathBuilder } from '../categoryPathBuilder'; | ||
|
||
export class ContentCategoryUpdateBuilder { | ||
private contentCategory: ContentCategory; | ||
private kind: 'UpdateAndAppend' | 'ReplaceProvidedProperties' | 'ClearAndReplace'; | ||
|
||
constructor({ id, kind }: { | ||
id: string, | ||
kind: 'UpdateAndAppend' | 'ReplaceProvidedProperties' | 'ClearAndReplace' | ||
}) { | ||
this.contentCategory = { | ||
$type: 'Relewise.Client.DataTypes.ContentCategory, Relewise.Client', | ||
id: id, | ||
}; | ||
this.kind = kind; | ||
} | ||
|
||
displayName(values: { | ||
value: string; | ||
language: string; | ||
}[]): this { | ||
this.contentCategory.displayName = { | ||
values: values.map(x => ({ text: x.value, language: { value: x.language } })), | ||
}; | ||
|
||
return this; | ||
} | ||
|
||
data(data: Record<string, DataValue | null>): this { | ||
this.contentCategory.data = data as Record<string, DataValue>; // TODO remove dirty hack | ||
|
||
return this; | ||
} | ||
|
||
/** | ||
* Add multiple category paths to a content category. Start from the root to the lowest child. Example: Tools -> Outdoor -> Shovel | ||
* @param paths | ||
* @returns | ||
*/ | ||
categoryPaths(builder: (b: CategoryPathBuilder) => void): this { | ||
const b = new CategoryPathBuilder(); | ||
builder(b); | ||
this.contentCategory.categoryPaths = b.build(); | ||
|
||
return this; | ||
} | ||
|
||
assortments(assortments: number[]): this { | ||
this.contentCategory.assortments = assortments; | ||
|
||
return this; | ||
} | ||
|
||
build(): ContentCategoryUpdate { | ||
return { | ||
$type: 'Relewise.Client.DataTypes.ContentCategoryUpdate, Relewise.Client', | ||
category: this.contentCategory, | ||
kind: this.kind, | ||
}; | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/integrations/src/builders/contentcategories/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './contentCategoryUpdateBuilder'; | ||
export * from './contentCategoryAdministrativeActionBuilder'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from './categoryPathBuilder'; | ||
export * from './products'; | ||
export * from './productcategories'; | ||
export * from './productcategories'; | ||
export * from './contentcategories'; | ||
export * from './content'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/integrations/tests/integration-tests/content-categories/updates.integration.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { test } from '@jest/globals'; | ||
import { ContentCategoryUpdateBuilder, Integrator, ContentCategoryAdministrativeActionBuilder } from '../../../src'; | ||
import { DataValueFactory } from '@relewise/client'; | ||
const { npm_config_API_KEY: API_KEY, npm_config_DATASET_ID: DATASET_ID, npm_config_SERVER_URL: SERVER_URL } = process.env; | ||
|
||
const integrator = new Integrator(DATASET_ID!, API_KEY!, { serverUrl: SERVER_URL }); | ||
|
||
const unixTimeStamp: number = Date.now(); | ||
|
||
test('Create Content Category', async() => { | ||
const category = new ContentCategoryUpdateBuilder({ | ||
id: '1234', | ||
kind: 'ReplaceProvidedProperties', | ||
}) | ||
.displayName([ | ||
{ language: 'da', value: 'Skovle' }, | ||
]) | ||
.data({ | ||
'UnixTimestamp': DataValueFactory.number(unixTimeStamp), | ||
'Description': DataValueFactory.string('Misc. skovle'), | ||
'Tags': DataValueFactory.stringCollection(['outdoor', 'quality', 'good-deal']), | ||
'InStock': DataValueFactory.boolean(true), | ||
'Removed': null, | ||
'Complex': DataValueFactory.object({ | ||
'nestedDataKey': DataValueFactory.string('Key'), | ||
}), | ||
}) | ||
.assortments([1, 2, 3]) | ||
.categoryPaths(b => b | ||
.path(p => p | ||
.category({ | ||
id: '1', | ||
displayName: [{ language: 'da', value: 'Værktøj' }], | ||
}) | ||
.category({ | ||
id: '2', | ||
displayName: [{ language: 'da', value: 'Udendørs' }], | ||
}) | ||
.category({ | ||
id: '3', | ||
displayName: [{ language: 'da', value: 'Skovle' }], | ||
}))); | ||
|
||
await integrator.updateContentCategory(category.build()); | ||
|
||
const enable = new ContentCategoryAdministrativeActionBuilder({ | ||
filters: (f) => f.addContentCategoryDataFilter('UnixTimeStamp', c => c.addEqualsCondition(DataValueFactory.number(unixTimeStamp))), | ||
kind: 'Enable', | ||
}); | ||
await integrator.executeContentCategoryAdministrativeAction(enable.build()); | ||
|
||
const disable = new ContentCategoryAdministrativeActionBuilder({ | ||
filters: (f) => f.addContentCategoryDataFilter('UnixTimeStamp', c => c.addEqualsCondition(DataValueFactory.number(unixTimeStamp), /* negated: */ true)), | ||
kind: 'Disable', | ||
}); | ||
await integrator.executeContentCategoryAdministrativeAction(disable.build()); | ||
}); |
Oops, something went wrong.