From 827c0d4bd667a779e4364d20e9d28c1ef2506244 Mon Sep 17 00:00:00 2001 From: yk-eukarya <81808708+yk-eukarya@users.noreply.github.com> Date: Thu, 3 Aug 2023 15:07:56 +0300 Subject: [PATCH] fix(server): add missing fields to PropertySchema documents. (#621) --- .../mongo/mongodoc/property_schema.go | 68 ++++++++++--------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/server/internal/infrastructure/mongo/mongodoc/property_schema.go b/server/internal/infrastructure/mongo/mongodoc/property_schema.go index 8948bc0dfe..452e4df67c 100644 --- a/server/internal/infrastructure/mongo/mongodoc/property_schema.go +++ b/server/internal/infrastructure/mongo/mongodoc/property_schema.go @@ -16,25 +16,27 @@ type PropertySchemaDocument struct { } type PropertySchemaGroupDocument struct { - ID string - Fields []*PropertySchemaFieldDocument - List bool - IsAvailableIf *PropertyConditonDocument - Title map[string]string + ID string + Fields []*PropertySchemaFieldDocument + List bool + IsAvailableIf *PropertyConditonDocument + Title map[string]string + RepresentativeFieldID *string `bson:",omitempty"` } type PropertySchemaFieldDocument struct { - ID string - Type string - Name map[string]string - Description map[string]string - Prefix string - Suffix string - DefaultValue interface{} - UI *string - Min *float64 - Max *float64 - Choices []PropertySchemaFieldChoiceDocument + ID string + Type string + Name map[string]string + Description map[string]string + Prefix string + Suffix string + DefaultValue interface{} + UI *string + Min *float64 + Max *float64 + Choices []PropertySchemaFieldChoiceDocument + IsAvailableIf *PropertyConditonDocument `bson:",omitempty"` } type PropertySchemaFieldChoiceDocument struct { @@ -73,16 +75,17 @@ func NewPropertySchemaField(f *property.SchemaField) *PropertySchemaFieldDocumen } field := &PropertySchemaFieldDocument{ - ID: string(f.ID()), - Name: f.Title(), - Suffix: f.Suffix(), - Prefix: f.Prefix(), - Description: f.Description(), - Type: string(f.Type()), - DefaultValue: f.DefaultValue().Value(), - UI: f.UI().StringRef(), - Min: f.Min(), - Max: f.Max(), + ID: string(f.ID()), + Name: f.Title(), + Suffix: f.Suffix(), + Prefix: f.Prefix(), + Description: f.Description(), + Type: string(f.Type()), + DefaultValue: f.DefaultValue().Value(), + UI: f.UI().StringRef(), + Min: f.Min(), + Max: f.Max(), + IsAvailableIf: newPropertyCondition(f.IsAvailableIf()), } if choices := f.Choices(); choices != nil { field.Choices = make([]PropertySchemaFieldChoiceDocument, 0, len(choices)) @@ -167,6 +170,7 @@ func ToModelPropertySchemaField(f *PropertySchemaFieldDocument) (*property.Schem MinRef(f.Min). MaxRef(f.Max). Choices(choices). + IsAvailableIf(toModelPropertyCondition(f.IsAvailableIf)). Build() } @@ -232,11 +236,12 @@ func newPropertySchemaGroup(p *property.SchemaGroup) *PropertySchemaGroupDocumen } return &PropertySchemaGroupDocument{ - ID: string(p.ID()), - List: p.IsList(), - IsAvailableIf: newPropertyCondition(p.IsAvailableIf()), - Title: p.Title(), - Fields: fields, + ID: string(p.ID()), + List: p.IsList(), + IsAvailableIf: newPropertyCondition(p.IsAvailableIf()), + Title: p.Title(), + RepresentativeFieldID: p.RepresentativeFieldID().StringRef(), + Fields: fields, } } @@ -260,6 +265,7 @@ func (d *PropertySchemaGroupDocument) Model() (*property.SchemaGroup, error) { Title(d.Title). IsAvailableIf(toModelPropertyCondition(d.IsAvailableIf)). Fields(fields). + RepresentativeField(id.PropertyFieldIDFromRef(d.RepresentativeFieldID)). Build() }