@@ -21,6 +21,7 @@ query entityToPublish($entityId: String!, $spaceId: String!) {
21
21
entity(id: $entityId, spaceId: $spaceId) {
22
22
values {
23
23
propertyId
24
+ value
24
25
}
25
26
relations {
26
27
id
@@ -33,6 +34,7 @@ type EntityToPublishQueryResult = {
33
34
entity : {
34
35
values : {
35
36
propertyId : string ;
37
+ value : string ;
36
38
} [ ] ;
37
39
relations : {
38
40
id : string ;
@@ -97,7 +99,34 @@ export const preparePublish = async <S extends Entity.AnyNoContext>({
97
99
return { ops } ;
98
100
}
99
101
100
- // TODO: implement updating an existing entity
102
+ if ( data ?. entity ) {
103
+ for ( const [ key , propertyId ] of Object . entries ( mappingEntry . properties || { } ) ) {
104
+ let serializedValue : string = entity [ key ] ;
105
+ if ( fields [ key ] === Type . Checkbox ) {
106
+ serializedValue = Graph . serializeCheckbox ( entity [ key ] ) ;
107
+ } else if ( fields [ key ] === Type . Date ) {
108
+ serializedValue = Graph . serializeDate ( entity [ key ] ) ;
109
+ } else if ( fields [ key ] === Type . Point ) {
110
+ serializedValue = Graph . serializePoint ( entity [ key ] ) ;
111
+ } else if ( fields [ key ] === Type . Number ) {
112
+ serializedValue = Graph . serializeNumber ( entity [ key ] ) ;
113
+ }
114
+
115
+ const existingValue = data . entity . values . find ( ( value ) => value . propertyId === propertyId ) ;
116
+
117
+ if ( serializedValue !== existingValue ?. value ) {
118
+ values . push ( { property : propertyId , value : serializedValue } ) ;
119
+ }
120
+ }
121
+
122
+ // TODO: handle added or removed relations
123
+ // TODO: handle updated relations
124
+ // TODO: handle added or removed types
125
+ if ( values . length > 0 ) {
126
+ const { ops : updateEntityOps } = Graph . updateEntity ( { id : entity . id , values } ) ;
127
+ ops . push ( ...updateEntityOps ) ;
128
+ }
129
+ }
101
130
102
131
return { ops } ;
103
132
} ;
0 commit comments