add application key to submitters
This commit is contained in:
@@ -106,7 +106,7 @@ module Api
|
|||||||
|
|
||||||
def submissions_params
|
def submissions_params
|
||||||
params.permit(submission: [{
|
params.permit(submission: [{
|
||||||
submitters: [[:uuid, :name, :email, :role, :completed, :phone,
|
submitters: [[:uuid, :name, :email, :role, :completed, :phone, :application_key,
|
||||||
{ values: {}, readonly_fields: [],
|
{ values: {}, readonly_fields: [],
|
||||||
fields: [%i[name default_value readonly validation_pattern invalid_message]] }]]
|
fields: [%i[name default_value readonly validation_pattern invalid_message]] }]]
|
||||||
}])
|
}])
|
||||||
|
|||||||
@@ -4,6 +4,27 @@ module Api
|
|||||||
class SubmittersController < ApiBaseController
|
class SubmittersController < ApiBaseController
|
||||||
load_and_authorize_resource :submitter
|
load_and_authorize_resource :submitter
|
||||||
|
|
||||||
|
def index
|
||||||
|
submitters = Submitters.search(@submitters, params[:q])
|
||||||
|
|
||||||
|
submitters = submitters.where(application_key: params[:application_key]) if params[:application_key].present?
|
||||||
|
submitters = submitters.where(submission_id: params[:submission_id]) if params[:submission_id].present?
|
||||||
|
|
||||||
|
submitters = paginate(
|
||||||
|
submitters.preload(:template, :submission, :submission_events,
|
||||||
|
documents_attachments: :blob, attachments_attachments: :blob)
|
||||||
|
)
|
||||||
|
|
||||||
|
render json: {
|
||||||
|
data: submitters.map { |s| Submitters::SerializeForApi.call(s, with_template: true, with_events: true) },
|
||||||
|
pagination: {
|
||||||
|
count: submitters.size,
|
||||||
|
next: submitters.last&.id,
|
||||||
|
prev: submitters.first&.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
Submissions::EnsureResultGenerated.call(@submitter) if @submitter.completed_at?
|
Submissions::EnsureResultGenerated.call(@submitter) if @submitter.completed_at?
|
||||||
|
|
||||||
|
|||||||
+16
-15
@@ -4,21 +4,22 @@
|
|||||||
#
|
#
|
||||||
# Table name: submitters
|
# Table name: submitters
|
||||||
#
|
#
|
||||||
# id :bigint not null, primary key
|
# id :bigint not null, primary key
|
||||||
# completed_at :datetime
|
# application_key :string
|
||||||
# email :string
|
# completed_at :datetime
|
||||||
# ip :string
|
# email :string
|
||||||
# name :string
|
# ip :string
|
||||||
# opened_at :datetime
|
# name :string
|
||||||
# phone :string
|
# opened_at :datetime
|
||||||
# sent_at :datetime
|
# phone :string
|
||||||
# slug :string not null
|
# sent_at :datetime
|
||||||
# ua :string
|
# slug :string not null
|
||||||
# uuid :string not null
|
# ua :string
|
||||||
# values :text not null
|
# uuid :string not null
|
||||||
# created_at :datetime not null
|
# values :text not null
|
||||||
# updated_at :datetime not null
|
# created_at :datetime not null
|
||||||
# submission_id :bigint not null
|
# updated_at :datetime not null
|
||||||
|
# submission_id :bigint not null
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
|
|||||||
+1
-1
@@ -35,7 +35,7 @@ Rails.application.routes.draw do
|
|||||||
resources :template_folders_autocomplete, only: %i[index]
|
resources :template_folders_autocomplete, only: %i[index]
|
||||||
resources :submitter_email_clicks, only: %i[create]
|
resources :submitter_email_clicks, only: %i[create]
|
||||||
resources :submitter_form_views, only: %i[create]
|
resources :submitter_form_views, only: %i[create]
|
||||||
resources :submitters, only: %i[show]
|
resources :submitters, only: %i[index show]
|
||||||
resources :submissions, only: %i[index show create destroy] do
|
resources :submissions, only: %i[index show create destroy] do
|
||||||
collection do
|
collection do
|
||||||
resources :emails, only: %i[create], controller: 'submissions', as: :submissions_emails
|
resources :emails, only: %i[create], controller: 'submissions', as: :submissions_emails
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AddApplicationIdToSubmitters < ActiveRecord::Migration[7.0]
|
||||||
|
def change
|
||||||
|
add_column :submitters, :application_key, :string
|
||||||
|
end
|
||||||
|
end
|
||||||
+2
-1
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.0].define(version: 2023_10_07_052818) do
|
ActiveRecord::Schema[7.0].define(version: 2023_10_17_213639) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
@@ -133,6 +133,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_07_052818) do
|
|||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.string "phone"
|
t.string "phone"
|
||||||
|
t.string "application_key"
|
||||||
t.index ["email"], name: "index_submitters_on_email"
|
t.index ["email"], name: "index_submitters_on_email"
|
||||||
t.index ["slug"], name: "index_submitters_on_slug", unique: true
|
t.index ["slug"], name: "index_submitters_on_slug", unique: true
|
||||||
t.index ["submission_id"], name: "index_submitters_on_submission_id"
|
t.index ["submission_id"], name: "index_submitters_on_submission_id"
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ module Submissions
|
|||||||
email:,
|
email:,
|
||||||
phone: attrs[:phone].to_s.gsub(/[^0-9+]/, ''),
|
phone: attrs[:phone].to_s.gsub(/[^0-9+]/, ''),
|
||||||
name: attrs[:name],
|
name: attrs[:name],
|
||||||
|
application_key: attrs[:application_key],
|
||||||
completed_at: attrs[:completed] ? Time.current : nil,
|
completed_at: attrs[:completed] ? Time.current : nil,
|
||||||
sent_at: mark_as_sent && email.present? && is_order_sent ? Time.current : nil,
|
sent_at: mark_as_sent && email.present? && is_order_sent ? Time.current : nil,
|
||||||
values: attrs[:values] || {},
|
values: attrs[:values] || {},
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ module Submitters
|
|||||||
|
|
||||||
serialize_params = {
|
serialize_params = {
|
||||||
include: {},
|
include: {},
|
||||||
only: %i[id slug uuid name email phone completed_at
|
only: %i[id slug uuid name email phone completed_at application_key
|
||||||
opened_at sent_at created_at updated_at]
|
opened_at sent_at created_at updated_at]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user