-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #233 from JoinColony/maintenance/153-check-domain-…
…id-when-creating-task Check domain ID when creating task
- Loading branch information
Showing
19 changed files
with
233 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/colony-js-client/src/ColonyClient/senders/CreateTask.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* @flow */ | ||
/* eslint-disable no-underscore-dangle */ | ||
|
||
import ContractClient from '@colony/colony-js-contract-client'; | ||
import type ColonyClient from '../index'; | ||
|
||
type InputValues = { | ||
specificationHash: string, | ||
domainId: number, | ||
}; | ||
|
||
type OutputValues = { | ||
id: number, | ||
}; | ||
|
||
// XXX This is a good use-case for some kind of async validation step, | ||
// but since the underlying method functionality is due to change very soon, | ||
// we're opting to not make big changes to the Sender behaviour, and simply | ||
// extend the `send` method to perform this async validation. | ||
export default class CreateTask extends ContractClient.Sender< | ||
InputValues, | ||
OutputValues, | ||
ColonyClient, | ||
> { | ||
async send(inputValues: InputValues, options: *) { | ||
// Validate that the domain exists before attempting to create a task | ||
if (Object.hasOwnProperty.call(inputValues, 'domainId')) { | ||
const { count } = await this.client.getDomainCount.call(); | ||
if (count < inputValues.domainId) | ||
throw new Error(`Domain ID ${inputValues.domainId} not found`); | ||
} | ||
return super.send(inputValues, options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.