fix: update organization node may clear description

This commit is contained in:
Qiu Jian
2023-07-20 15:30:31 +08:00
parent 29cd4e3af1
commit 860c7f98ec
2 changed files with 17 additions and 3 deletions
+15 -2
View File
@@ -104,6 +104,19 @@ func generateId(orgId string, fullLabel string, level int) string {
}
func (manager *SOrganizationNodeManager) ensureNode(ctx context.Context, orgId string, label string, fullLabel string, level int, weight *int, desc string) (*SOrganizationNode, error) {
id := generateId(orgId, fullLabel, level)
obj, err := manager.FetchById(id)
if err != nil {
if errors.Cause(err) != sql.ErrNoRows {
return nil, errors.Wrap(err, "FetchById")
}
// not exist
} else {
// exist
if len(desc) == 0 {
desc = obj.(*SOrganizationNode).Description
}
}
node := &SOrganizationNode{
OrgId: orgId,
FullLabel: fullLabel,
@@ -112,9 +125,9 @@ func (manager *SOrganizationNodeManager) ensureNode(ctx context.Context, orgId s
}
node.Description = desc
node.Name = label
node.Id = generateId(orgId, fullLabel, level)
node.Id = id
err := manager.TableSpec().InsertOrUpdate(ctx, node)
err = manager.TableSpec().InsertOrUpdate(ctx, node)
if err != nil {
return nil, errors.Wrap(err, "InsertOrUpdate")
}
@@ -50,7 +50,8 @@ func (opts *OrganizationNodeIdOptions) Params() (jsonutils.JSONObject, error) {
type OrganizationNodeUpdateOptions struct {
OrganizationNodeIdOptions
Weigth int `help:"update weight of node"`
Weigth int `help:"update weight of node"`
Description string `help:"update description"`
}
func (opts *OrganizationNodeUpdateOptions) Params() (jsonutils.JSONObject, error) {