-
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 #49 from Relewise/feat/brand-updates
feat: brand updates
- Loading branch information
Showing
6 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
packages/integrations/src/builders/brands/brandAdministrativeActionBuilder.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 { BrandAdministrativeAction, FilterBuilder } from '@relewise/client'; | ||
|
||
export class BrandAdministrativeActionBuilder { | ||
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(): BrandAdministrativeAction { | ||
const filters = this.filterBuilder.build(); | ||
|
||
if (!filters || !filters.items || filters.items.length === 0) { | ||
throw new Error('No filters were provided for the brand administrative action'); | ||
} | ||
|
||
return { | ||
$type: 'Relewise.Client.DataTypes.BrandAdministrativeAction, Relewise.Client', | ||
...(this.language && { language: { value: this.language } }), | ||
...(this.currency && { currency: { value: this.currency } }), | ||
filters: filters, | ||
kind: this.kind, | ||
}; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
packages/integrations/src/builders/brands/brandUpdateBuilder.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,40 @@ | ||
import { DataValue, Brand, BrandUpdate } from '@relewise/client'; | ||
|
||
export class BrandUpdateBuilder { | ||
private brand: Brand; | ||
private updateKind: 'None' | 'UpdateAndAppend' | 'ReplaceProvidedProperties' | 'ClearAndReplace'; | ||
|
||
constructor({ id, updateKind }: { | ||
id: string, | ||
updateKind: 'None' | 'UpdateAndAppend' | 'ReplaceProvidedProperties' | 'ClearAndReplace', | ||
}) { | ||
this.brand = { id: id }; | ||
this.updateKind = updateKind; | ||
} | ||
|
||
displayName(name: string): this { | ||
this.brand.displayName = name; | ||
|
||
return this; | ||
} | ||
|
||
data(data: Record<string, DataValue | null>): this { | ||
this.brand.data = data as Record<string, DataValue>; // TODO remove dirty hack | ||
|
||
return this; | ||
} | ||
|
||
assortments(assortments: number[]): this { | ||
this.brand.assortments = assortments; | ||
|
||
return this; | ||
} | ||
|
||
build(): BrandUpdate { | ||
return { | ||
$type: 'Relewise.Client.DataTypes.BrandUpdate, Relewise.Client', | ||
brand: this.brand, | ||
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 './brandUpdateBuilder'; | ||
export * from './brandAdministrativeActionBuilder'; |
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
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
41 changes: 41 additions & 0 deletions
41
packages/integrations/tests/integration-tests/brands/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,41 @@ | ||
import { test } from '@jest/globals'; | ||
import { BrandUpdateBuilder, BrandAdministrativeActionBuilder, Integrator } 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 Brand', async() => { | ||
const brand = new BrandUpdateBuilder({ | ||
id: '1234', | ||
updateKind: 'ReplaceProvidedProperties', | ||
}) | ||
.displayName('HP') | ||
.data({ | ||
'UnixTimestamp': DataValueFactory.number(unixTimeStamp), | ||
'Description': DataValueFactory.string('Really nice Brand'), | ||
'Tags': DataValueFactory.stringCollection(['fall collection', 'blue', 'good-deal']), | ||
'InStock': DataValueFactory.boolean(true), | ||
'Removed': null, | ||
'Complex': DataValueFactory.object({ | ||
'nestedDataKey': DataValueFactory.string('Key'), | ||
}), | ||
}) | ||
.assortments([1, 2, 3]); | ||
|
||
await integrator.updateBrand(brand.build()); | ||
|
||
const enable = new BrandAdministrativeActionBuilder({ | ||
filters: (f) => f.addBrandDataFilter('UnixTimeStamp', c => c.addEqualsCondition(DataValueFactory.number(unixTimeStamp))), | ||
kind: 'Enable', | ||
}); | ||
await integrator.executeBrandAdministrativeAction(enable.build()); | ||
|
||
const disable = new BrandAdministrativeActionBuilder({ | ||
filters: (f) => f.addBrandDataFilter('UnixTimeStamp', c => c.addEqualsCondition(DataValueFactory.number(unixTimeStamp), /* negated: */ true)), | ||
kind: 'Disable', | ||
}); | ||
await integrator.executeBrandAdministrativeAction(disable.build()); | ||
}); |