hola-server 0.3.16 → 0.3.18
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/db/entity.js +30 -21
- package/package.json +1 -1
package/db/entity.js
CHANGED
|
@@ -632,16 +632,6 @@ class Entity {
|
|
|
632
632
|
}
|
|
633
633
|
}
|
|
634
634
|
|
|
635
|
-
//check all the ref by array first
|
|
636
|
-
const has_refer_by_array = await this.check_refer_entity(id_array);
|
|
637
|
-
if (has_refer_by_array.length > 0) {
|
|
638
|
-
const array = [...new Set(has_refer_by_array)];
|
|
639
|
-
if (is_log_error()) {
|
|
640
|
-
log_error(LOG_ENTITY, "has_refer_by_array:" + JSON.stringify(array));
|
|
641
|
-
}
|
|
642
|
-
return { code: HAS_REF, err: array };
|
|
643
|
-
}
|
|
644
|
-
|
|
645
635
|
if (this.meta.delete) {
|
|
646
636
|
const { code, err } = await this.meta.delete(this, id_array);
|
|
647
637
|
if (err || code != SUCCESS) {
|
|
@@ -651,6 +641,16 @@ class Entity {
|
|
|
651
641
|
return { code: code, err: err };
|
|
652
642
|
}
|
|
653
643
|
} else {
|
|
644
|
+
//check all the ref by array first
|
|
645
|
+
const has_refer_by_array = await this.check_refer_entity(id_array);
|
|
646
|
+
if (has_refer_by_array.length > 0) {
|
|
647
|
+
const array = [...new Set(has_refer_by_array)];
|
|
648
|
+
if (is_log_error()) {
|
|
649
|
+
log_error(LOG_ENTITY, "has_refer_by_array:" + JSON.stringify(array));
|
|
650
|
+
}
|
|
651
|
+
return { code: HAS_REF, err: array };
|
|
652
|
+
}
|
|
653
|
+
|
|
654
654
|
const result = await this.delete(query);
|
|
655
655
|
if (result.ok != 1) {
|
|
656
656
|
if (is_log_error()) {
|
|
@@ -658,17 +658,16 @@ class Entity {
|
|
|
658
658
|
}
|
|
659
659
|
return { code: ERROR, err: "delete record is failed" };
|
|
660
660
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
await refer_by_entity.delete_refer_entity(ref_field.name, id_array)
|
|
661
|
+
//delete other ref_by entity based on delete mode
|
|
662
|
+
for (let i = 0; i < this.meta.ref_by_metas.length; i++) {
|
|
663
|
+
const ref_by_meta = this.meta.ref_by_metas[i];
|
|
664
|
+
const ref_fields = ref_by_meta.ref_fields.filter(field => field.ref == this.meta.collection);
|
|
665
|
+
for (let j = 0; j < ref_fields.length; j++) {
|
|
666
|
+
const ref_field = ref_fields[j];
|
|
667
|
+
if (ref_field.delete == DELETE_MODE.cascade) {
|
|
668
|
+
const refer_by_entity = new Entity(ref_by_meta);
|
|
669
|
+
await refer_by_entity.delete_refer_entity(ref_field.name, id_array)
|
|
670
|
+
}
|
|
672
671
|
}
|
|
673
672
|
}
|
|
674
673
|
}
|
|
@@ -746,6 +745,16 @@ class Entity {
|
|
|
746
745
|
return this.db.delete(this.meta.collection, query);
|
|
747
746
|
}
|
|
748
747
|
|
|
748
|
+
/**
|
|
749
|
+
* Remove the records from mongodb
|
|
750
|
+
* @param {*} id can be array or string
|
|
751
|
+
* @returns
|
|
752
|
+
*/
|
|
753
|
+
delete_by_id(id) {
|
|
754
|
+
const query = Array.isArray(id) ? oid_queries(id) : oid_query(id);
|
|
755
|
+
return this.db.delete(this.meta.collection, query);
|
|
756
|
+
}
|
|
757
|
+
|
|
749
758
|
/**
|
|
750
759
|
* Find the objects that are refered by other entity
|
|
751
760
|
* @param {ref value} value
|