diff --git a/src/datasources/product-api.ts b/src/datasources/product-api.ts index fc02df1..ad40f2a 100644 --- a/src/datasources/product-api.ts +++ b/src/datasources/product-api.ts @@ -515,6 +515,7 @@ export class ProductAPI extends BaseSQLDataSource { this.updateProductField(id, 'artNo', `e${id}`); await this.updateProductField(id, 'name', formattedName); await this.updateProductField(id, 'batch', fixedBatch); + return id; } @@ -537,15 +538,6 @@ export class ProductAPI extends BaseSQLDataSource { promises.push(promise); } - if (oldProd.fields.name !== info.name) { - const promise = this.textsApi.translateProductName( - info.name, - oldProd.path, - uniquePath, - ); - promises.push(promise); - } - const publishingDate = info.publishingDate; // Some notes about timezone here: // If client sets YYYY-MM-10T00:00:00.000+02 (which admin does) the timestamp diff --git a/src/datasources/texts-api.ts b/src/datasources/texts-api.ts index 3f18efa..ef7744b 100644 --- a/src/datasources/texts-api.ts +++ b/src/datasources/texts-api.ts @@ -43,108 +43,8 @@ export class TextsAPI extends SQLDataSource { } } - 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++) { - let langCode = this.getLanguageCode(locales[i]); - // If we have a fallback locale we skip translating - if (locales[i].fallbackId) { - continue; - } - const input: TranslateInput = { - text: name, - targetLanguageCode: langCode, - }; - const translated = await translateText(input); - - await this.upsertTextDataEntry(textId, translated, locales[i].id); - } - } - - /** - * Upsert translated entry to the i18n-texts_data table - * @param text The translated text to insert - * @param localeId The id of the locale - */ - private async upsertTextDataEntry( - textId: number, - text: string, - localeId: number, - ) { - // Check if we have an entry already - const textDataEntry = await this.knex - .select('*') - .from('i18n-texts_data') - .where({ textid: textId, locale_id: localeId }) - .first(); - - if (textDataEntry) { - // Update existing entry - await this.knex('i18n-texts_data') - .where({ textid: textId, locale_id: localeId }) - .update({ text: text }); - } else { - //Insert new entry - await this.knex('i18n-texts_data').insert({ - text: text, - textid: textId, - locale_id: localeId, - }); - } - } - private getLanguageCode(locale: Locale) { let langCode = locale.value.substr(0, 2); return langCode == 'nn' ? 'no' : langCode; } - - /** - * 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): Promise { - let textEntry = await this.knex - .select('*') - .from('i18n-texts') - .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) { - const res = await this.knex('i18n-texts') - .insert({ name: newKey, category: 'productTitles' }) - .returning('*'); - - textEntry = res[0]; - } - - // Update table if different - if (oldKey !== newKey) { - await this.knex - .table('i18n-texts') - .update({ name: newKey }) - .where({ name: oldKey, category: 'productTitles' }); - } - return textEntry.textid; - } }