yaml-admin-api 0.0.21 → 0.0.23
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yaml-admin-api",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "YAML Admin API package",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -8,9 +8,7 @@
|
|
|
8
8
|
"files": [
|
|
9
9
|
"src"
|
|
10
10
|
],
|
|
11
|
-
"scripts": {
|
|
12
|
-
"pub": "npm publish -w yaml-admin-api --access public"
|
|
13
|
-
},
|
|
11
|
+
"scripts": {},
|
|
14
12
|
"dependencies": {
|
|
15
13
|
"@aws-sdk/client-s3": "^3.596.0",
|
|
16
14
|
"@aws-sdk/client-ses": "^3.855.0",
|
|
@@ -158,6 +158,22 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
|
|
161
|
+
/**
|
|
162
|
+
* check entity max key and update counter to max+1
|
|
163
|
+
* @param {*} db
|
|
164
|
+
* @param {*} entity_name
|
|
165
|
+
*/
|
|
166
|
+
const recalcurateAutoGenerateIndex = async (db, entity_name) => {
|
|
167
|
+
const list = await db.collection(entity_name).find({}).sort({ [key_field.name]: -1 }).limit(1).toArray()
|
|
168
|
+
const counter = await db.collection('counters').findOne({ _id: key_field.name })
|
|
169
|
+
if(list.length > 0) {
|
|
170
|
+
let seq = counter?.seq || 0
|
|
171
|
+
let maxKey = list[0][key_field.name]
|
|
172
|
+
if(maxKey <= seq)
|
|
173
|
+
await db.collection('counters').updateOne({ _id: key_field.name }, { $set: { seq: maxKey + 1 } })
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
161
177
|
//list
|
|
162
178
|
app.get(`/${entity_name}`, auth.isAuthenticated, asyncErrorHandler(async (req, res) => {
|
|
163
179
|
//검색 파라미터
|
|
@@ -261,6 +277,9 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
|
|
|
261
277
|
|
|
262
278
|
//create
|
|
263
279
|
app.post(`/${entity_name}`, auth.isAuthenticated, asyncErrorHandler(async (req, res) => {
|
|
280
|
+
|
|
281
|
+
await recalcurateAutoGenerateIndex(db, entity_name)
|
|
282
|
+
|
|
264
283
|
let entityId
|
|
265
284
|
if (key_field.autogenerate)
|
|
266
285
|
entityId = await generateKey()
|
|
@@ -428,6 +447,8 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
|
|
|
428
447
|
let header = list[0]
|
|
429
448
|
list.shift();
|
|
430
449
|
|
|
450
|
+
await recalcurateAutoGenerateIndex(db, entity_name)
|
|
451
|
+
|
|
431
452
|
let upsert = yml_entity.crud.import.upsert || true
|
|
432
453
|
let fields = yml_entity.crud.import.fields.map(m => m)
|
|
433
454
|
fields = fields.map(field => {
|