@tachybase/actions 1.6.12 → 1.6.13-alpha.2

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.
@@ -72,14 +72,43 @@ const _SortAbleCollection = class _SortAbleCollection {
72
72
  const sourceInstance = await this.collection.repository.findById(sourceInstanceId);
73
73
  const targetInstance = await this.collection.repository.findById(targetInstanceId);
74
74
  if (this.scopeKey && sourceInstance.get(this.scopeKey) !== targetInstance.get(this.scopeKey)) {
75
- await this.collection.repository.update({
76
- targetCollection: this.collection.name,
77
- filterByTk: sourceInstanceId,
78
- values: {
79
- [this.scopeKey]: targetInstance.get(this.scopeKey)
80
- },
81
- silent: false
82
- });
75
+ const fieldName = this.field.get("name");
76
+ let targetSort = targetInstance.get(fieldName);
77
+ if (options.insertAfter) {
78
+ targetSort = targetSort + 1;
79
+ }
80
+ const transaction = await this.collection.model.sequelize.transaction();
81
+ try {
82
+ await this.collection.model.increment(fieldName, {
83
+ where: {
84
+ [this.scopeKey]: {
85
+ [import_sequelize.Op.eq]: targetInstance.get(this.scopeKey)
86
+ },
87
+ [fieldName]: {
88
+ [import_sequelize.Op.gte]: targetSort
89
+ }
90
+ },
91
+ by: 1,
92
+ silent: true,
93
+ transaction
94
+ });
95
+ await this.collection.repository.update({
96
+ targetCollection: this.collection.name,
97
+ filterByTk: sourceInstanceId,
98
+ values: {
99
+ [this.scopeKey]: targetInstance.get(this.scopeKey),
100
+ [fieldName]: targetSort
101
+ },
102
+ silent: false,
103
+ skipSortScopeChangeAppend: true,
104
+ transaction
105
+ });
106
+ await transaction.commit();
107
+ } catch (err) {
108
+ await transaction.rollback();
109
+ throw err;
110
+ }
111
+ return;
83
112
  }
84
113
  await this.sameScopeMove(sourceInstance, targetInstance, options, sourceInstanceId);
85
114
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tachybase/actions",
3
- "version": "1.6.12",
3
+ "version": "1.6.13-alpha.2",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/tegojs/tego#readme",
6
6
  "bugs": {
@@ -18,10 +18,10 @@
18
18
  "koa": "^2.16.2",
19
19
  "lodash": "4.17.21",
20
20
  "sequelize": "^6.37.7",
21
- "@tachybase/cache": "1.6.12",
22
- "@tachybase/database": "1.6.12",
23
- "@tachybase/resourcer": "1.6.12",
24
- "@tachybase/utils": "1.6.12"
21
+ "@tachybase/cache": "1.6.13-alpha.2",
22
+ "@tachybase/database": "1.6.13-alpha.2",
23
+ "@tachybase/resourcer": "1.6.13-alpha.2",
24
+ "@tachybase/utils": "1.6.13-alpha.2"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/koa": "^2.15.0",