Files
docuseal/app/controllers/api/form_events_controller.rb
T

40 lines
1.3 KiB
Ruby
Raw Normal View History

2024-07-19 11:49:22 +03:00
# frozen_string_literal: true
module Api
class FormEventsController < ApiBaseController
load_and_authorize_resource :submitter, parent: false
def index
submitters = @submitters.where.not(completed_at: nil)
params[:after] = Time.zone.at(params[:after].to_i) if params[:after].present?
params[:before] = Time.zone.at(params[:before].to_i) if params[:before].present?
submitters = paginate(
2025-07-20 08:28:19 +03:00
submitters.preload(template: { folder: :parent_folder },
submission: [:submitters, { audit_trail_attachment: :blob,
combined_document_attachment: :blob }],
2024-07-19 11:49:22 +03:00
documents_attachments: :blob, attachments_attachments: :blob),
field: :completed_at
)
2025-08-31 16:40:18 +03:00
expires_at = Accounts.link_expires_at(current_account)
2024-07-19 11:49:22 +03:00
render json: {
data: submitters.map do |s|
{
event_type: 'form.completed',
timestamp: s.completed_at,
2025-08-31 16:40:18 +03:00
data: Submitters::SerializeForWebhook.call(s, expires_at:)
2024-07-19 11:49:22 +03:00
}
end,
pagination: {
count: submitters.size,
next: submitters.last&.completed_at&.to_i,
prev: submitters.first&.completed_at&.to_i
}
}
end
end
end