Merge pull request 'Clean up #not_nil!
uses' (#84) from clean-up-not-nil into main
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: mentorenwahl/mentorenwahl#84
This commit is contained in:
commit
630d858dde
4 changed files with 7 additions and 8 deletions
|
@ -50,7 +50,7 @@ module Backend
|
||||||
|
|
||||||
if @user
|
if @user
|
||||||
@admin = @user.not_nil!.admin
|
@admin = @user.not_nil!.admin
|
||||||
@role = Schema::UserRole.parse(@user.not_nil!.role).not_nil!
|
@role = Schema::UserRole.parse(@user.not_nil!.role)
|
||||||
@external =
|
@external =
|
||||||
case @role.not_nil!
|
case @role.not_nil!
|
||||||
when .teacher?
|
when .teacher?
|
||||||
|
|
|
@ -42,7 +42,7 @@ module Backend
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(id : Int32)
|
def initialize(id : Int32)
|
||||||
@model = {{ type }}.find(id).not_nil!
|
@model = {{ type }}.find!(id)
|
||||||
end
|
end
|
||||||
|
|
||||||
{% space_name = type.names.last.underscore.gsub(/_/, " ").capitalize %}
|
{% space_name = type.names.last.underscore.gsub(/_/, " ").capitalize %}
|
||||||
|
@ -50,7 +50,7 @@ module Backend
|
||||||
@[GraphQL::Field]
|
@[GraphQL::Field]
|
||||||
# {{ space_name }}'s ID
|
# {{ space_name }}'s ID
|
||||||
def id : Int32
|
def id : Int32
|
||||||
@model.id.not_nil!.to_i32
|
@model.id.not_nil!.to_i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -82,9 +82,9 @@ module Backend
|
||||||
@model.teacher
|
@model.teacher
|
||||||
when .student?
|
when .student?
|
||||||
@model.student
|
@model.student
|
||||||
end.not_nil!.id.not_nil!.to_i
|
end
|
||||||
rescue NilAssertionError
|
.try(&.id)
|
||||||
nil
|
.try(&.to_i)
|
||||||
end
|
end
|
||||||
|
|
||||||
@[GraphQL::Field]
|
@[GraphQL::Field]
|
||||||
|
|
|
@ -25,8 +25,7 @@ module Mosquito::Serializers::Granite
|
||||||
end
|
end
|
||||||
|
|
||||||
def deserialize_{{ method_suffix }}(raw : String) : {{ klass.id }}
|
def deserialize_{{ method_suffix }}(raw : String) : {{ klass.id }}
|
||||||
id = raw.to_i
|
{{ klass.id }}.find!(raw.to_i)
|
||||||
{{ klass.id }}.find(id).not_nil!
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue