Skip to content

Commit

Permalink
fix(integriti_visitor_access): split models into a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach committed Feb 17, 2025
1 parent 492fa20 commit e9a9332
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 80 deletions.
2 changes: 1 addition & 1 deletion drivers/inner_range/integriti_visitor_access.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require "placeos-driver"
require "placeos-driver/interface/mailer"
require "placeos-driver/interface/mailer_templates"

# other data
# required models
require "../wiegand/models"
require "../place/visitor_models"

Expand Down
80 changes: 1 addition & 79 deletions drivers/place/visitor_mailer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require "placeos-driver/interface/mailer"
require "placeos-driver/interface/mailer_templates"

require "./password_generator_helper"
require "./visitor_models"

require "uuid"
require "oauth2"
Expand Down Expand Up @@ -184,85 +185,6 @@ class Place::VisitorMailer < PlaceOS::Driver
@building_zone.as(ZoneDetails)
end

enum Induction
TENTATIVE
ACCEPTED
DECLINED
end

abstract class GuestNotification
include JSON::Serializable

use_json_discriminator "action", {
"booking_created" => BookingGuest,
"booking_updated" => BookingGuest,
"meeting_created" => EventGuest,
"meeting_update" => EventGuest,
"checkin" => GuestCheckin,
"induction_accepted" => BookingInduction,
"induction_declined" => BookingInduction,
}

property action : String

property checkin : Bool?
property event_summary : String
property event_starting : Int64
property attendee_name : String?
property attendee_email : String
property host : String

# This is optional for backwards compatibility
property zones : Array(String)?

property ext_data : Hash(String, JSON::Any)?
end

class EventGuest < GuestNotification
include JSON::Serializable

property system_id : String
property event_id : String
property resource : String

def resource_id
system_id
end
end

class BookingGuest < GuestNotification
include JSON::Serializable

property booking_id : Int64
property resource_id : String

def event_id
booking_id.to_s
end
end

class GuestCheckin < GuestNotification
include JSON::Serializable

property system_id : String = ""
property event_id : String = ""
property resource : String = ""
property resource_id : String = ""
end

class BookingInduction < GuestNotification
include JSON::Serializable

property induction : Induction = Induction::TENTATIVE
property booking_id : Int64
property resource_id : String
property resource_ids : Array(String)

def event_id
booking_id.to_s
end
end

protected def guest_event(payload)
logger.debug { "received guest event payload: #{payload}" }
guest_details = GuestNotification.from_json payload
Expand Down
82 changes: 82 additions & 0 deletions drivers/place/visitor_models.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
require "json"

module Place
enum Induction
TENTATIVE
ACCEPTED
DECLINED
end

abstract class GuestNotification
include JSON::Serializable

use_json_discriminator "action", {
"booking_created" => BookingGuest,
"booking_updated" => BookingGuest,
"meeting_created" => EventGuest,
"meeting_update" => EventGuest,
"checkin" => GuestCheckin,
"induction_accepted" => BookingInduction,
"induction_declined" => BookingInduction,
}

property action : String

property checkin : Bool?
property event_summary : String
property event_starting : Int64
property attendee_name : String?
property attendee_email : String
property host : String

# This is optional for backwards compatibility
property zones : Array(String)?

property ext_data : Hash(String, JSON::Any)?
end

class EventGuest < GuestNotification
include JSON::Serializable

property system_id : String
property event_id : String
property resource : String

def resource_id
system_id
end
end

class BookingGuest < GuestNotification
include JSON::Serializable

property booking_id : Int64
property resource_id : String

def event_id
booking_id.to_s
end
end

class GuestCheckin < GuestNotification
include JSON::Serializable

property system_id : String = ""
property event_id : String = ""
property resource : String = ""
property resource_id : String = ""
end

class BookingInduction < GuestNotification
include JSON::Serializable

property induction : Induction = Induction::TENTATIVE
property booking_id : Int64
property resource_id : String
property resource_ids : Array(String)

def event_id
booking_id.to_s
end
end
end

0 comments on commit e9a9332

Please sign in to comment.