@yongdall/organization 0.3.0
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/hooks.yongdall.mjs +15 -0
- package/hooks.yongdall.mjs.map +1 -0
- package/index.d.mts +28 -0
- package/index.mjs +3 -0
- package/organization-bygDRLDu.mjs +320 -0
- package/organization-bygDRLDu.mjs.map +1 -0
- package/package.json +22 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { n as OrganizationType, t as Organization } from "./organization-bygDRLDu.mjs";
|
|
2
|
+
|
|
3
|
+
//#region plugins/organization/hooks.yongdall.mjs
|
|
4
|
+
/** @import { Hooks } from '@yongdall/core' */
|
|
5
|
+
/** @type {Hooks.Define['models']} */
|
|
6
|
+
const models = {
|
|
7
|
+
organizationType: OrganizationType,
|
|
8
|
+
organization: Organization
|
|
9
|
+
};
|
|
10
|
+
/** @type {Hooks.Define['migrationModels']} */
|
|
11
|
+
const migrationModels = [OrganizationType, Organization];
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
export { migrationModels, models };
|
|
15
|
+
//# sourceMappingURL=hooks.yongdall.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.yongdall.mjs","names":[],"sources":["../../plugins/organization/hooks.yongdall.mjs"],"sourcesContent":["/** @import { Hooks } from '@yongdall/core' */\nimport { OrganizationType, Organization } from './index.mjs';\n\n/** @type {Hooks.Define['models']} */\nexport const models = {\n\torganizationType: OrganizationType,\n\torganization: Organization,\n};\n\n/** @type {Hooks.Define['migrationModels']} */\nexport const migrationModels = [\n\tOrganizationType,\n\tOrganization,\n]\n"],"mappings":";;;;;AAIA,MAAa,SAAS;CACrB,kBAAkB;CAClB,cAAc;CACd;;AAGD,MAAa,kBAAkB,CAC9B,kBACA,aACA"}
|
package/index.d.mts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as imodel10 from "imodel";
|
|
2
|
+
import * as _yongdall_model0 from "@yongdall/model";
|
|
3
|
+
|
|
4
|
+
//#region plugins/organization/models/OrganizationType.d.mts
|
|
5
|
+
declare const OrganizationType: _yongdall_model0.ModelTable<{
|
|
6
|
+
id: imodel10.FieldDefine<"string", false, false>;
|
|
7
|
+
label: imodel10.FieldDefine<"string", false, false>;
|
|
8
|
+
description: imodel10.FieldDefine<"string", false, true>;
|
|
9
|
+
createdAt: imodel10.FieldDefine<"timestamp", false, false>;
|
|
10
|
+
updatedAt: imodel10.FieldDefine<"timestamp", false, false>;
|
|
11
|
+
}, "organizationType">;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region plugins/organization/models/Organization.d.mts
|
|
14
|
+
declare const Organization: _yongdall_model0.ModelTable<{
|
|
15
|
+
id: imodel10.FieldDefine<"uuid", false, false>;
|
|
16
|
+
label: imodel10.FieldDefine<"string", false, false>;
|
|
17
|
+
parentId: imodel10.FieldDefine<"uuid", false, true>;
|
|
18
|
+
typeId: imodel10.FieldDefine<"string", false, false>;
|
|
19
|
+
internal: imodel10.FieldDefine<"bool", false, false>;
|
|
20
|
+
mainId: imodel10.FieldDefine<"uuid", false, true>;
|
|
21
|
+
description: imodel10.FieldDefine<"text", false, true>;
|
|
22
|
+
lft: imodel10.FieldDefine<"i32", false, false>;
|
|
23
|
+
rgt: imodel10.FieldDefine<"i32", false, false>;
|
|
24
|
+
createdAt: imodel10.FieldDefine<"timestamp", false, false>;
|
|
25
|
+
updatedAt: imodel10.FieldDefine<"timestamp", false, false>;
|
|
26
|
+
}, "organization">;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { Organization, OrganizationType };
|
package/index.mjs
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { Query, Where, createField, createModel, mergeHooks, now, uuid } from "@yongdall/model";
|
|
2
|
+
import "@yongdall/connection";
|
|
3
|
+
import { ServerError, nestedSetTree } from "@yongdall/core";
|
|
4
|
+
|
|
5
|
+
//#region plugins/organization/models/OrganizationType.mjs
|
|
6
|
+
const OrganizationType = createModel("organizationType", {
|
|
7
|
+
id: createField("string", {
|
|
8
|
+
nullable: false,
|
|
9
|
+
label: "标识",
|
|
10
|
+
primary: 1
|
|
11
|
+
}),
|
|
12
|
+
label: createField("string", {
|
|
13
|
+
nullable: false,
|
|
14
|
+
default: "",
|
|
15
|
+
label: "名称"
|
|
16
|
+
}),
|
|
17
|
+
description: createField("string", {
|
|
18
|
+
nullable: true,
|
|
19
|
+
default: "",
|
|
20
|
+
label: "描述"
|
|
21
|
+
}),
|
|
22
|
+
createdAt: createField("timestamp", {
|
|
23
|
+
nullable: false,
|
|
24
|
+
creating: now,
|
|
25
|
+
label: "创建日期"
|
|
26
|
+
}),
|
|
27
|
+
updatedAt: createField("timestamp", {
|
|
28
|
+
nullable: false,
|
|
29
|
+
updating: now,
|
|
30
|
+
label: "最后更新日期"
|
|
31
|
+
})
|
|
32
|
+
}, {
|
|
33
|
+
label: "组织类型",
|
|
34
|
+
labelField: "label",
|
|
35
|
+
permissions: [{
|
|
36
|
+
permission: "system:organization",
|
|
37
|
+
fields: "*",
|
|
38
|
+
authorizations: [
|
|
39
|
+
"query",
|
|
40
|
+
"options",
|
|
41
|
+
"read",
|
|
42
|
+
"create",
|
|
43
|
+
"update",
|
|
44
|
+
"destroy",
|
|
45
|
+
"add",
|
|
46
|
+
"remove"
|
|
47
|
+
]
|
|
48
|
+
}, {
|
|
49
|
+
permission: "organization",
|
|
50
|
+
fields: "*",
|
|
51
|
+
authorizations: [
|
|
52
|
+
"query",
|
|
53
|
+
"options",
|
|
54
|
+
"read"
|
|
55
|
+
]
|
|
56
|
+
}]
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region plugins/organization/models/Organization.mjs
|
|
61
|
+
const Organization = createModel("organization", {
|
|
62
|
+
id: createField("uuid", {
|
|
63
|
+
nullable: false,
|
|
64
|
+
default: uuid,
|
|
65
|
+
primary: 1,
|
|
66
|
+
uncreatable: true,
|
|
67
|
+
layout: { hidden: true }
|
|
68
|
+
}),
|
|
69
|
+
label: createField("string", {
|
|
70
|
+
size: 255,
|
|
71
|
+
nullable: false,
|
|
72
|
+
default: "",
|
|
73
|
+
label: "名称",
|
|
74
|
+
layout: { colSpan: 6 }
|
|
75
|
+
}),
|
|
76
|
+
parentId: createField("uuid", {
|
|
77
|
+
nullable: true,
|
|
78
|
+
label: "上级组织",
|
|
79
|
+
model: "organization",
|
|
80
|
+
renderer: "document",
|
|
81
|
+
layout: { colSpan: 6 }
|
|
82
|
+
}),
|
|
83
|
+
typeId: createField("string", {
|
|
84
|
+
size: 255,
|
|
85
|
+
nullable: false,
|
|
86
|
+
label: "类型",
|
|
87
|
+
model: "organizationType",
|
|
88
|
+
renderer: "document",
|
|
89
|
+
layout: { colSpan: 6 }
|
|
90
|
+
}),
|
|
91
|
+
internal: createField("bool", {
|
|
92
|
+
nullable: false,
|
|
93
|
+
default: false,
|
|
94
|
+
label: "是否为子组织",
|
|
95
|
+
layout: { colSpan: 6 }
|
|
96
|
+
}),
|
|
97
|
+
mainId: createField("uuid", {
|
|
98
|
+
nullable: true,
|
|
99
|
+
label: "所属主体组织",
|
|
100
|
+
model: "organization",
|
|
101
|
+
renderer: "document",
|
|
102
|
+
layout: { colSpan: 6 }
|
|
103
|
+
}),
|
|
104
|
+
description: createField("text", {
|
|
105
|
+
nullable: true,
|
|
106
|
+
label: "描述"
|
|
107
|
+
}),
|
|
108
|
+
lft: createField("i32", {
|
|
109
|
+
nullable: false,
|
|
110
|
+
default: 0,
|
|
111
|
+
label: "LFT",
|
|
112
|
+
layout: { hidden: true }
|
|
113
|
+
}),
|
|
114
|
+
rgt: createField("i32", {
|
|
115
|
+
nullable: false,
|
|
116
|
+
default: 0,
|
|
117
|
+
label: "RGT",
|
|
118
|
+
layout: { hidden: true }
|
|
119
|
+
}),
|
|
120
|
+
createdAt: createField("timestamp", {
|
|
121
|
+
nullable: false,
|
|
122
|
+
creating: now,
|
|
123
|
+
label: "创建日期",
|
|
124
|
+
layout: { hidden: true }
|
|
125
|
+
}),
|
|
126
|
+
updatedAt: createField("timestamp", {
|
|
127
|
+
nullable: false,
|
|
128
|
+
updating: now,
|
|
129
|
+
label: "最后更新日期",
|
|
130
|
+
layout: { hidden: true }
|
|
131
|
+
})
|
|
132
|
+
}, {
|
|
133
|
+
label: "组织",
|
|
134
|
+
labelField: "label",
|
|
135
|
+
permissions: [
|
|
136
|
+
{
|
|
137
|
+
permission: "system:organization",
|
|
138
|
+
fields: [
|
|
139
|
+
"id",
|
|
140
|
+
"label",
|
|
141
|
+
"parentId",
|
|
142
|
+
"typeId",
|
|
143
|
+
"internal",
|
|
144
|
+
"description",
|
|
145
|
+
"createdAt",
|
|
146
|
+
"updatedAt"
|
|
147
|
+
],
|
|
148
|
+
authorizations: [
|
|
149
|
+
"options",
|
|
150
|
+
"query",
|
|
151
|
+
"read",
|
|
152
|
+
"create",
|
|
153
|
+
"update",
|
|
154
|
+
"destroy",
|
|
155
|
+
"add",
|
|
156
|
+
"remove"
|
|
157
|
+
]
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
permission: "system:organization",
|
|
161
|
+
fields: ["mainId", "lft"],
|
|
162
|
+
authorizations: [
|
|
163
|
+
"options",
|
|
164
|
+
"query",
|
|
165
|
+
"read"
|
|
166
|
+
]
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
permission: "organization",
|
|
170
|
+
fields: [
|
|
171
|
+
"id",
|
|
172
|
+
"label",
|
|
173
|
+
"parentId",
|
|
174
|
+
"typeId",
|
|
175
|
+
"internal",
|
|
176
|
+
"description",
|
|
177
|
+
"createdAt",
|
|
178
|
+
"updatedAt"
|
|
179
|
+
],
|
|
180
|
+
organizationField: "mainId",
|
|
181
|
+
authorizations: [
|
|
182
|
+
"options",
|
|
183
|
+
"query",
|
|
184
|
+
"read",
|
|
185
|
+
"create",
|
|
186
|
+
"update",
|
|
187
|
+
"destroy",
|
|
188
|
+
"add",
|
|
189
|
+
"remove"
|
|
190
|
+
]
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
permission: "",
|
|
194
|
+
fields: ["mainId", "lft"],
|
|
195
|
+
organizationField: "mainId",
|
|
196
|
+
authorizations: [
|
|
197
|
+
"options",
|
|
198
|
+
"query",
|
|
199
|
+
"read"
|
|
200
|
+
]
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
permission: "organization",
|
|
204
|
+
fields: [
|
|
205
|
+
"id",
|
|
206
|
+
"label",
|
|
207
|
+
"parentId",
|
|
208
|
+
"typeId",
|
|
209
|
+
"internal",
|
|
210
|
+
"description",
|
|
211
|
+
"createdAt",
|
|
212
|
+
"updatedAt"
|
|
213
|
+
],
|
|
214
|
+
organizationField: "parentId",
|
|
215
|
+
authorizations: [
|
|
216
|
+
"options",
|
|
217
|
+
"query",
|
|
218
|
+
"read",
|
|
219
|
+
"create",
|
|
220
|
+
"update",
|
|
221
|
+
"destroy",
|
|
222
|
+
"add",
|
|
223
|
+
"remove"
|
|
224
|
+
]
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
permission: "",
|
|
228
|
+
fields: ["mainId", "lft"],
|
|
229
|
+
organizationField: "parentId",
|
|
230
|
+
authorizations: [
|
|
231
|
+
"options",
|
|
232
|
+
"query",
|
|
233
|
+
"read"
|
|
234
|
+
]
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
permission: "organization",
|
|
238
|
+
fields: [
|
|
239
|
+
"id",
|
|
240
|
+
"label",
|
|
241
|
+
"parentId",
|
|
242
|
+
"typeId",
|
|
243
|
+
"internal",
|
|
244
|
+
"description",
|
|
245
|
+
"createdAt",
|
|
246
|
+
"updatedAt"
|
|
247
|
+
],
|
|
248
|
+
organizationField: "id",
|
|
249
|
+
authorizations: [
|
|
250
|
+
"options",
|
|
251
|
+
"query",
|
|
252
|
+
"read",
|
|
253
|
+
"create",
|
|
254
|
+
"update",
|
|
255
|
+
"add",
|
|
256
|
+
"remove"
|
|
257
|
+
]
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
permission: "",
|
|
261
|
+
fields: ["mainId", "lft"],
|
|
262
|
+
organizationField: "id",
|
|
263
|
+
authorizations: [
|
|
264
|
+
"options",
|
|
265
|
+
"query",
|
|
266
|
+
"read"
|
|
267
|
+
]
|
|
268
|
+
}
|
|
269
|
+
],
|
|
270
|
+
hooks: mergeHooks(nestedSetTree("parentId"), {
|
|
271
|
+
async beforeCreate(conn, Model, document) {
|
|
272
|
+
delete document.mainId;
|
|
273
|
+
if (!document.internal) {
|
|
274
|
+
const parentId = document.parentId;
|
|
275
|
+
if (!parentId) return;
|
|
276
|
+
const parent = await conn.first(new Query(Model).where("id", parentId));
|
|
277
|
+
if (!parent) {
|
|
278
|
+
delete document.parentId;
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
if (parent.internal) throw new ServerError("主体组织,只能作为其他主体组织的下级组织");
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const parentId = document.parentId;
|
|
285
|
+
const parent = parentId ? await conn.first(new Query(Model).where("id", parentId)) : null;
|
|
286
|
+
if (!parent) throw new ServerError("请选择上级组织");
|
|
287
|
+
document.internal = true;
|
|
288
|
+
document.mainId = parent.internal && parent.mainId || parent.id;
|
|
289
|
+
},
|
|
290
|
+
async afterCreate(conn, Model, document) {
|
|
291
|
+
if (document.mainId) return;
|
|
292
|
+
const id = document.id;
|
|
293
|
+
if (!await conn.update(Model, { mainId: id }, Where.and("id", id), true)) return;
|
|
294
|
+
document.mainId = id;
|
|
295
|
+
},
|
|
296
|
+
async beforeUpdate(conn, Model, document, set) {
|
|
297
|
+
delete set.mainId;
|
|
298
|
+
const parentId = set.parentId;
|
|
299
|
+
if (typeof parentId !== "number" && typeof parentId !== "string" || parentId === document.parentId) {
|
|
300
|
+
delete set.parentId;
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
if (!parentId) {
|
|
304
|
+
if (document.internal) delete set.parentId;
|
|
305
|
+
else set.parentId = null;
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
if (!document.internal) {
|
|
309
|
+
if (await conn.count(new Query(Model).where("id", parentId).where("internal", false))) return;
|
|
310
|
+
throw new ServerError("主体组织,只能作为其他主体组织的下级组织");
|
|
311
|
+
}
|
|
312
|
+
if (await conn.count(new Query(Model).where("id", parentId).where("mainId", document.mainId))) return;
|
|
313
|
+
throw new ServerError("非主体组织,只能调整到同一主体组织下");
|
|
314
|
+
}
|
|
315
|
+
})
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
//#endregion
|
|
319
|
+
export { OrganizationType as n, Organization as t };
|
|
320
|
+
//# sourceMappingURL=organization-bygDRLDu.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"organization-bygDRLDu.mjs","names":[],"sources":["../../plugins/organization/models/OrganizationType.mjs","../../plugins/organization/models/Organization.mjs"],"sourcesContent":["import { createField, createModel, uuid, now } from '@yongdall/model';\n\nexport const OrganizationType = createModel('organizationType', {\n\tid: createField('string', { nullable: false, label: '标识', primary: 1 }),\n\tlabel: createField('string', { nullable: false, default: '', label: '名称' }),\n\tdescription: createField('string', { nullable: true, default: '', label: '描述' }),\n\tcreatedAt: createField('timestamp', { nullable: false, creating: now, label: '创建日期' }),\n\tupdatedAt: createField('timestamp', { nullable: false, updating: now, label: '最后更新日期' }),\n}, {\n\tlabel: '组织类型',\n\tlabelField: 'label',\n\tpermissions: [\n\t\t{permission: 'system:organization', fields: '*', authorizations: ['query', 'options', 'read', 'create', 'update', 'destroy', 'add', 'remove'] },\n\t\t{permission: 'organization', fields: '*', authorizations: ['query', 'options', 'read'] },\n\t],\n});\n","import { createField, createModel, uuid, now, Query, mergeHooks, Where } from '@yongdall/model';\nimport { useConnection } from '@yongdall/connection';\nimport { nestedSetTree, ServerError } from '@yongdall/core';\n\n// 定义模型\nexport const Organization = createModel('organization', {\n\tid: createField('uuid', { nullable: false, default: uuid, primary: 1, uncreatable: true, layout: { hidden: true } }),\n\tlabel: createField('string', { size: 255, nullable: false, default: '', label: '名称', layout: { colSpan: 6 } }),\n\tparentId: createField('uuid', { nullable: true, label: '上级组织', model: 'organization', renderer: 'document', layout: { colSpan: 6 } }),\n\ttypeId: createField('string', { size: 255, nullable: false, label: '类型', model: 'organizationType', renderer: 'document', layout: { colSpan: 6 } }),\n\tinternal: createField('bool', { nullable: false, default: false, label: '是否为子组织', layout: { colSpan: 6 } }),\n\tmainId: createField('uuid', { nullable: true, label: '所属主体组织', model: 'organization', renderer: 'document', layout: { colSpan: 6 } }),\n\tdescription: createField('text', { nullable: true, label: '描述' }),\n\n\t// Nested Set 树结构字段,通常由 hook 自动维护,但需定义以便存储\n\tlft: createField('i32', { nullable: false, default: 0, label: 'LFT', layout: { hidden: true } }),\n\trgt: createField('i32', { nullable: false, default: 0, label: 'RGT', layout: { hidden: true } }),\n\n\tcreatedAt: createField('timestamp', { nullable: false, creating: now, label: '创建日期', layout: { hidden: true } }),\n\tupdatedAt: createField('timestamp', { nullable: false, updating: now, label: '最后更新日期', layout: { hidden: true } }),\n}, {\n\tlabel: '组织',\n\tlabelField: 'label',\n\tpermissions: [\n\t\t{ permission: 'system:organization', fields: ['id', 'label', 'parentId', 'typeId', 'internal', 'description', 'createdAt', 'updatedAt'], authorizations: ['options', 'query', 'read', 'create', 'update', 'destroy', 'add', 'remove'] },\n\t\t{ permission: 'system:organization', fields: ['mainId', 'lft'], authorizations: ['options', 'query', 'read'] },\n\n\t\t{ permission: 'organization', fields: ['id', 'label', 'parentId', 'typeId', 'internal', 'description', 'createdAt', 'updatedAt'], organizationField: 'mainId', authorizations: ['options', 'query', 'read', 'create', 'update', 'destroy', 'add', 'remove'] },\n\t\t{ permission: '', fields: ['mainId', 'lft'], organizationField: 'mainId', authorizations: ['options', 'query', 'read'] },\n\t\t{ permission: 'organization', fields: ['id', 'label', 'parentId', 'typeId', 'internal', 'description', 'createdAt', 'updatedAt'], organizationField: 'parentId', authorizations: ['options', 'query', 'read', 'create', 'update', 'destroy', 'add', 'remove'] },\n\t\t{ permission: '', fields: ['mainId', 'lft'], organizationField: 'parentId', authorizations: ['options', 'query', 'read'] },\n\t\t{ permission: 'organization', fields: ['id', 'label', 'parentId', 'typeId', 'internal', 'description', 'createdAt', 'updatedAt'], organizationField: 'id', authorizations: ['options', 'query', 'read', 'create', 'update', 'add', 'remove'] },\n\t\t{ permission: '', fields: ['mainId', 'lft'], organizationField: 'id', authorizations: ['options', 'query', 'read'] },\n\t],\n\thooks: mergeHooks(nestedSetTree('parentId'), {\n\n\t\tasync beforeCreate(conn, Model, document) {\n\t\t\tdelete document.mainId;\n\n\t\t\tif (!document.internal) {\n\t\t\t\tconst parentId = document.parentId;\n\t\t\t\tif (!parentId) { return; }\n\t\t\t\tconst parent = await conn.first(new Query(Model).where('id', parentId));\n\t\t\t\tif (!parent) {\n\t\t\t\t\tdelete document.parentId;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (parent.internal) {\n\t\t\t\t\tthrow new ServerError('主体组织,只能作为其他主体组织的下级组织');\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst parentId = document.parentId;\n\t\t\tconst parent = parentId\n\t\t\t\t? await conn.first(new Query(Model).where('id', parentId))\n\t\t\t\t: null;\n\n\t\t\tif (!parent) {\n\t\t\t\tthrow new ServerError('请选择上级组织');\n\t\t\t}\n\n\t\t\tdocument.internal = true;\n\t\t\tdocument.mainId = (parent.internal && parent.mainId) || parent.id;\n\t\t},\n\t\tasync afterCreate(conn, Model, document) {\n\t\t\tif (document.mainId) { return; }\n\t\t\tconst id = document.id;\n\t\t\tif (!await conn.update(Model, { mainId: id }, Where.and('id', id), true)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdocument.mainId = id;\n\t\t},\n\n\t\tasync beforeUpdate(conn, Model, document, set) {\n\t\t\tdelete set.mainId;\n\n\t\t\tconst parentId = set.parentId;\n\t\t\t// 检查 parentId 是否真的改变\n\t\t\tif ((typeof parentId !== 'number' && typeof parentId !== 'string') || parentId === document.parentId) {\n\t\t\t\tdelete set.parentId;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!parentId) {\n\t\t\t\tif (document.internal) {\n\t\t\t\t\tdelete set.parentId;\n\t\t\t\t} else {\n\t\t\t\t\tset.parentId = null;\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!document.internal) {\n\t\t\t\tconst parent = await conn.count(\n\t\t\t\t\tnew Query(Model)\n\t\t\t\t\t\t.where('id', parentId)\n\t\t\t\t\t\t.where('internal', false)\n\t\t\t\t);\n\t\t\t\tif (parent) { return; }\n\t\t\t\tthrow new ServerError('主体组织,只能作为其他主体组织的下级组织');\n\t\t\t}\n\n\t\t\tconst parent = await conn.count(\n\t\t\t\tnew Query(Model)\n\t\t\t\t.where('id', parentId)\n\t\t\t\t.where('mainId', document.mainId)\n\t\t\t);\n\t\t\t\tif (parent) { return; }\n\t\t\tthrow new ServerError('非主体组织,只能调整到同一主体组织下');\n\n\n\t\t}\n\t}),\n});\n\n// 静态方法转换为独立导出函数\n// 使用时需传入 connection 或直接使用模型引用\n/**\n * \n * @param {string?} id \n * @returns \n */\nexport async function getAncestors(id) {\n\tif (!id) return [];\n\tconst conn = useConnection('rdb');\n\tconst o = await conn.first(\n\t\tnew Query(Organization).select('lft', 'rgt').where('id', id)\n\t);\n\tif (!o) { return []; }\n\n\tconst { lft, rgt } = o;\n\tconst list = await conn.select(\n\t\tnew Query(Organization).select('id').where('lft', '<=', lft).where('rgt', '>=', rgt)\n\t);\n\treturn list.map(v => v.id);\n}\n\n/**\n * \n * @param {string?} id \n * @returns \n */\nexport async function getPosterity(id) {\n\tif (!id) return [];\n\tconst conn = useConnection('rdb');\n\tconst o = await conn.first(new Query(Organization).select('lft', 'rgt').where('id', id));\n\tif (!o) { return []; }\n\n\tconst { lft, rgt } = o;\n\tconst list = await conn.select(\n\t\tnew Query(Organization).select('id').where('lft', '>=', lft).where('rgt', '<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UAAW,OAAO;;EAEhE,MAAM,YAAY,MAAM,OAAO,UAAU;AACxC,OAAI,SAAS,OAAU;GACvB,MAAM,KAAK,SAAS;AACpB,OAAI,CAAC,MAAM,KAAK,OAAO,OAAO,EAAE,QAAQ,IAAI,EAAE,MAAM,IAAI,MAAM,GAAG,EAAE,KAAK,CACvE;AAED,YAAS,SAAS;;EAGnB,MAAM,aAAa,MAAM,OAAO,UAAU,KAAK;AAC9C,UAAO,IAAI;GAEX,MAAM,WAAW,IAAI;AAErB,OAAK,OAAO,aAAa,YAAY,OAAO,aAAa,YAAa,aAAa,SAAS,UAAU;AACrG,WAAO,IAAI;AACX;;AAED,OAAI,CAAC,UAAU;AACd,QAAI,SAAS,SACZ,QAAO,IAAI;QAEX,KAAI,WAAW;AAEhB;;AAGD,OAAI,CAAC,SAAS,UAAU;AAMvB,QALe,MAAM,KAAK,MACzB,IAAI,MAAM,MAAM,CACd,MAAM,MAAM,SAAS,CACrB,MAAM,YAAY,MAAM,CAC1B,CACa;AACd,UAAM,IAAI,YAAY,uBAAuB;;AAQ7C,OALc,MAAM,KAAK,MACzB,IAAI,MAAM,MAAM,CACf,MAAM,MAAM,SAAS,CACrB,MAAM,UAAU,SAAS,OAAO,CACjC,CACc;AACf,SAAM,IAAI,YAAY,qBAAqB;;EAI5C,CAAC;CACF,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yongdall/organization",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"main": "./index.mjs",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./index.mjs"
|
|
7
|
+
},
|
|
8
|
+
"version": "0.3.0",
|
|
9
|
+
"description": "",
|
|
10
|
+
"keywords": [],
|
|
11
|
+
"author": "",
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@yongdall/connection": "^0.3.0",
|
|
15
|
+
"@yongdall/context": "^0.3.0",
|
|
16
|
+
"@yongdall/model": "^0.3.0",
|
|
17
|
+
"@yongdall/core": "^0.3.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@yongdall/types": "^0.3.0"
|
|
21
|
+
}
|
|
22
|
+
}
|