Skip to content

Commit 1de1ad9

Browse files
author
John Huffman
committed
updates to field logic and adding fK field on relationships
1 parent 20f2292 commit 1de1ad9

File tree

1 file changed

+35
-108
lines changed

1 file changed

+35
-108
lines changed

custom_connectors/oauth2/trackvia.rb

Lines changed: 35 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@
3636
type: 'oauth2',
3737

3838
authorization_url: lambda { |connection|
39-
"https://#{connection['custom_domain'].presence || 'go.trackvia.com'}/oauth/authorize?response_type=code"
39+
params = {
40+
client_id: connection['client_id'],
41+
client_secret: connection['client_secret'],
42+
response_type: 'code'
43+
}.to_param
44+
"https://#{connection['custom_domain'].presence || 'go.trackvia.com'}/oauth/authorize?" + params
4045
},
4146

4247
acquire: lambda do |connection, auth_code, redirect_uri|
@@ -78,123 +83,45 @@
7883
},
7984

8085
base_uri: lambda do |connection|
81-
if connection['custom_domain'].presence
82-
"https://#{connection['custom_domain']}/openapi/"
83-
else
84-
"https://go.trackvia.com/openapi/"
85-
end
86+
"https://#{connection['custom_domain'].presence || 'go.trackvia.com'}/openapi/"
8687
end
8788
},
8889

8990
test: ->(_connection) { get('views') },
9091

