@cocreate/crud-server
Advanced tools
Comparing version
@@ -0,1 +1,14 @@ | ||
# [1.14.0](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.13.7...v1.14.0) (2022-11-25) | ||
### Bug Fixes | ||
* querying an array of documents requires the _id to be wrapped in ObjectId ([d988da8](https://github.com/CoCreate-app/CoCreate-crud-server/commit/d988da872248cf68bbeaf4d47bec6d8875ddda23)) | ||
* replaced @cocreate/filter with @cocreate/utils fo search, query and sort functions ([f91fb78](https://github.com/CoCreate-app/CoCreate-crud-server/commit/f91fb78dea770b4afc72dd5ad2842e4745d659f8)) | ||
### Features | ||
* run dotNotationToObject on createDocument ([133cc30](https://github.com/CoCreate-app/CoCreate-crud-server/commit/133cc302771ef139642e47f31c0f308a69c07869)) | ||
## [1.13.7](https://github.com/CoCreate-app/CoCreate-crud-server/compare/v1.13.6...v1.13.7) (2022-11-24) | ||
@@ -2,0 +15,0 @@ |
{ | ||
"name": "@cocreate/crud-server", | ||
"version": "1.13.7", | ||
"version": "1.14.0", | ||
"description": "CoCreate-crud-server", | ||
@@ -43,3 +43,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@cocreate/docs": "^1.4.3", | ||
"@cocreate/docs": "^1.4.4", | ||
"@cocreate/utils": "^1.12.0", | ||
"csvtojson": "^2.0.10", | ||
@@ -46,0 +47,0 @@ "json-2-csv": "^3.10.3", |
'use strict'; | ||
const {replaceArray} = require("./utils.crud.js") | ||
const {searchData, sortData} = require("@cocreate/filter") | ||
const {searchData, sortData} = require("@cocreate/utils"); | ||
const mongodb = require('./mongodb/mongodb'); | ||
@@ -6,0 +5,0 @@ |
@@ -1,5 +0,3 @@ | ||
// const {mongoClient} = require("./db") | ||
const {MongoClient, ObjectId} = require('mongodb'); | ||
const {replaceArray} = require("../utils.crud.js") | ||
const {searchData, sortData} = require("@cocreate/filter") | ||
const {dotNotationToObject, searchData, sortData} = require('@cocreate/utils') | ||
@@ -321,2 +319,4 @@ function mongoClient(dbUrl) { | ||
if (action == 'createDocument') { | ||
data[type][i] = dotNotationToObject(data[type][i]) | ||
if (!data[type][i]._id) | ||
@@ -330,3 +330,3 @@ data[type][i]._id = ObjectId() | ||
if (data[type][i]._id) | ||
_ids.push(data[type][i]._id) | ||
_ids.push(ObjectId(data[type][i]._id)) | ||
} | ||
@@ -345,3 +345,3 @@ if (action =='updateDocument') { | ||
if (data[type][i]._id) { | ||
_ids.push(data[type][i]._id) | ||
_ids.push(ObjectId(data[type][i]._id)) | ||
documents.push({_id: data[type][i]._id, db: 'mongodb', database, collection}) | ||
@@ -454,3 +454,3 @@ } | ||
doc['modified'] = {on: data.timeStamp, by: data.user || data.clientId} | ||
_ids.push(doc._id) | ||
@@ -487,7 +487,6 @@ } | ||
collectionObj.updateMany(query, update, { | ||
upsert: false, | ||
upsert: data.upsert, | ||
projection | ||
}).then((result) => { | ||
}).catch((error) => { | ||
@@ -565,3 +564,3 @@ errorLog.push(error) | ||
if (data[type][0]) { | ||
update['$set'] = valueTypes(data[type][0]) | ||
update['$set'] = data[type][0] | ||
// update['$set']['organization_id'] = data['organization_id']; | ||
@@ -718,31 +717,2 @@ if (update['$set']['_id']) | ||
function valueTypes(data) { | ||
let object = {} | ||
if ( typeof data === 'object' ) { | ||
// update['$set'] = {} | ||
for (const [key, value] of Object.entries(data)) { | ||
let val; | ||
let valueType = typeof value; | ||
switch(valueType) { | ||
case 'string': | ||
val = value | ||
break; | ||
case 'number': | ||
val = Number(value) | ||
break; | ||
case 'object': | ||
if (Array.isArray(value)) | ||
val = new Array(...value) | ||
else | ||
val = new Object(value) | ||
break; | ||
default: | ||
val = value | ||
} | ||
object[key] = val | ||
} | ||
return object; | ||
} | ||
} | ||
function errorHandler(data, error, database, collection){ | ||
@@ -764,5 +734,22 @@ if (typeof error == 'object') | ||
function replaceArray(data) { | ||
let keys = Object.keys(data); | ||
let objectData = {}; | ||
keys.forEach((k) => { | ||
let nk = k | ||
if (/\[([0-9]*)\]/g.test(k)) { | ||
nk = nk.replace(/\[/g, '.'); | ||
if (nk.endsWith(']')) | ||
nk = nk.slice(0, -1) | ||
nk = nk.replace(/\]./g, '.'); | ||
nk = nk.replace(/\]/g, '.'); | ||
} | ||
objectData[nk] = data[k]; | ||
}); | ||
return objectData; | ||
} | ||
module.exports = { | ||
@@ -769,0 +756,0 @@ databaseStats, |
98797
0.05%5
25%15
-6.25%960
-3.32%+ Added
Updated