Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/overwrite #574

Merged
merged 15 commits into from
Nov 30, 2016
Merged

Feature/overwrite #574

merged 15 commits into from
Nov 30, 2016

Conversation

keang
Copy link
Contributor

@keang keang commented Nov 25, 2016

Context

We have a request for a feature to allow admin to overwrite certain host's (all his cancellation policy) cancellation_policy. Effort started with https://github.com/roomorama/concierge/pull/565/files, to add a new column to host and inject the host's cancellation policy into supplier mappers.

The issue

Then next week there'll be a request to overwrite the cancellation_policy per property. I want to prepare for more of such adhoc custom field overwrites (some host want to default available? some host want to have overwrite currencies? because of the Chinese distribution maybe?)

So what might be better than creating new column on the properties, then injecting into Mapper implementations? (11 classes to modify for 11 suppliers)

Solution (this PR)

We can have a "overwrites" table which has:
host_id: int,
property_identifier: string,
data: text(json)

As Lawrence receive a spreadsheet from host detailing the custom cancellation_policy, he just populate the above table, preempting property identifiers before the synchronisation process created a row on the properties table.

PropertySynchronisation#start applies these overwrites before sending to properties to Roomorama.
If an update is removed from the database, the supplier defaults will be kicked in and sent to Roomorama instead.

With this we can halt #565

@keang
Copy link
Contributor Author

keang commented Nov 25, 2016

Missing from this PR is the UI for lawrence to populate the table, but I wanted to do a sanity check with you guys first before carrying forward.. any comments @kkolotyuk @sharipov-ru @rmascarenhas ?

@kkolotyuk
Copy link
Contributor

So I didn't get. We want to override host's fields or each property's fields?

@sharipov-ru
Copy link
Contributor

As I understood, @keang wants to be able to easily update cancellation policies, without modifying every supplier.

@kkolotyuk
Copy link
Contributor

Yes, but he wants to update it per host or per property?

@keang
Copy link
Contributor Author

keang commented Nov 25, 2016

This PR will allow both =D
per host: just set host_id, leave property_identifier to be nil
per property: set both host_id and property_identifier. (because identifier alone doesn't guarantee uniqueness)

@kkolotyuk
Copy link
Contributor

Ok I see. The idea looks fine to me.

@keang
Copy link
Contributor Author

keang commented Nov 30, 2016

Access Overwrites from hosts list:

image

list of overwrites for a host

image

Create/edit form:

image

Complete with flashes:

image

@keang
Copy link
Contributor Author

keang commented Nov 30, 2016

@kkolotyuk @sharipov-ru please 👀

change do
create_table :overwrites do
primary_key :id
foreign_key :host_id, :hosts, on_delete: :set_null, null: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on_delete: :set_null, null: false this is a contradiction isn't it?

Copy link
Contributor Author

@keang keang Nov 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is would actually prevent deleting a host that still has overwrites.
The host deletion flow need to delete existing overwrites before deleting a host. Will add to our exising Flows::HostDeletion

class OverwriteRepository
include Hanami::Repository

# returns the total number of suppliers in the database.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong comment.

expose :overwrite

def call(params)
@overwrite = Overwrite.new
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra spaces before =

end

def valid_json?
json_decode(data_json).success?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be add Hash class check here. Because json_decode returns success result for nil and any string and here what I see in this case:
json_error

@@ -5,7 +5,7 @@ class New
expose :overwrite

def call(params)
@overwrite = Overwrite.new
@overwrite = Overwrite.new
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still 2 spaces 💅

@keang
Copy link
Contributor Author

keang commented Nov 30, 2016 via email

@sharipov-ru
Copy link
Contributor

Looks good!

@keang keang merged commit ea6d18c into development Nov 30, 2016
@keang keang deleted the feature/overwrite branch November 30, 2016 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants