bonsaif 1.10.36 → 1.10.37
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/lib/hookup/mongoose.js +20 -2
- package/package.json +1 -1
package/lib/hookup/mongoose.js
CHANGED
|
@@ -736,7 +736,25 @@ const distinct = async (options, db, collection, query) => {
|
|
|
736
736
|
* API - Router principal para todas las operaciones
|
|
737
737
|
*/
|
|
738
738
|
const api = async (options, db, body) => {
|
|
739
|
-
|
|
739
|
+
let { dml = '', collection = '' } = body;
|
|
740
|
+
|
|
741
|
+
// Compatibilidad con formato MongoDB: collection puede venir en json.[dml]
|
|
742
|
+
if (!collection && dml) {
|
|
743
|
+
collection = body[dml] || '';
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
// Si aún no hay collection, intentar extraer del body
|
|
747
|
+
if (!collection) {
|
|
748
|
+
const possibleDmls = ['find', 'findOne', 'insert', 'update', 'updateMany',
|
|
749
|
+
'delete', 'deleteMany', 'upsert', 'count', 'aggregate', 'distinct'];
|
|
750
|
+
for (const possibleDml of possibleDmls) {
|
|
751
|
+
if (body[possibleDml]) {
|
|
752
|
+
dml = possibleDml;
|
|
753
|
+
collection = body[possibleDml];
|
|
754
|
+
break;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
}
|
|
740
758
|
|
|
741
759
|
if (!collection) {
|
|
742
760
|
return {
|
|
@@ -745,7 +763,7 @@ const api = async (options, db, body) => {
|
|
|
745
763
|
time: 0,
|
|
746
764
|
code: 400,
|
|
747
765
|
error: 1,
|
|
748
|
-
msg: 'Se requiere especificar "collection"'
|
|
766
|
+
msg: 'Se requiere especificar "collection" en body.collection o body.[dml]'
|
|
749
767
|
},
|
|
750
768
|
data: []
|
|
751
769
|
};
|