Skip to content

Instantly share code, notes, and snippets.

@mrdotb

mrdotb/model.ex Secret

Last active May 4, 2022 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrdotb/112c09ea7d1e5895cfd4746f8e7d80ad to your computer and use it in GitHub Desktop.
Save mrdotb/112c09ea7d1e5895cfd4746f8e7d80ad to your computer and use it in GitHub Desktop.
model.ex
defmodule App.Print do
@behaviour App.Recover.Impl
@table_name "prints"
import Ecto.Query, only: [from: 2]
alias App.{Repo, Teams}
alias App.Schemas.Print
alias App.Teams.Recover.Helpers
@impl true
def dump([team, terminal_id]) do
query =
from(p in Print,
where: p.terminal_id == ^terminal_id,
order_by: p.inserted_at,
select: p
)
Repo.all(query, prefix: Teams.team_prefix(team))
|> Enum.map(&map(&1))
end
@impl true
def map(p) do
[
id: p.id,
count: p.count,
type: p.type,
terminal_id: p.terminal_id,
print_date: Helpers.cast(p.print_date),
transaction_id: p.transaction_id,
prev_id: p.prev_id,
next_id: p.next_id,
hash: "",
synced: Helpers.cast(true)
]
end
@impl true
def table_name, do: @table_name
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment