Skip to content

Commit

Permalink
cleanup user after unsubscribing
Browse files Browse the repository at this point in the history
  • Loading branch information
abeidahmed committed May 9, 2023
1 parent 5c1e16b commit 34e46c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/controllers/survey_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
class SurveyController < ApplicationController
before_action :authenticate_user!

# If a user re-subscribes within the grace period, we don't want to process the job.
GRACE_PERIOD = 1.week

def create
current_user.surveys.create!(survey_param)
current_user.surveys.create(survey_param)
current_user.stop_active_subscriptions
SeeYouSoonJob.set(wait: GRACE_PERIOD).perform_later(current_user)

redirect_to see_you_soon_path, notice: "We hope to see you again!"
end

Expand Down
9 changes: 9 additions & 0 deletions app/jobs/see_you_soon_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class SeeYouSoonJob < ApplicationJob
queue_as :default

# Delete all records that are part of the paid feature.
def perform(user)
user.posts.each { |posts| posts.destroy }
user.uploaded_pictures.each { |upload| upload.destroy }
end
end

0 comments on commit 34e46c3

Please sign in to comment.