Skip to content
Permalink
Browse files

Remove target_id from target version mutator

  • Loading branch information
bodhish committed Feb 11, 2020
1 parent bfdd188 commit 3b9bf521c804afe68308553bf9e10608a6764321
@@ -1,7 +1,6 @@
module Mutations
class CreateTargetVersion < GraphQL::Schema::Mutation
argument :target_id, ID, required: true
argument :target_version_id, ID, required: false
argument :target_version_id, ID, required: true

description "Update a target"

@@ -24,8 +24,8 @@ let reducer = (_state, action) =>

module CreateTargetVersionMutation = [%graphql
{|
mutation($targetId: ID!, $targetVersionId: ID) {
createTargetVersion(targetId: $targetId, targetVersionId: $targetVersionId) {
mutation($targetVersionId: ID!) {
createTargetVersion(targetVersionId: $targetVersionId) {
success
}
}
@@ -62,7 +62,7 @@ let createTargetVersion = (targetId, targetVersion, send) => {

send(SetLoading);

CreateTargetVersionMutation.make(~targetId, ~targetVersionId, ())
CreateTargetVersionMutation.make(~targetVersionId, ())
|> GraphqlQuery.sendQuery
|> Js.Promise.then_(_result => {
loadContentBlocks(targetId, send, None);
@@ -1,11 +1,10 @@
class CreateTargetVersionMutator < ApplicationQuery
property :target_id
property :target_version_id

validate :target_version_must_be_valid
validate :target_exists
validate :content_should_change
validate :less_than_three_version_per_day
validate :less_than_three_versions_per_day

def create_target_version
::TargetVersions::CreateService.new(target, target_version).execute
@@ -23,7 +22,7 @@ def target_exists
errors[:base] << 'Target does not exist' if target.blank?
end

def less_than_three_version_per_day
def less_than_three_versions_per_day
return if target.target_versions.where(created_at: Time.now.beginning_of_day..Time.now.end_of_day).count < 3

errors[:base] << 'You cannot create more than 3 versions per day'
@@ -40,11 +39,11 @@ def content_should_change
end

def target
@target ||= current_school.targets.find_by(id: target_id)
@target ||= current_school.targets.find_by(id: target_version.target_id)
end

def target_version
@target_version ||= target.target_versions.find_by(id: target_version_id)
@target_version ||= TargetVersion.find_by(id: target_version_id)
end

def authorized?
@@ -5186,7 +5186,7 @@
"description": "",
"args": [
{
"name": "targetId",
"name": "targetVersionId",
"description": "",
"type": {
"kind": "NON_NULL",
@@ -5198,16 +5198,6 @@
}
},
"defaultValue": null
},
{
"name": "targetVersionId",
"description": "",
"type": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
},
"defaultValue": null
}
],
"type": {

0 comments on commit 3b9bf52

Please sign in to comment.
You can’t perform that action at this time.