Skip to content

Commit

Permalink
fix(api-i18n-ddb): entity
Browse files Browse the repository at this point in the history
  • Loading branch information
brunozoric committed Dec 16, 2024
1 parent ac14f84 commit f9de254
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 69 deletions.
70 changes: 34 additions & 36 deletions packages/api-i18n-ddb/src/definitions/localeEntity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Entity, Table } from "@webiny/db-dynamodb/toolbox";
import type { Table } from "@webiny/db-dynamodb/toolbox";
import type { I18NContext } from "@webiny/api-i18n/types";
import { getExtraAttributes } from "@webiny/db-dynamodb/utils/attributes";
import { getExtraAttributesFromPlugins } from "@webiny/db-dynamodb/utils/attributes";
import type { IEntity } from "@webiny/db-dynamodb";
import { createEntity } from "@webiny/db-dynamodb";

Expand All @@ -12,38 +12,36 @@ export interface ILocaleEntityParams {
export default (params: ILocaleEntityParams): IEntity => {
const { context, table } = params;
const entityName = "I18NLocale";
const attributes = getExtraAttributes(context, entityName);
return createEntity(
new Entity({
name: entityName,
table,
attributes: {
PK: {
partitionKey: true
},
SK: {
sortKey: true
},
createdOn: {
type: "string"
},
createdBy: {
type: "map"
},
code: {
type: "string"
},
default: {
type: "boolean"
},
webinyVersion: {
type: "string"
},
tenant: {
type: "string"
},
...attributes
}
})
);
const attributes = getExtraAttributesFromPlugins(context.plugins, entityName);
return createEntity({
name: entityName,
table,
attributes: {
PK: {
partitionKey: true
},
SK: {
sortKey: true
},
createdOn: {
type: "string"
},
createdBy: {
type: "map"
},
code: {
type: "string"
},
default: {
type: "boolean"
},
webinyVersion: {
type: "string"
},
tenant: {
type: "string"
},
...attributes
}
});
};
42 changes: 20 additions & 22 deletions packages/api-i18n-ddb/src/definitions/systemEntity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Entity, Table } from "@webiny/db-dynamodb/toolbox";
import type { Table } from "@webiny/db-dynamodb/toolbox";
import type { I18NContext } from "@webiny/api-i18n/types";
import { getExtraAttributesFromPlugins } from "@webiny/db-dynamodb/utils/attributes";
import type { IEntity } from "@webiny/db-dynamodb";
Expand All @@ -11,25 +11,23 @@ export default (params: {
const { context, table } = params;
const entityName = "I18NSystem";
const attributes = getExtraAttributesFromPlugins(context.plugins, entityName);
return createEntity(
new Entity({
name: entityName,
table,
attributes: {
PK: {
partitionKey: true
},
SK: {
sortKey: true
},
version: {
type: "string"
},
tenant: {
type: "string"
},
...attributes
}
})
);
return createEntity({
name: entityName,
table,
attributes: {
PK: {
partitionKey: true
},
SK: {
sortKey: true
},
version: {
type: "string"
},
tenant: {
type: "string"
},
...attributes
}
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@ import type { Table } from "@webiny/db-dynamodb/toolbox";
import WebinyError from "@webiny/error";
import defineTable from "~/definitions/table";
import defineLocaleEntity from "~/definitions/localeEntity";
import type { IEntity, QueryAllParams } from "@webiny/db-dynamodb";
import {
cleanupItems,
createListResponse,
filterItems,
queryAll,
sortItems
} from "@webiny/db-dynamodb";
import type { IEntity, IEntityQueryAllParams } from "@webiny/db-dynamodb";
import { cleanupItems, createListResponse, filterItems, sortItems } from "@webiny/db-dynamodb";
import { LocaleDynamoDbFieldPlugin } from "~/plugins/LocaleDynamoDbFieldPlugin";

interface ConstructorParams {
Expand Down Expand Up @@ -210,7 +204,7 @@ export class LocalesStorageOperations implements I18NLocalesStorageOperations {

let results: I18NLocaleData[] = [];
try {
results = await queryAll<I18NLocaleData>(queryAllParams);
results = await this.entity.queryAll<I18NLocaleData>(queryAllParams);
} catch (ex) {
throw new WebinyError(
ex.message || "Cannot list I18N locales.",
Expand Down Expand Up @@ -272,7 +266,7 @@ export class LocalesStorageOperations implements I18NLocalesStorageOperations {

private createQueryAllParamsOptions(
params: I18NLocalesStorageOperationsListParams
): QueryAllParams {
): IEntityQueryAllParams {
const { where } = params;

const tenant = where.tenant;
Expand All @@ -285,7 +279,6 @@ export class LocalesStorageOperations implements I18NLocalesStorageOperations {
delete where.default;
}
return {
entity: this.entity.entity,
partitionKey,
options: {}
};
Expand Down

0 comments on commit f9de254

Please sign in to comment.