add application key to submitters
This commit is contained in:
@@ -106,7 +106,7 @@ module Api
|
||||
|
||||
def submissions_params
|
||||
params.permit(submission: [{
|
||||
submitters: [[:uuid, :name, :email, :role, :completed, :phone,
|
||||
submitters: [[:uuid, :name, :email, :role, :completed, :phone, :application_key,
|
||||
{ values: {}, readonly_fields: [],
|
||||
fields: [%i[name default_value readonly validation_pattern invalid_message]] }]]
|
||||
}])
|
||||
|
||||
@@ -4,6 +4,27 @@ module Api
|
||||
class SubmittersController < ApiBaseController
|
||||
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
|
||||
Submissions::EnsureResultGenerated.call(@submitter) if @submitter.completed_at?
|
||||
|
||||
|
||||
+16
-15
@@ -4,21 +4,22 @@
|
||||
#
|
||||
# Table name: submitters
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# completed_at :datetime
|
||||
# email :string
|
||||
# ip :string
|
||||
# name :string
|
||||
# opened_at :datetime
|
||||
# phone :string
|
||||
# sent_at :datetime
|
||||
# slug :string not null
|
||||
# ua :string
|
||||
# uuid :string not null
|
||||
# values :text not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# submission_id :bigint not null
|
||||
# id :bigint not null, primary key
|
||||
# application_key :string
|
||||
# completed_at :datetime
|
||||
# email :string
|
||||
# ip :string
|
||||
# name :string
|
||||
# opened_at :datetime
|
||||
# phone :string
|
||||
# sent_at :datetime
|
||||
# slug :string not null
|
||||
# ua :string
|
||||
# uuid :string not null
|
||||
# values :text not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# submission_id :bigint not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ Rails.application.routes.draw do
|
||||
resources :template_folders_autocomplete, only: %i[index]
|
||||
resources :submitter_email_clicks, 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
|
||||
collection do
|
||||
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.
|
||||
|
||||
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
|
||||
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.string "name"
|
||||
t.string "phone"
|
||||
t.string "application_key"
|
||||
t.index ["email"], name: "index_submitters_on_email"
|
||||
t.index ["slug"], name: "index_submitters_on_slug", unique: true
|
||||
t.index ["submission_id"], name: "index_submitters_on_submission_id"
|
||||
|
||||
@@ -92,6 +92,7 @@ module Submissions
|
||||
email:,
|
||||
phone: attrs[:phone].to_s.gsub(/[^0-9+]/, ''),
|
||||
name: attrs[:name],
|
||||
application_key: attrs[:application_key],
|
||||
completed_at: attrs[:completed] ? Time.current : nil,
|
||||
sent_at: mark_as_sent && email.present? && is_order_sent ? Time.current : nil,
|
||||
values: attrs[:values] || {},
|
||||
|
||||
@@ -18,7 +18,7 @@ module Submitters
|
||||
|
||||
serialize_params = {
|
||||
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]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user