yaml-admin-api 0.0.32 → 0.0.34
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/package.json
CHANGED
|
@@ -164,13 +164,15 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
|
|
|
164
164
|
* @param {*} entity_name
|
|
165
165
|
*/
|
|
166
166
|
const recalcurateAutoGenerateIndex = async (db, entity_name) => {
|
|
167
|
-
const list = await db.collection(entity_name).find({})
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
const list = await db.collection(entity_name).find({})
|
|
168
|
+
.project({ [key_field.name]: 1, _id: 0 })
|
|
169
|
+
.sort({ [key_field.name]: -1 }).limit(1).toArray()
|
|
170
|
+
const counter = await db.collection('counters').findOne({ _id: entity_name })
|
|
171
|
+
if(list.length > 0 && counter) {
|
|
170
172
|
let seq = counter?.seq || 0
|
|
171
173
|
let maxKey = list[0][key_field.name]
|
|
172
|
-
if(maxKey
|
|
173
|
-
await db.collection('counters').updateOne({ _id:
|
|
174
|
+
if(maxKey >= seq)
|
|
175
|
+
await db.collection('counters').updateOne({ _id: entity_name }, { $set: { seq: maxKey + 1 } })
|
|
174
176
|
}
|
|
175
177
|
}
|
|
176
178
|
|
|
@@ -223,14 +225,17 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
|
|
|
223
225
|
//Custom f list End
|
|
224
226
|
|
|
225
227
|
const projection = (key_field.name == '_id' ? {} : { _id: false })
|
|
228
|
+
if(yml.debug)
|
|
229
|
+
console.log('list', entity_name, f)
|
|
226
230
|
var count = await db.collection(entity_name).find(f).project(projection).sort(s).count();
|
|
227
231
|
let list = await db.collection(entity_name).find(f).project(projection).sort(s).skip(parseInt(_start)).limit(l).toArray()
|
|
228
232
|
list.map(m => {
|
|
229
233
|
m.id = getKeyFromEntity(m)
|
|
230
234
|
})
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
235
|
+
|
|
236
|
+
if(yml.debug)
|
|
237
|
+
console.log('list', entity_name, 'found', count)
|
|
238
|
+
|
|
234
239
|
await addInfo(db, list)
|
|
235
240
|
|
|
236
241
|
res.header('X-Total-Count', count);
|