Skip to content

Commit

Permalink
adding seed for general_configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jyotigautam committed Nov 28, 2018
1 parent 765ee82 commit 518bfd8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion apps/admin_app/lib/admin_app_web/views/layout_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule AdminAppWeb.LayoutView do
alias Snitch.Data.Schema.{GeneralConfiguration, Taxonomy}
alias Snitch.Core.Tools.MultiTenancy.Repo
alias AdminAppWeb.Helpers
import Ecto.Query

@doc """
Generates name for the JavaScript view we want to use
Expand Down Expand Up @@ -36,7 +37,8 @@ defmodule AdminAppWeb.LayoutView do
end

def check_general_settings() do
Repo.all(GeneralConfiguration) |> List.first()
count = Repo.aggregate(from(g in "snitch_general_configurations"), :count, :id)
if count == 1, do: true, else: false
end

def get_default_taxonomy() do
Expand Down
9 changes: 9 additions & 0 deletions apps/snitch_core/priv/repo/seed/general_configuration.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Snitch.Seed.GeneralConfiguration do
alias Snitch.Data.Schema.GeneralConfiguration, as: GCSchema
alias Snitch.Core.Tools.MultiTenancy.Repo

def seed!() do
Repo.delete_all(GCSchema)
%GCSchema{currency: "USD"} |> Repo.insert()
end
end
2 changes: 0 additions & 2 deletions apps/snitch_core/priv/repo/seed/option_types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ defmodule Snitch.Seed.OptionType do
alias Snitch.Core.Tools.MultiTenancy.Repo
alias Snitch.Data.Schema.OptionType

@base_path Application.app_dir(:snitch_core, "priv/repo/demo/demo_data")

def seed!() do
create_option_type("size", "Size")
create_option_type("color", "Color")
Expand Down
4 changes: 3 additions & 1 deletion apps/snitch_core/priv/repo/seed/seeds.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
alias Snitch.Core.Tools.MultiTenancy.Repo

alias Snitch.Seed.{
GeneralConfiguration,
CountryState,
PaymentMethods,
OptionType,
Expand All @@ -32,9 +33,10 @@ alias Snitch.Tools.Helper.Taxonomy, as: TaxonomyHelper

variant_count = 9

# seeds general settings for the store.
GeneralConfiguration.seed!()
# seeds the taxonomy
# Taxonomy.seed()

# seeds countries and states entity
Repo.transaction(fn ->
CountryState.seed_countries!()
Expand Down

0 comments on commit 518bfd8

Please sign in to comment.