fix empty object

This commit is contained in:
vigdorov
2020-07-12 14:53:56 +03:00
parent da55228f70
commit 31a58d0dc1
3 changed files with 12 additions and 10 deletions

View File

@ -30,7 +30,7 @@ export class Store extends Document {
@Prop({
required: true,
type: {}
type: Object,
})
value: any;

View File

@ -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<Store> {

View File

@ -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
DELETE http://localhost:4001/store/testApi22 HTTP/1.1