diff --git a/src/store/store.schema.ts b/src/store/store.schema.ts index 83a47b9..bf42caf 100644 --- a/src/store/store.schema.ts +++ b/src/store/store.schema.ts @@ -30,7 +30,7 @@ export class Store extends Document { @Prop({ required: true, - type: {} + type: Object, }) value: any; diff --git a/src/store/store.service.ts b/src/store/store.service.ts index 1bd905e..703df0e 100644 --- a/src/store/store.service.ts +++ b/src/store/store.service.ts @@ -30,7 +30,11 @@ export class StoreService { await validateModel(createdStore); - return createdStore.save(); + const savedStore = await createdStore.save(); + if (!Object.keys(savedStore.value).length) { + await savedStore.updateOne(store); + } + return savedStore; } async update({author, ...omitProps}: StoreRequest): Promise { diff --git a/store.http b/store.http index 326d504..17ae223 100644 --- a/store.http +++ b/store.http @@ -2,7 +2,7 @@ GET http://localhost:4001/store HTTP/1.1 ### -GET http://localhost:4001/store/testApi HTTP/1.1 +GET http://localhost:4001/store/testApi22 HTTP/1.1 ### @@ -10,10 +10,9 @@ POST http://localhost:4001/store HTTP/1.1 content-type: application/json { - "key": "testApi", + "key": "testApi-4", "value": { - "name": "ivan", - "age": 16 + }, "description": "тестовое апи", "service_name": "test-api", @@ -26,10 +25,9 @@ PUT http://localhost:4001/store HTTP/1.1 content-type: application/json { - "key": "testApi", + "key": "testApi-4", "value": { - "name": "ivan23", - "age": 22 + }, "description": "тестовое апи", "service_name": "test-api", @@ -38,4 +36,4 @@ content-type: application/json ### -DELETE http://localhost:4001/store/testApi HTTP/1.1 \ No newline at end of file +DELETE http://localhost:4001/store/testApi22 HTTP/1.1 \ No newline at end of file