dobo 1.1.14 → 1.1.15

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": "dobo",
3
- "version": "1.1.14",
3
+ "version": "1.1.15",
4
4
  "description": "Database ORM/ODM for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -56,13 +56,13 @@ async function create (name, input, opts = {}) {
56
56
  if (options.req.file) await handleAttachmentUpload.call(this, { name: schema.name, id: body.id, body, options, action: 'create' })
57
57
  if (options.req.flash && !options.noFlash) options.req.flash('notify', options.req.t('recordCreated'))
58
58
  }
59
+ if (clearModel) await clearModel({ model: name, body: nbody, options, record })
60
+ if (noResult) return
61
+ record.data = await this.pickRecord({ record: record.data, fields, schema, hidden, forceNoHidden })
59
62
  if (!noHook) {
60
63
  await runHook(`${this.name}.${camelCase(name)}:afterRecordCreate`, nbody, options, record)
61
64
  await runHook(`${this.name}:afterRecordCreate`, name, nbody, options, record)
62
65
  }
63
- if (clearModel) await clearModel({ model: name, body: nbody, options, record })
64
- if (noResult) return
65
- record.data = await this.pickRecord({ record: record.data, fields, schema, hidden, forceNoHidden })
66
66
  if (!noFeatureHook) await execFeatureHook.call(this, 'afterCreate', { schema, body: nbody, options, record })
67
67
  return dataOnly ? record.data : record
68
68
  }
@@ -39,11 +39,11 @@ async function findOne (name, filter = {}, opts = {}) {
39
39
  record.data = record.data[0]
40
40
 
41
41
  if (isSet(options.rels)) await singleRelRows.call(this, { schema, record: record.data, options })
42
+ record.data = await this.pickRecord({ record: record.data, fields, schema, hidden, forceNoHidden })
42
43
  if (!noHook) {
43
44
  await runHook(`${this.name}.${camelCase(name)}:afterRecordFindOne`, filter, options, record)
44
45
  await runHook(`${this.name}:afterRecordFindOne`, name, filter, options, record)
45
46
  }
46
- record.data = await this.pickRecord({ record: record.data, fields, schema, hidden, forceNoHidden })
47
47
  if (set && !noCache) await set({ model: name, filter, options, record })
48
48
  if (!noFeatureHook) await execFeatureHook.call(this, 'afterFindOne', { schema, filter, options, record })
49
49
  return dataOnly ? record.data : record
@@ -36,13 +36,13 @@ async function find (name, filter = {}, opts = {}) {
36
36
  const records = options.records ?? (await handler.call(this.app[driver.ns], { schema, filter, options }))
37
37
  delete options.records
38
38
  if (isSet(options.rels)) await multiRelRows.call(this, { schema, records: records.data, options })
39
+ for (const idx in records.data) {
40
+ records.data[idx] = await this.pickRecord({ record: records.data[idx], fields, schema, hidden, forceNoHidden })
41
+ }
39
42
  if (!noHook) {
40
43
  await runHook(`${this.name}.${camelCase(name)}:afterRecordFind`, filter, options, records)
41
44
  await runHook(`${this.name}:afterRecordFind`, name, filter, options, records)
42
45
  }
43
- for (const idx in records.data) {
44
- records.data[idx] = await this.pickRecord({ record: records.data[idx], fields, schema, hidden, forceNoHidden })
45
- }
46
46
  if (set && !noCache) await set({ model: name, filter, options, records })
47
47
  if (!noFeatureHook) await execFeatureHook.call(this, 'afterFind', { schema, filter, options, records })
48
48
  return dataOnly ? records.data : records
@@ -33,12 +33,11 @@ async function get (name, id, opts = {}) {
33
33
  const record = options.record ?? (await handler.call(this.app[driver.ns], { schema, id, options }))
34
34
  delete options.record
35
35
  if (isSet(options.rels)) await singleRelRows.call(this, { schema, record: record.data, options })
36
+ record.data = await this.pickRecord({ record: record.data, fields, schema, hidden, forceNoHidden })
36
37
  if (!noHook) {
37
38
  await runHook(`${this.name}.${camelCase(name)}:afterRecordGet`, id, options, record)
38
39
  await runHook(`${this.name}:afterRecordGet`, name, id, options, record)
39
40
  }
40
- record.data = await this.pickRecord({ record: record.data, fields, schema, hidden, forceNoHidden })
41
-
42
41
  if (set && !noCache) await set({ model: name, id, options, record })
43
42
  if (!noFeatureHook) await execFeatureHook.call(this, 'afterGet', { schema, id, options, record })
44
43
  return dataOnly ? record.data : record
@@ -27,13 +27,13 @@ async function remove (name, id, opts = {}) {
27
27
  if (options.req.file) await handleAttachmentUpload.call(this, { name: schema.name, id, options, action: 'remove' })
28
28
  if (options.req.flash && !options.noFlash) options.req.flash('notify', options.req.t('recordRemoved'))
29
29
  }
30
+ if (clearModel) await clearModel({ model: name, id, options, record })
31
+ if (noResult) return
32
+ record.oldData = options.record ? options.record.oldData : (await this.pickRecord({ record: record.oldData, fields, schema, hidden, forceNoHidden }))
30
33
  if (!noHook) {
31
34
  await runHook(`${this.name}.${camelCase(name)}:afterRecordRemove`, id, options, record)
32
35
  await runHook(`${this.name}:afterRecordRemove`, name, id, options, record)
33
36
  }
34
- if (clearModel) await clearModel({ model: name, id, options, record })
35
- if (noResult) return
36
- record.oldData = options.record ? options.record.oldData : (await this.pickRecord({ record: record.oldData, fields, schema, hidden, forceNoHidden }))
37
37
  if (!noFeatureHook) await execFeatureHook.call(this, 'afterRemove', { schema, id, options, record })
38
38
  return dataOnly ? record.oldData : record
39
39
  }
@@ -47,14 +47,14 @@ async function update (name, id, input, opts = {}) {
47
47
  if (options.req.file) await handleAttachmentUpload.call(this, { name: schema.name, id, body, options, action: 'update' })
48
48
  if (options.req.flash && !options.noFlash) options.req.flash('notify', options.req.t('recordUpdated'))
49
49
  }
50
- if (!noHook) {
51
- await runHook(`${this.name}.${camelCase(name)}:afterRecordUpdate`, id, nbody, options, record)
52
- await runHook(`${this.name}:afterRecordUpdate`, name, id, nbody, options, record)
53
- }
54
50
  if (clearModel) await clearModel({ model: name, id, body: nbody, options, record })
55
51
  if (noResult) return
56
52
  record.oldData = await this.pickRecord({ record: record.oldData, fields, schema, hidden, forceNoHidden })
57
53
  record.data = await this.pickRecord({ record: record.data, fields, schema, hidden, forceNoHidden })
54
+ if (!noHook) {
55
+ await runHook(`${this.name}.${camelCase(name)}:afterRecordUpdate`, id, nbody, options, record)
56
+ await runHook(`${this.name}:afterRecordUpdate`, name, id, nbody, options, record)
57
+ }
58
58
  if (!noFeatureHook) await execFeatureHook.call(this, 'afterUpdate', { schema, body: nbody, record })
59
59
  return dataOnly ? record.data : record
60
60
  }