Updated API DB oriented models' init functions
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Dominic Grimm 2022-03-08 09:44:33 +01:00
parent 1554ab16cd
commit 46c64f9cb5
No known key found for this signature in database
GPG key ID: 27C59510125F3C8A
3 changed files with 4 additions and 4 deletions

View file

@ -36,8 +36,8 @@ module Backend
def initialize(@model : {{ type }}) def initialize(@model : {{ type }})
end end
def initialize(id : Int32) def self.from_id(id : Int32) : self
@model = {{ type }}.find!(id) new({{ type }}.find!(id))
end end
{% space_name = type.names.last.underscore.gsub(/_/, " ").capitalize %} {% space_name = type.names.last.underscore.gsub(/_/, " ").capitalize %}

View file

@ -38,7 +38,7 @@ module Backend
def user(context : Context, id : Int32) : User def user(context : Context, id : Int32) : User
context.admin! context.admin!
User.new(id) User.from_id(id)
end end
@[GraphQL::Field] @[GraphQL::Field]

View file

@ -76,7 +76,7 @@ module Backend
end end
# Creates user data from DB entry index # Creates user data from DB entry index
def self.from_index(id : Int32) : self def self.from_id(id : Int32) : self
from_db(Db::User.find!(id)) from_db(Db::User.find!(id))
end end
end end