@keltoi/hydra 2.0.6 → 2.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +15 -5
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -71,6 +71,8 @@ class Entity{
|
|
|
71
71
|
get key(){ return this.#key }
|
|
72
72
|
get data(){ return this.#data }
|
|
73
73
|
|
|
74
|
+
set key(value = {}){ this.#key = value; }
|
|
75
|
+
|
|
74
76
|
get $(){
|
|
75
77
|
return { ...this.#key, ...this.#data }
|
|
76
78
|
}
|
|
@@ -461,23 +463,31 @@ let Repository$1 = class Repository{
|
|
|
461
463
|
create = (entity = new Entity())=>
|
|
462
464
|
this.myContext()
|
|
463
465
|
.insert(entity.data,Object.keys(entity.key))
|
|
464
|
-
.then(ids=>
|
|
465
|
-
|
|
466
|
-
|
|
466
|
+
.then(ids=>{
|
|
467
|
+
entity.key = ids[0];
|
|
468
|
+
|
|
469
|
+
return new Result({ data:entity.$ })
|
|
470
|
+
})
|
|
467
471
|
.catch(err=>Promise.reject( new Result({code:500,message:err}) ))
|
|
468
472
|
|
|
469
473
|
update = (entity = new Entity())=>
|
|
470
474
|
this.myContext()
|
|
471
475
|
.where(entity.key)
|
|
472
476
|
.update(entity.data)
|
|
473
|
-
.then(affected=>
|
|
477
|
+
.then(affected=> affected > 0
|
|
478
|
+
? new Result({ code:200,message:`${this.#name} updated` })
|
|
479
|
+
: new Result({ code:404,message:'Not found' })
|
|
480
|
+
)
|
|
474
481
|
.catch(err=>Promise.reject( new Result({code:500,message:err}) ))
|
|
475
482
|
|
|
476
483
|
delete = (entity = new Entity())=>
|
|
477
484
|
this.myContext()
|
|
478
485
|
.where(entity.key)
|
|
479
486
|
.del()
|
|
480
|
-
.then(affected=>
|
|
487
|
+
.then(affected=> affected > 0
|
|
488
|
+
? new Result({ code:200,message:`${this.#name} deleted` })
|
|
489
|
+
: new Result({ code:404,message:'Not found' })
|
|
490
|
+
)
|
|
481
491
|
.catch(err=>Promise.reject( new Result({code:500,message:err}) ))
|
|
482
492
|
|
|
483
493
|
get = (entity = new Entity())=>
|