backend: improve SetRandomProjectColor mutation

This commit is contained in:
0x1eef 2024-01-17 15:44:52 -03:00
parent a369edd812
commit 17458dd2a5
4 changed files with 6 additions and 9 deletions

View file

@ -20,7 +20,7 @@ module Twenty
# @return [String]
# Returns the default SQLite database.
def self.default_database
@default_database ||= File.join(home, "20.sqlite")
@default_database ||= File.join(home, "database.sqlite")
end
##

View file

@ -2,17 +2,16 @@ module Twenty::GraphQL::Mutation
class SetRandomProjectColor < ::GraphQL::Schema::Mutation
require_relative "../type/project"
argument :project_id, Int, required: true
field :ok, Boolean, null: false
field :errors, [String], null: false
field :project, Twenty::GraphQL::Type::Project, null: true
def resolve(project_id:)
project = Twenty::Project.find_by(id: project_id)
project.color = project.send(:random_color)
project.save!
{ok: true, errors: [], project:}
project = Twenty::Project.find(project_id)
project.update!(color: project.random_color)
{errors: [], project:}
rescue => ex
{ok: false, errors: [ex.message]}
{errors: [ex.message]}
end
end
end

View file

@ -53,7 +53,6 @@ Autogenerated return type of SetRandomProjectColor.
"""
type SetRandomProjectColorPayload {
errors: [String!]!
ok: Boolean!
project: Project
}

View file

@ -108,7 +108,6 @@ export type QueryTasksArgs = {
export type SetRandomProjectColorPayload = {
__typename?: "SetRandomProjectColorPayload";
errors: Array<Scalars["String"]["output"]>;
ok: Scalars["Boolean"]["output"];
project?: Maybe<Project>;
};