Skip to content

Commit 1c9f082

Browse files
authored
feat(project): added more support for project indexes (#241)
1 parent d11863d commit 1c9f082

6 files changed

Lines changed: 53 additions & 27 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@labdigital/commercetools-mock": minor
3+
---
4+
5+
Added support for more search indexes on projects

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"devDependencies": {
4747
"@changesets/changelog-github": "^0.5.0",
4848
"@changesets/cli": "^2.27.1",
49-
"@commercetools/platform-sdk": "7.11.0",
49+
"@commercetools/platform-sdk": "7.17.0",
5050
"@stylistic/eslint-plugin": "^1.6.2",
5151
"@types/basic-auth": "^1.1.8",
5252
"@types/body-parser": "^1.19.5",

pnpm-lock.yaml

Lines changed: 9 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/repositories/project.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
ProjectChangeCountriesAction,
66
ProjectChangeCountryTaxRateFallbackEnabledAction,
77
ProjectChangeCurrenciesAction,
8+
ProjectChangeCustomerSearchStatusAction,
89
ProjectChangeLanguagesAction,
910
ProjectChangeMessagesConfigurationAction,
1011
ProjectChangeNameAction,
@@ -95,6 +96,18 @@ class ProjectUpdateHandler
9596
resource.currencies = currencies;
9697
}
9798

99+
changeCustomerSearchStatus(
100+
context: RepositoryContext,
101+
resource: Writable<Project>,
102+
{ status }: ProjectChangeCustomerSearchStatusAction,
103+
) {
104+
if (!resource.searchIndexing?.customers) {
105+
throw new Error("Invalid project state");
106+
}
107+
resource.searchIndexing.customers.status = status;
108+
resource.searchIndexing.customers.lastModifiedAt = new Date().toISOString();
109+
}
110+
98111
changeLanguages(
99112
context: RepositoryContext,
100113
resource: Writable<Project>,
@@ -150,8 +163,20 @@ class ProjectUpdateHandler
150163
changeProductSearchIndexingEnabled(
151164
context: RepositoryContext,
152165
resource: Writable<Project>,
153-
{ enabled }: ProjectChangeProductSearchIndexingEnabledAction,
166+
{ enabled, mode }: ProjectChangeProductSearchIndexingEnabledAction,
154167
) {
168+
if (mode === "ProductsSearch") {
169+
if (!resource.searchIndexing?.productsSearch) {
170+
throw new Error("Invalid project state");
171+
}
172+
resource.searchIndexing.productsSearch.status = enabled
173+
? "Activated"
174+
: "Deactivated";
175+
resource.searchIndexing.productsSearch.lastModifiedAt =
176+
new Date().toISOString();
177+
return;
178+
}
179+
155180
if (!resource.searchIndexing?.products) {
156181
throw new Error("Invalid project state");
157182
}

src/services/project.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,18 @@ describe("Project", () => {
3939
},
4040
name: "",
4141
searchIndexing: {
42+
customers: {
43+
status: "Deactivated",
44+
},
4245
orders: {
4346
status: "Deactivated",
4447
},
4548
products: {
4649
status: "Deactivated",
4750
},
51+
productsSearch: {
52+
status: "Deactivated",
53+
},
4854
},
4955
trialUntil: "2018-12",
5056
} as Project);

src/storage/in-memory.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,15 @@ export class InMemoryStorage extends AbstractStorage {
8787
products: {
8888
status: "Deactivated",
8989
},
90+
productsSearch: {
91+
status: "Deactivated",
92+
},
9093
orders: {
9194
status: "Deactivated",
9295
},
96+
customers: {
97+
status: "Deactivated",
98+
},
9399
},
94100
version: 1,
95101
};

0 commit comments

Comments
 (0)