@nocobase/actions 0.15.0-alpha.4 → 0.16.0-alpha.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/lib/actions/move.d.ts +1 -1
- package/lib/actions/move.js +24 -12
- package/package.json +5 -5
package/lib/actions/move.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Model } from 'sequelize';
|
|
2
2
|
import { Context } from '..';
|
|
3
|
-
import { Collection,
|
|
3
|
+
import { Collection, SortField, TargetKey } from '@nocobase/database';
|
|
4
4
|
export declare function move(ctx: Context, next: any): Promise<void>;
|
|
5
5
|
interface MoveOptions {
|
|
6
6
|
insertAfter?: boolean;
|
package/lib/actions/move.js
CHANGED
|
@@ -28,20 +28,32 @@ var import_utils = require("../utils");
|
|
|
28
28
|
async function move(ctx, next) {
|
|
29
29
|
const repository = (0, import_utils.getRepositoryFromParams)(ctx);
|
|
30
30
|
const { sourceId, targetId, sortField, targetScope, sticky, method } = ctx.action.params;
|
|
31
|
-
if (repository instanceof import_database.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
if (sourceId && sticky) {
|
|
42
|
-
await sortAbleCollection.sticky(sourceId);
|
|
31
|
+
if (repository instanceof import_database.BelongsToManyRepository) {
|
|
32
|
+
throw new Error("Sorting association as 'belongs-to-many' type is not supported.");
|
|
33
|
+
}
|
|
34
|
+
if (repository instanceof import_database.HasManyRepository) {
|
|
35
|
+
const hasManyField = repository.sourceCollection.getField(repository.associationName);
|
|
36
|
+
if (!hasManyField.options.sortable) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
`association ${hasManyField.options.name} in ${repository.sourceCollection.name} is not sortable`
|
|
39
|
+
);
|
|
43
40
|
}
|
|
44
41
|
}
|
|
42
|
+
const sortAbleCollection = new SortAbleCollection(
|
|
43
|
+
repository instanceof import_database.Repository ? repository.collection : repository.targetCollection,
|
|
44
|
+
repository instanceof import_database.Repository ? sortField : `${repository.association.foreignKey}Sort`
|
|
45
|
+
);
|
|
46
|
+
if (sourceId && targetId) {
|
|
47
|
+
await sortAbleCollection.move(sourceId, targetId, {
|
|
48
|
+
insertAfter: method === "insertAfter"
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (sourceId && targetScope) {
|
|
52
|
+
await sortAbleCollection.changeScope(sourceId, targetScope, method);
|
|
53
|
+
}
|
|
54
|
+
if (sourceId && sticky) {
|
|
55
|
+
await sortAbleCollection.sticky(sourceId);
|
|
56
|
+
}
|
|
45
57
|
ctx.body = "ok";
|
|
46
58
|
await next();
|
|
47
59
|
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/actions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0-alpha.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@nocobase/cache": "0.
|
|
10
|
-
"@nocobase/database": "0.
|
|
11
|
-
"@nocobase/resourcer": "0.
|
|
9
|
+
"@nocobase/cache": "0.16.0-alpha.1",
|
|
10
|
+
"@nocobase/database": "0.16.0-alpha.1",
|
|
11
|
+
"@nocobase/resourcer": "0.16.0-alpha.1"
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
15
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
16
16
|
"directory": "packages/actions"
|
|
17
17
|
},
|
|
18
|
-
"gitHead": "
|
|
18
|
+
"gitHead": "e8aaf48d169448376a06d87f090786cd7649255e"
|
|
19
19
|
}
|