From 92abd4bb713344d5442661c18d22c9fd71b7fb09 Mon Sep 17 00:00:00 2001 From: Max Polsky Date: Sun, 15 Oct 2023 12:29:38 +0300 Subject: [PATCH] refactor: some refactors --- .../test/e2e/app_data.e2e.spec.ts | 2 +- .../src/mongo_data_provider.ts | 2 +- .../src/converters/data_utils.ts | 32 ++----------------- 3 files changed, 5 insertions(+), 31 deletions(-) diff --git a/apps/velo-external-db/test/e2e/app_data.e2e.spec.ts b/apps/velo-external-db/test/e2e/app_data.e2e.spec.ts index 6f4171865..a82576f06 100644 --- a/apps/velo-external-db/test/e2e/app_data.e2e.spec.ts +++ b/apps/velo-external-db/test/e2e/app_data.e2e.spec.ts @@ -80,7 +80,7 @@ describe(`Velo External DB Data REST API: ${currentDbImplementationName()}`, () pagingMetadata: data.pagingMetadata(ctx.items.length, ctx.items.length) }) }) - testIfSupportedOperationsIncludes(supportedOperations, [ AtomicBulkInsert, PrimaryKey ])('insert api should return the inserted items if they don\'t exist and if they do, it should return an error object', async() => { + testIfSupportedOperationsIncludes(supportedOperations, [ AtomicBulkInsert, PrimaryKey ])('bulk insert api should return the inserted items if they don\'t exist and if they do, it should return an error object', async() => { await schema.givenCollection(ctx.collectionName, [ctx.column], authOwner) await data.givenItems([ ctx.items[1] ], ctx.collectionName, authAdmin) diff --git a/libs/external-db-mongo/src/mongo_data_provider.ts b/libs/external-db-mongo/src/mongo_data_provider.ts index 3a6a730a8..79432ce23 100644 --- a/libs/external-db-mongo/src/mongo_data_provider.ts +++ b/libs/external-db-mongo/src/mongo_data_provider.ts @@ -53,7 +53,7 @@ export default class DataProvider implements IDataProvider { // In case the updated item matches the item in the DB, nModified will be 0 // But the update did not fail, the updated item is indeed in the db so in that case we will return nMatched - return result.nModified ? result.nModified: result.nMatched + return result.nMatched } async delete(collectionName: string, itemIds: string[]): Promise { diff --git a/libs/velo-external-db-core/src/converters/data_utils.ts b/libs/velo-external-db-core/src/converters/data_utils.ts index e81e632bc..8cfa29dbe 100644 --- a/libs/velo-external-db-core/src/converters/data_utils.ts +++ b/libs/velo-external-db-core/src/converters/data_utils.ts @@ -1,8 +1,7 @@ -import { isDate, errors as domainErrors } from '@wix-velo/velo-external-db-commons' +import { isDate } from '@wix-velo/velo-external-db-commons' import { Item, ItemWithId } from '@wix-velo/velo-external-db-types' import * as crypto from 'crypto' -import { ApiErrors } from '../spi-model/errors' -import { ApplicationError } from '../spi-model/data_source' + export const asWixData = (item: Item) => { return generateIdsIfNeeded(packDates(item)) @@ -20,30 +19,5 @@ const packDates = (item: Item) => Object.entries(item) .reduce((o, [k, v]) => ({ ...o, [k]: isDate(v) ? { $date: new Date(v).toISOString() } : v }), {}) -export const domainToSpiErrorTranslator = (err: any): ApplicationError => { - switch(err.constructor) { - case domainErrors.ItemAlreadyExists: - const itemAlreadyExists: domainErrors.ItemAlreadyExists = err - return { code: ApiErrors.WDE0074, description: itemAlreadyExists.message } - - case domainErrors.CollectionDoesNotExists: - const collectionDoesNotExists: domainErrors.CollectionDoesNotExists = err - return { code: ApiErrors.WDE0025, description: collectionDoesNotExists.message } - - case domainErrors.FieldAlreadyExists: - const fieldAlreadyExists: domainErrors.FieldAlreadyExists = err - return { code: ApiErrors.WDE0074, description: fieldAlreadyExists.message } - - case domainErrors.FieldDoesNotExist: - const fieldDoesNotExist: domainErrors.FieldDoesNotExist = err - return { code: ApiErrors.WDE0147, description: fieldDoesNotExist.message } - - case domainErrors.UnsupportedSchemaOperation: - const unsupportedSchemaOperation: domainErrors.UnsupportedSchemaOperation = err - return { code: ApiErrors.WDE0025, description: unsupportedSchemaOperation.message } - - default: - return { code: ApiErrors.WDE0112, description: err.message } - } -} +