9192
methods: {
9293
get_all_output_fields: lambda do |input|
93-
url = input[:view_id].present? ? "views/#{input[:view_id]}" : "users"
94-
Array.wrap(get(url)&.[]('structure')).reject { |field| field['name'] == "ID" }.map do |field|
95-
case field['type']
96-
when 'number', 'currency', 'percentage', 'autoIncrement', 'relationship'
97-
{ type: 'number' }
98-
when 'date'
99-
{ type: 'date' }
100-
when 'datetime'
101-
{ type: 'date_time' }
102-
when 'point'
103-
{ type: 'object', properties: [
104-
{ name: 'latitude', type: 'number', optional: false },
105-
{ name: 'longitude', type: 'number', optional: false }
106-
] }
107-
when 'checkbox'
108-
{ type: :array, of: :object, properties: [
109-
{ name: 'choice' }
110-
] }
111-
else
112-
{}
113-
end.merge(name: "f_#{field['fieldMetaId']}", label: field['name'], field_name: field['name'])
114-
end.concat([{ name: 'id' }])
115-
end,
116-
117-
get_output_fields: lambda do |input|
118-
url = input[:view_id].present? ? "views/#{input[:view_id]}" : "users"
119-
Array.wrap(get(url)&.[]('structure')).reject { |field| field['name'] == "ID" || %w[image document].include?(field['type']) }.map do |field|
120-
case field['type']
121-
when 'number', 'currency', 'percentage', 'autoIncrement', 'relationship'
122-
{ type: 'number' }
123-
when 'date'
124-
{ type: 'date' }
125-
when 'datetime'
126-
{ type: 'date_time' }
127-
when 'point'
128-
{ type: 'object', properties: [
129-
{ name: 'latitude', type: 'number', optional: false },
130-
{ name: 'longitude', type: 'number', optional: false }
131-
] }
132-
when 'checkbox'
133-
{ type: :array, of: :object, properties: [
134-
{ name: 'choice' }
135-
] }
136-
else
137-
{}
138-
end.merge(name: "f_#{field['fieldMetaId']}", label: field['name'], field_name: field['name'])
139-
end.concat([{ name: 'id' }])
140-
end,
141-
142-
get_fields: lambda do |input|
143-
structure = Array.wrap(get("views/#{input[:view_id]}")&.[]('structure')).
144-
reject { |field| field['canCreate'].is_not_true? || field['canUpdate'].is_not_true? || %w[image document].include?(field['type']) }
145-
structure.map do |field|
146-
# properties = { optional: input['id'].present? ? true : !field['required'], label: field['name'], field_name: field['name'] }
94+
url = input[:view_id].present? ? "views/#{input[:view_id]}" : 'users'
95+
Array.wrap(get(url)&.[]('structure')).map do |field|
14796
case field['type']
148-
when 'number', 'currency', 'autoIncrement', 'relationship'
149-
{ type: 'number' }
150-
when 'percentage'
151-
{
152-
type: 'number',
153-
hint: "Enter in your percentage as a decimal. i.e. 10% should be entered in as 0.10. If necessary, use the '/'' operator in formula mode to adjust your value."
154-
}
97+
when 'identifier', 'shortAnswer', 'paragraph', 'userGroup', 'email', 'url'
98+
[{ name: "f_#{field['fieldMetaId']}", label: field['name'], field_name: field['name'], type: 'string' }]
99+
when 'relationship'
100+
[{ name: "f_#{field['fieldMetaId']}", label: field['name'], field_name: field['name'], type: 'string' },
101+
{ name: "f_#{field['fieldMetaId']}(id)", label: "#{field['name']}(id)", field_name: "#{field['name']}(id)", type: 'number' }]
102+
when 'number', 'percentage', 'currency', 'autoIncrement', 'user'
103+
[{name: field['name'] == 'ID' ? 'id' : "f_#{field['fieldMetaId']}", label: field['name'], field_name: field['name'], type: 'number' }]
155104
when 'date'
156-
{ type: 'date' }
105+
[{ name: "f_#{field['fieldMetaId']}", label: field['name'], field_name: field['name'], type: 'date' }]
157106
when 'datetime'
158-
{ type: 'date_time' }
107+
[{ name: "f_#{field['fieldMetaId']}", label: field['name'], field_name: field['name'], type: 'date_time' }]
159108
when 'point'
160-
{ type: 'object', properties: [
161-
{ name: 'latitude', type: 'number', optional: false },
162-
{ name: 'longitude', type: 'number', optional: false }
163-
] }
164-
when 'user'
165-
{ hint: 'Enter the required user ID. User ID can be foun at the end of URL.' }
166-
when 'userGroup'
167-
{ hint: 'Enter valid user group ID.' }
168-
when 'checkbox'
169-
{
170-
control_type: 'multiselect', delimiter: ',', options: field['choices'].map { |k| [k, k] }, toggle_hint: 'Select from list',
171-
toggle_field: {
172-
name: "f_#{field['fieldMetaId']}",
173-
type: :string,
174-
label: field['name'],
175-
control_type: 'text',
176-
hint: "Valid values are #{field['choices'].map { |k| k }.join(', ')}. For multiple values, enter values separated by (<b>,</b>). Example: <b>choice1,choice2</b>",
177-
toggle_hint: 'Enter custom value'
178-
}
179-
}
180-
when 'dropDown'
181-
{
182-
control_type: 'select', pick_list: field['choices'].map { |k| [k, k] }, toggle_hint: 'Select from list',
183-
toggle_field: {
184-
name: "f_#{field['fieldMetaId']}",
185-
type: :string,
186-
label: field['name'],
187-
control_type: 'text',
188-
hint: "Valid values are #{field['choices'].map { |k| k }.join(', ')}.",
189-
toggle_hint: 'Enter custom value'
190-
}
191-
}
192-
when 'email'
193-
{ control_type: 'email' }
109+
[{ name: "f_#{field['fieldMetaId']}", label: field['name'], field_name: field['name'], type: 'object',
110+
properties: [
111+
{ name: 'latitude', type: 'number', optional: false },
112+
{ name: 'longitude', type: 'number', optional: false }
113+
]
114+
}]
115+
when 'checkbox', 'dropDown'
116+
[{ name: "f_#{field['fieldMetaId']}", label: field['name'], field_name: field['name'], type: :array, of: :object,
117+
properties: [
118+
{ name: 'choices' }
119+
]
120+
}]
194121
else
195-
{}
196-
end.merge(name: "f_#{field['fieldMetaId']}", optional: input['id'].present? ? true : !field['required'], label: field['name'], field_name: field['name'])
197-
end
122+
nil
123+
end
124+
end.flatten.compact
198125
end,
199126

200127
get_fields_sample_output: lambda do |input|
@@ -223,7 +150,7 @@
223150
object_definitions: {
224151
record: {
225152
fields: lambda { |_connection, config_fields|
226-
call(:get_fields, config_fields)
153+
call(:get_all_output_fields, config_fields)
227154
}
228155
},
229156

@@ -235,7 +162,7 @@
235162

236163
create_record_output: {
237164
fields: lambda { |_connection, config_fields|
238-
call(:get_output_fields, view_id: config_fields['view_id'])
165+
call(:get_all_output_fields, view_id: config_fields['view_id'])
239166
}
240167
}
241168
},

0 commit comments

Comments
 (0)