-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AutomaticTranslationConfigDataSource fix
now returns and accepts domain object instead of a db raw type
- Loading branch information
Showing
6 changed files
with
73 additions
and
41 deletions.
There are no files selected for viewing
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
6 changes: 3 additions & 3 deletions
6
...nalIntegrations.v2/automaticTranslation/contracts/AutomaticTranslationConfigDataSource.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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { AutomaticTranslationConfig } from 'shared/types/settingsType'; | ||
import { RawAutomaticTranslationConfig } from '../model/RawAutomaticTranslationConfig'; | ||
|
||
export interface AutomaticTranslationConfigDataSource { | ||
get(): Promise<AutomaticTranslationConfig>; | ||
update(config: AutomaticTranslationConfig): Promise<AutomaticTranslationConfig>; | ||
get(): Promise<RawAutomaticTranslationConfig>; | ||
update(config: RawAutomaticTranslationConfig): Promise<RawAutomaticTranslationConfig>; | ||
} |
16 changes: 13 additions & 3 deletions
16
...ntegrations.v2/automaticTranslation/database/MongoAutomaticTranslationConfigDataSource.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
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
48 changes: 48 additions & 0 deletions
48
app/api/externalIntegrations.v2/automaticTranslation/model/RawAutomaticTranslationConfig.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,48 @@ | ||
import { LanguageISO6391 } from 'shared/types/commonTypes'; | ||
import { AutomaticTranslationTemplateConfig } from './AutomaticTranslationTemplateConfig'; | ||
import { Property } from 'api/templates.v2/model/Property'; | ||
import { AutomaticTranslationConfig } from './AutomaticTranslationConfig'; | ||
|
||
class RawAutomaticTranslationConfig { | ||
readonly active: boolean; | ||
|
||
readonly templates: AutomaticTranslationTemplateConfig[]; | ||
|
||
constructor(active: boolean, templates: AutomaticTranslationTemplateConfig[]) { | ||
this.active = active; | ||
this.templates = templates; | ||
} | ||
|
||
getValidConfig( | ||
languages: LanguageISO6391[], | ||
validProperties: Property[] | ||
): AutomaticTranslationConfig { | ||
const validPropertiesMap = validProperties.reduce( | ||
(memo, property) => { | ||
// eslint-disable-next-line no-param-reassign | ||
memo[property.id] = property; | ||
return memo; | ||
}, | ||
{} as { [k: string]: Property } | ||
); | ||
|
||
const validPropertiesIds = Object.keys(validPropertiesMap); | ||
|
||
const templates = (this.templates || []).map( | ||
templateConfig => | ||
new AutomaticTranslationTemplateConfig( | ||
templateConfig.template, | ||
(templateConfig.properties || []).filter( | ||
propertyId => | ||
validPropertiesIds.includes(propertyId) && | ||
validPropertiesMap[propertyId].template === templateConfig.template | ||
), | ||
templateConfig.commonProperties | ||
) | ||
); | ||
|
||
return new AutomaticTranslationConfig(this.active, languages, templates); | ||
} | ||
} | ||
|
||
export { RawAutomaticTranslationConfig }; |
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