2024-05-18 07:35:48 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2024-04-06 13:09:38 -04:00
|
|
|
class Owntracks::PointCreatingJob < ApplicationJob
|
2024-04-02 11:37:38 -04:00
|
|
|
queue_as :default
|
|
|
|
|
|
2024-07-04 16:20:12 -04:00
|
|
|
def perform(point_params, user_id)
|
2024-04-02 11:37:38 -04:00
|
|
|
parsed_params = OwnTracks::Params.new(point_params).call
|
|
|
|
|
|
2024-05-29 17:06:58 -04:00
|
|
|
return if point_exists?(parsed_params, user_id)
|
|
|
|
|
|
2024-05-25 07:26:56 -04:00
|
|
|
Point.create!(parsed_params.merge(user_id:))
|
2024-04-02 11:37:38 -04:00
|
|
|
end
|
2024-05-29 17:06:58 -04:00
|
|
|
|
|
|
|
|
def point_exists?(params, user_id)
|
|
|
|
|
Point.exists?(
|
2025-03-03 15:34:06 -05:00
|
|
|
lonlat: "POINT(#{params[:longitude]} #{params[:latitude]})",
|
2024-05-29 17:06:58 -04:00
|
|
|
timestamp: params[:timestamp],
|
|
|
|
|
user_id:
|
|
|
|
|
)
|
|
|
|
|
end
|
2024-04-02 11:37:38 -04:00
|
|
|
end
|