Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | 4x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 4x | import Node from 'type/node';
import FieldValue from 'type/field-value';
import Operation, {OperationInput} from 'operation';
interface NodeInput {
readonly id: string;
readonly type_id: string;
readonly [key: string]: FieldValue;
}
interface Input extends OperationInput {
readonly node: NodeInput;
}
class CreateNodeOperation extends Operation<Input, Node> {
protected async performInternal(): Promise<Node> {
const node = await this.buildNode();
const repository = this.getRepository();
return repository.storeNode(node);
}
private async buildNode(): Promise<Node> {
const node_input = this.getNodeInput();
const creator = this.getAccountUrl();
const created_at = Date.now();
const updated_at = created_at;
return {
...node_input,
creator,
created_at,
updated_at,
changes: []
};
}
private getNodeInput(): NodeInput {
const input = this.getInput();
return input.node;
}
private getAccountUrl(): string {
const account = this.getAccount();
const repository = this.getRepository();
return repository.buildNodeUrl(account);
}
}
export default CreateNodeOperation;
|