Skip to content
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

feat(project): added more support for project indexes #241

Merged
merged 2 commits into from
Oct 22, 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
5 changes: 5 additions & 0 deletions .changeset/tough-bobcats-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@labdigital/commercetools-mock": minor
---

Added support for more search indexes on projects
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"devDependencies": {
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@commercetools/platform-sdk": "7.11.0",
"@commercetools/platform-sdk": "7.17.0",
"@stylistic/eslint-plugin": "^1.6.2",
"@types/basic-auth": "^1.1.8",
"@types/body-parser": "^1.19.5",
Expand Down
34 changes: 9 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 26 additions & 1 deletion src/repositories/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
ProjectChangeCountriesAction,
ProjectChangeCountryTaxRateFallbackEnabledAction,
ProjectChangeCurrenciesAction,
ProjectChangeCustomerSearchStatusAction,
ProjectChangeLanguagesAction,
ProjectChangeMessagesConfigurationAction,
ProjectChangeNameAction,
Expand Down Expand Up @@ -95,6 +96,18 @@ class ProjectUpdateHandler
resource.currencies = currencies;
}

changeCustomerSearchStatus(
context: RepositoryContext,
resource: Writable<Project>,
{ status }: ProjectChangeCustomerSearchStatusAction,
) {
if (!resource.searchIndexing?.customers) {
throw new Error("Invalid project state");
}
resource.searchIndexing.customers.status = status;
resource.searchIndexing.customers.lastModifiedAt = new Date().toISOString();
}

changeLanguages(
context: RepositoryContext,
resource: Writable<Project>,
Expand Down Expand Up @@ -150,8 +163,20 @@ class ProjectUpdateHandler
changeProductSearchIndexingEnabled(
context: RepositoryContext,
resource: Writable<Project>,
{ enabled }: ProjectChangeProductSearchIndexingEnabledAction,
{ enabled, mode }: ProjectChangeProductSearchIndexingEnabledAction,
) {
if (mode === "ProductsSearch") {
if (!resource.searchIndexing?.productsSearch) {
throw new Error("Invalid project state");
}
resource.searchIndexing.productsSearch.status = enabled
? "Activated"
: "Deactivated";
resource.searchIndexing.productsSearch.lastModifiedAt =
new Date().toISOString();
return;
}

if (!resource.searchIndexing?.products) {
throw new Error("Invalid project state");
}
Expand Down
6 changes: 6 additions & 0 deletions src/services/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@ describe("Project", () => {
},
name: "",
searchIndexing: {
customers: {
status: "Deactivated",
},
orders: {
status: "Deactivated",
},
products: {
status: "Deactivated",
},
productsSearch: {
status: "Deactivated",
},
},
trialUntil: "2018-12",
} as Project);
Expand Down
6 changes: 6 additions & 0 deletions src/storage/in-memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,15 @@ export class InMemoryStorage extends AbstractStorage {
products: {
status: "Deactivated",
},
productsSearch: {
status: "Deactivated",
},
orders: {
status: "Deactivated",
},
customers: {
status: "Deactivated",
},
},
version: 1,
};
Expand Down