@kravc/dos 1.6.0 → 1.6.1

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": "@kravc/dos",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "Convention-based, easy-to-use library for building API-driven serverless services.",
5
5
  "keywords": [
6
6
  "Service",
package/src/Document.js CHANGED
@@ -64,6 +64,12 @@ class Document extends Component {
64
64
  }
65
65
 
66
66
  static async create(context, query, mutation) {
67
+ const { document: existingDocument } = context
68
+
69
+ if (existingDocument) {
70
+ return existingDocument
71
+ }
72
+
67
73
  if (!mutation) {
68
74
  mutation = query
69
75
  query = {}
@@ -64,6 +64,13 @@ describe('Document', () => {
64
64
  expect(profile.attributes.createdBy).to.not.exist
65
65
  })
66
66
 
67
+ it('returns exiting document from the context', async () => {
68
+ const profile = await Profile.create(context, { name: 'Volodymyr' })
69
+ const existingProfile = await Profile.create({ ...context, document: profile }, { name: 'Volodymyr' })
70
+
71
+ expect(profile.id).to.eql(existingProfile.id)
72
+ })
73
+
67
74
  it('throws "DocumentExistsError" if document already exists', async () => {
68
75
  const { id } = await Profile.create(context, {}, { name: 'Artem' })
69
76
  const error = await expectError(() => Profile.create(context, {}, { id, name: 'Liam' }))