@kravc/dos 1.11.19 → 1.11.20
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/examples/ReadProfile.js +13 -1
- package/package.json +1 -1
- package/src/Document.js +4 -12
- package/src/Document.spec.js +4 -4
- package/src/helpers/createSpec.js +5 -1
package/examples/ReadProfile.js
CHANGED
|
@@ -3,4 +3,16 @@
|
|
|
3
3
|
const Read = require('../src/operations/Read')
|
|
4
4
|
const Profile = require('./Profile')
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
class ReadProfile extends Read(Profile) {
|
|
7
|
+
static get query() {
|
|
8
|
+
return {
|
|
9
|
+
id: {
|
|
10
|
+
description: 'Profile ID',
|
|
11
|
+
required: true,
|
|
12
|
+
example: 'PRO_1'
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = ReadProfile
|
package/package.json
CHANGED
package/src/Document.js
CHANGED
|
@@ -9,6 +9,8 @@ const DocumentNotFoundError = require('./errors/DocumentNotFoundError')
|
|
|
9
9
|
const { get, omit, capitalize, cloneDeep } = require('lodash')
|
|
10
10
|
|
|
11
11
|
const STORE = {}
|
|
12
|
+
const SYSTEM = 'SYSTEM'
|
|
13
|
+
const IDENTITY_SUBJECT_PATH = 'identity.sub'
|
|
12
14
|
|
|
13
15
|
class Document extends Component {
|
|
14
16
|
static get idKey() {
|
|
@@ -88,12 +90,7 @@ class Document extends Component {
|
|
|
88
90
|
|
|
89
91
|
const { validator } = context
|
|
90
92
|
mutation = validator.normalize(mutation, this.id)
|
|
91
|
-
|
|
92
|
-
const identitySubjectId = get(context, 'identity.sub')
|
|
93
|
-
|
|
94
|
-
if (identitySubjectId) {
|
|
95
|
-
mutation.createdBy = identitySubjectId
|
|
96
|
-
}
|
|
93
|
+
mutation.createdBy = get(context, IDENTITY_SUBJECT_PATH, SYSTEM)
|
|
97
94
|
|
|
98
95
|
const timestamp = new Date().toJSON()
|
|
99
96
|
mutation.createdAt = timestamp
|
|
@@ -191,12 +188,7 @@ class Document extends Component {
|
|
|
191
188
|
|
|
192
189
|
static async update(context, query, mutation, originalDocument = null) {
|
|
193
190
|
mutation = omit(mutation, [ this.idKey, 'createdAt', 'createdBy' ])
|
|
194
|
-
|
|
195
|
-
const identitySubjectId = get(context, 'identity.sub')
|
|
196
|
-
|
|
197
|
-
if (identitySubjectId) {
|
|
198
|
-
mutation.updatedBy = identitySubjectId
|
|
199
|
-
}
|
|
191
|
+
mutation.updatedBy = get(context, IDENTITY_SUBJECT_PATH, SYSTEM)
|
|
200
192
|
|
|
201
193
|
const timestamp = new Date().toJSON()
|
|
202
194
|
mutation.updatedAt = timestamp
|
package/src/Document.spec.js
CHANGED
|
@@ -58,14 +58,14 @@ describe('Document', () => {
|
|
|
58
58
|
expect(profile.attributes.name).to.eql('Olga')
|
|
59
59
|
})
|
|
60
60
|
|
|
61
|
-
it('creates document without identity in context', async () => {
|
|
61
|
+
it('creates document without identity in context as SYSTEM', async () => {
|
|
62
62
|
const context = { validator }
|
|
63
63
|
const profile = await Profile.create(context, { name: 'Oleg' })
|
|
64
64
|
|
|
65
65
|
expect(profile.id).to.exist
|
|
66
66
|
expect(profile.attributes.name).to.eql('Oleg')
|
|
67
67
|
expect(profile.attributes.createdAt).to.exist
|
|
68
|
-
expect(profile.attributes.createdBy).to.
|
|
68
|
+
expect(profile.attributes.createdBy).to.eql('SYSTEM')
|
|
69
69
|
})
|
|
70
70
|
|
|
71
71
|
it('returns exiting document from the context', async () => {
|
|
@@ -115,14 +115,14 @@ describe('Document', () => {
|
|
|
115
115
|
expect(profile.attributes.updatedBy).to.exist
|
|
116
116
|
})
|
|
117
117
|
|
|
118
|
-
it('updates document without identity in context', async () => {
|
|
118
|
+
it('updates document without identity in context as SYSTEM', async () => {
|
|
119
119
|
const context = { validator }
|
|
120
120
|
const { id } = await Profile.create(context, { name: 'Gustav' })
|
|
121
121
|
|
|
122
122
|
const profile = await Profile.update(context, { id }, { name: 'Jack' })
|
|
123
123
|
|
|
124
124
|
expect(profile.attributes.updatedAt).to.exist
|
|
125
|
-
expect(profile.attributes.updatedBy).to.
|
|
125
|
+
expect(profile.attributes.updatedBy).to.eql('SYSTEM')
|
|
126
126
|
})
|
|
127
127
|
|
|
128
128
|
it('throws "DocumentNotFoundError" if document not found', async () => {
|
|
@@ -80,7 +80,11 @@ const createSpec = (operations, schemasMap, url) => {
|
|
|
80
80
|
|
|
81
81
|
for (const name in query) {
|
|
82
82
|
const queryParameter = { in: 'query', name, type: 'string', ...query[name] }
|
|
83
|
-
|
|
83
|
+
|
|
84
|
+
if (queryParameter.example) {
|
|
85
|
+
queryParameter['x-example'] = queryParameter.example
|
|
86
|
+
delete queryParameter.example
|
|
87
|
+
}
|
|
84
88
|
|
|
85
89
|
parameters.push(queryParameter)
|
|
86
90
|
}
|