dobo 1.1.6 → 1.1.8

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.
@@ -121,6 +121,7 @@
121
121
  "fixtureAdded%s%s%s": "Fixture on '%s': added %s, rejected: %s",
122
122
  "errorAddingFixture%s%s": "Error adding fixture on model '%s': %s",
123
123
  "memoryDbSkipped%s": "'%s' is a memory DB, skipped",
124
+ "db": "DB",
124
125
  "field": {
125
126
  "id": "ID",
126
127
  "code": "Kode",
package/bajo/intl/id.json CHANGED
@@ -114,6 +114,7 @@
114
114
  "addingFixtureToMemDb": "Adding fixture for memory database",
115
115
  "recordsAdded%s%d%d": "%s: %d of %d records added",
116
116
  "driverInstantiated%s%s": "- Driver '%s:%s' instantiated",
117
+ "db": "DB",
117
118
  "field": {
118
119
  "id": "ID",
119
120
  "code": "Kode",
@@ -1,8 +1,9 @@
1
1
  import path from 'path'
2
2
 
3
3
  async function addFixture (name, { spinner } = {}) {
4
- const { resolvePath, readConfig, eachPlugins } = this.app.bajo
5
- const { isEmpty, isArray } = this.lib._
4
+ const { resolvePath, readConfig, eachPlugins, getPluginDataDir } = this.app.bajo
5
+ const { isEmpty, isArray, isString } = this.lib._
6
+ const { fs } = this.lib
6
7
  const { schema, connection } = this.getInfo(name)
7
8
  if (connection.proxy) {
8
9
  this.log.warn('proxiedConnBound%s', schema.name)
@@ -37,7 +38,19 @@ async function addFixture (name, { spinner } = {}) {
37
38
  }
38
39
  if (v === null) item[k] = undefined
39
40
  }
40
- await this.recordCreate(schema.name, item, { force: true })
41
+ const resp = await this.recordCreate(schema.name, item, { force: true })
42
+ if (isArray(item._attachments) && item._attachments.length > 0) {
43
+ for (let att of item._attachments) {
44
+ if (isString(att)) att = { field: 'file', file: att }
45
+ const fname = path.basename(att.file)
46
+ if (fs.existsSync(att.file)) {
47
+ const dest = `${getPluginDataDir(schema.ns)}/${resp.id}/${att.field}/${fname}`
48
+ try {
49
+ fs.copySync(att.file, dest)
50
+ } catch (err) {}
51
+ }
52
+ }
53
+ }
41
54
  result.success++
42
55
  if (spinner) spinner.setText('recordsAdded%s%d%d', schema.name, result.success, items.length)
43
56
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dobo",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "description": "Database ORM/ODM for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {