wolf_core 0.1.74 → 0.1.75

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea2c7642b7213912f7be0ed0d55cb8f3bab2dbf32e6208d7b505b094a36abd6d
4
- data.tar.gz: 4073fd23872f4388a46564ba875cc01cdfe40b416d519683fe3c5cb35a0ca21b
3
+ metadata.gz: ccd8da54fe6ce73bf327f86ccfa4b7ea3fd96793833765d21c13ee9a0a571e23
4
+ data.tar.gz: 6d090c26876e5c1a051bb27c30dda66d4094750cc3ee7ace28099a33e0d8a3f0
5
5
  SHA512:
6
- metadata.gz: 7516f45342dad488580974fc485c9e6d972d288d44245790d794adba1b4964172e19bf29b1c3c56ceb8d687ca2f1ce5de31991fc79a9fec3b448b875b40b0cb4
7
- data.tar.gz: 8d31afc2a95ebb7567ae3edee6965ab741ca1856c6a6fd28e047a5e3336d45d051afc17bed3cebdaca682c273550d896a89ee2a42425e16c2b164780206a62ae
6
+ metadata.gz: 89a469e772aaabd6c2571d3db5046b38d847620d155b2ccbc54376188700efdfaed915f14eea3c28ff958b555853bdd580f1eebc788b917c890addffd6c0c2dc
7
+ data.tar.gz: 845569183bfa0a3ff1d9fece60084f27366a2a7f3ced30fdfbf6061d5570bf1ce362bfa25a672a43d88506e95a2dcf3c0ec7db8560762598a2eea97313c66fbe
@@ -5,11 +5,18 @@ module WolfCore
5
5
  include WolfCore::LoggingUtils
6
6
 
7
7
  def get_foreign_key_destination_id(tenant:, source:, source_id:, destination:)
8
- foreign_keys = get_foreign_keys(tenant: tenant, source: source, source_id: source_id)
9
- foreign_key = foreign_keys.find { |fk| fk['destination'] == destination }
8
+ foreign_key = get_foreign_key_by_destination(
9
+ tenant: tenant, source: source, source_id: source_id,
10
+ destination: destination
11
+ )
10
12
  foreign_key&.dig('destination_id')
11
13
  end
12
14
 
15
+ def get_foreign_key_by_destination(tenant:, source:, source_id:, destination:)
16
+ foreign_keys = get_foreign_keys(tenant: tenant, source: source, source_id: source_id)
17
+ foreign_keys.find { |fk| fk['destination'] == destination }
18
+ end
19
+
13
20
  def get_foreign_keys(tenant:, source:, source_id:)
14
21
  response = http_get(
15
22
  url: "#{ENV['FKM_URL']}/Prod/lookup?tenant=#{tenant}&source=#{source}&source_id=#{source_id}"
@@ -65,5 +72,51 @@ module WolfCore
65
72
  )
66
73
  Result.success(data: { operation: :create })
67
74
  end
75
+
76
+ def upsert_foreign_key(tenant:, source:, source_id:, destination:, destination_id:, auth_token:)
77
+ foreign_key = get_foreign_key_by_destination(
78
+ tenant: tenant, source: source, source_id: source_id,
79
+ destination: destination
80
+ )
81
+ if foreign_key.present?
82
+ update_foreign_key(
83
+ tenant: tenant, auth_token: auth_token, uuid: foreign_key['uuid'],
84
+ source: source, source_id: source_id,
85
+ destination: destination, destination_id: destination_id,
86
+ )
87
+ else
88
+ create_foreign_key(
89
+ tenant: tenant, source: source, source_id: source_id,
90
+ destination: destination, destination_id: destination_id
91
+ )
92
+ end
93
+ end
94
+
95
+ def update_foreign_key(tenant:, auth_token:, uuid:, source: nil, source_id: nil, destination: nil, destination_id: nil)
96
+ raise_service_error({ message: 'tenant is required to update a foreign key', tenant: tenant }) if tenant.blank?
97
+ raise_service_error({ message: 'auth_token is required to update a foreign key', auth_token: auth_token }) if auth_token.blank?
98
+ raise_service_error({ message: 'uuid is required to update a foreign key', uuid: uuid }) if uuid.blank?
99
+
100
+ fields_to_update = {
101
+ source: source,
102
+ source_id: source_id,
103
+ destination: destination,
104
+ destination_id: destination_id,
105
+ }.compact
106
+
107
+ raise_service_error({ message: 'At least one field to update is required to update a foreign key', source: source }) if fields_to_update.blank?
108
+
109
+ response = safe_http_put(
110
+ url: "#{ENV['FKM_URL']}/Prod/create",
111
+ body: {
112
+ tenant: tenant,
113
+ authentication_token: auth_token,
114
+ uuid: uuid,
115
+ }.merge(fields_to_update),
116
+ title: 'update_foreign_key response is',
117
+ error_message: 'Error updating foreign key',
118
+ )
119
+ response.body
120
+ end
68
121
  end
69
122
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WolfCore
4
- VERSION = "0.1.74"
4
+ VERSION = "0.1.75"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wolf_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.74
4
+ version: 0.1.75
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Roncallo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-23 00:00:00.000000000 Z
11
+ date: 2024-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty