Skip to content

Commit

Permalink
refactor: some refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
MXPOL committed Oct 15, 2023
1 parent 19cc425 commit 92abd4b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 31 deletions.
2 changes: 1 addition & 1 deletion apps/velo-external-db/test/e2e/app_data.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion libs/external-db-mongo/src/mongo_data_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number> {
Expand Down
32 changes: 3 additions & 29 deletions libs/velo-external-db-core/src/converters/data_utils.ts
Original file line number Diff line number Diff line change
@@ -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))
Expand All @@ -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 }
}
}


0 comments on commit 92abd4b

Please sign in to comment.