diff --git a/src/datasources/product-api.ts b/src/datasources/product-api.ts index a2a0af7..ae00070 100644 --- a/src/datasources/product-api.ts +++ b/src/datasources/product-api.ts @@ -828,9 +828,7 @@ export class ProductAPI extends BaseSQLDataSource { WHERE ppf.value IN (${whereClause}); `; - const res = await this.cachedRaw(query) - .cache(MINUTE) - .then((data) => data.rows); + const res = await this.knex.raw(query).then((data) => data.rows); if (!res.length) { throw new UserInputError('No articles found'); diff --git a/src/datasources/texts-api.ts b/src/datasources/texts-api.ts index 29a653f..f8f8bb4 100644 --- a/src/datasources/texts-api.ts +++ b/src/datasources/texts-api.ts @@ -14,9 +14,13 @@ export class TextsAPI extends SQLDataSource { this.marketLocaleApi = marketLocaleApi; } - async translateProductName(name: string, oldPath, newPath): Promise { - // Check if we have an entry already - const textKey = await this.upsertTextId(newPath, oldPath); + async translateProductName( + name: string, + oldPath: string, + newPath: string, + ): Promise { + // Check if we have an entry already, if so update it + const textId = await this.upsertTextId(newPath, oldPath); const locales = await this.marketLocaleApi.getLocales(); for (let i = 0; i < locales.length; i++) { @@ -31,7 +35,7 @@ export class TextsAPI extends SQLDataSource { }; const translated = await translateText(input); - await this.upsertTextDataEntry(textKey.textid, translated, locales[i].id); + await this.upsertTextDataEntry(textId, translated, locales[i].id); } } @@ -73,17 +77,28 @@ export class TextsAPI extends SQLDataSource { } /** - * Upsert translated entry to the i18n-texts table + * Upsert translated entry to the i18n-texts table returning the entry (textId) * @param newKey the new name of the text key * @param localeId the old name of the text key */ - private async upsertTextId(newKey: string, oldKey: string) { + private async upsertTextId(newKey: string, oldKey: string): Promise { let textEntry = await this.knex .select('*') .from('i18n-texts') - .where({ name: oldKey }) + .where({ name: oldKey, category: 'productTitles' }) .first(); + const textNewEntry = await this.knex + .select('*') + .from('i18n-texts') + .where({ name: newKey, category: 'productTitles' }) + .first(); + + // New key did exist, which is kind of wrong but return it for updating the name + if (textNewEntry?.textid) { + return textNewEntry.textid; + } + let textId = textEntry?.textid; // No entry, create one if (!textId) { @@ -99,8 +114,8 @@ export class TextsAPI extends SQLDataSource { await this.knex .table('i18n-texts') .update({ name: newKey }) - .where({ name: oldKey }); + .where({ name: oldKey, category: 'productTitles' }); } - return textEntry; + return textEntry.textid; } } diff --git a/src/index.ts b/src/index.ts index 6ee1016..8ef1870 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,7 +15,7 @@ import { MarketLocaleAPI } from './datasources/market-locale-api'; import { ImageServerApi } from './datasources/imageserver-api'; import { InteriorAPI } from './datasources/interior-api'; -import { ClaimVerifyResult, verifyToken } from './cognito/cognito-client'; +import { verifyToken } from './cognito/cognito-client'; import { readFileSync } from 'fs'; import { InteriorsLambdaAPI } from './datasources/interiors-lambda-api'; import { TextsAPI } from './datasources/texts-api'; @@ -24,7 +24,7 @@ const typeDefs = readFileSync( path.join(__dirname, './schema.graphql'), ).toString('utf-8'); -// Should we convert columns? +// Converts column names to CamelCase const knexConfig = knexStringcase(dbConfig); // set up any dataSources our resolvers need