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

feat: update lenra datastore service #173

Merged
merged 1 commit into from
Mar 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions apps/lenra/lib/lenra/services/datastore_services.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,4 @@ defmodule Lenra.DatastoreServices do
def get_by(clauses) do
Repo.get_by(Datastore, clauses)
end

@doc """
Gets the datastore data

Returns the data.
data is nil if the data does not exists for this user/app
"""
def get_old_data(user_id, application_id) do
get_by(user_id: user_id, application_id: application_id)
end

@doc """
Creates or updates the data in the corresponding datastore.

Returns `{:ok, struct}` if the data was successfully inserted or updated.
Returns `{:error, changeset}` if the data could not be inserted or updated.
"""
def upsert_data(user_id, application_id, data) do
user_id
|> Datastore.new(application_id, data)
|> Repo.insert(
on_conflict: [set: [data: data]],
conflict_target: [:user_id, :application_id]
)
end
end