Skip to content

Commit

Permalink
Fix problem with updated field in DIDDocMetadata:
Browse files Browse the repository at this point in the history
   - When updated field is an empty in DIDDocMetadata, then
     we don't response updated field.
  • Loading branch information
abdulla-ashurov committed Mar 8, 2023
1 parent e21798a commit c96afcc
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions types/did_doc_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

didTypes "github.com/cheqd/cheqd-node/api/v2/cheqd/did/v2"
resourceTypes "github.com/cheqd/cheqd-node/api/v2/cheqd/resource/v2"
"google.golang.org/protobuf/types/known/timestamppb"
)

type ResolutionDidDocMetadata struct {
Expand All @@ -16,11 +17,12 @@ type ResolutionDidDocMetadata struct {
}

func NewResolutionDidDocMetadata(did string, metadata *didTypes.Metadata, resources []*resourceTypes.Metadata) ResolutionDidDocMetadata {
created := metadata.Created.AsTime()
updated := metadata.Updated.AsTime()
created := toTime(metadata.Created)
updated := toTime(metadata.Updated)

newMetadata := ResolutionDidDocMetadata{
Created: &created,
Updated: &updated,
Created: created,
Updated: updated,
Deactivated: metadata.Deactivated,
VersionId: metadata.VersionId,
}
Expand All @@ -41,3 +43,14 @@ func TransformToFragmentMetadata(metadata ResolutionDidDocMetadata) ResolutionDi
func (e *ResolutionDidDocMetadata) AddContext(newProtocol string) {}
func (e *ResolutionDidDocMetadata) RemoveContext() {}
func (e *ResolutionDidDocMetadata) GetBytes() []byte { return []byte{} }

func toTime(value *timestamppb.Timestamp) (result *time.Time) {
if value.AsTime().IsZero() {
result = nil
} else {
value := value.AsTime()
result = &value
}

return result
}

0 comments on commit c96afcc

Please sign in to comment.