@@ -14,6 +14,9 @@ const docusignEsign = require('docusign-esign');
1414const workflowI9 = require ( '../assets/workflows/I9.workflow' ) ;
1515const workflowOfferLetter = require ( '../assets/workflows/offerLetter.workflow' ) ;
1616const workflowNda = require ( '../assets/workflows/nda.workflow' ) ;
17+ const templateI9 = require ( '../assets/templates/I9.template' ) ;
18+ const templateOfferLetter = require ( '../assets/templates/offerLetter.template' ) ;
19+ const templateNda = require ( '../assets/templates/nda.template' ) ;
1720const { TEMPLATE_TYPE } = require ( '../constants' ) ;
1821
1922const oAuth = docusign . ApiClient . OAuth ;
@@ -62,30 +65,34 @@ class WorkflowsService {
6265
6366 static selectWorkflow = templateType => {
6467 let workflowCaller = null ;
68+ let templateCaller = null ;
6569
6670 switch ( templateType ) {
6771 case TEMPLATE_TYPE . I9 :
6872 workflowCaller = workflowI9 ;
73+ templateCaller = templateI9 ;
6974 break ;
7075
7176 case TEMPLATE_TYPE . OFFER :
7277 workflowCaller = workflowOfferLetter ;
78+ templateCaller = templateOfferLetter ;
7379 break ;
7480
7581 case TEMPLATE_TYPE . NDA :
7682 workflowCaller = workflowNda ;
83+ templateCaller = templateNda ;
7784 break ;
7885
7986 default :
8087 throw new Error ( 'selectWorkflow: TemplateType is not correct or not found' ) ;
8188 }
8289
83- return workflowCaller ;
90+ return { workflowCaller, templateCaller } ;
8491 } ;
8592
8693 static getTemplate = async args => {
87- const workflowCaller = this . selectWorkflow ( args . templateType ) ;
88- const templateName = workflowCaller ( null , null ) . name ;
94+ const { templateCaller } = this . selectWorkflow ( args . templateType ) ;
95+ const templateName = templateCaller ( ) . name ;
8996
9097 this . dsApiClient . setBasePath ( args . basePath ) ;
9198 this . dsApiClient . addDefaultHeader ( 'Authorization' , `Bearer ${ args . accessToken } ` ) ;
@@ -110,8 +117,25 @@ class WorkflowsService {
110117 } ;
111118 } ;
112119
120+ static createTemplate = async args => {
121+ const { templateCaller } = this . selectWorkflow ( args . templateType ) ;
122+
123+ this . dsApiClient . setBasePath ( args . basePath ) ;
124+ this . dsApiClient . addDefaultHeader ( 'Authorization' , `Bearer ${ args . accessToken } ` ) ;
125+ const templatesApi = new docusignEsign . TemplatesApi ( this . dsApiClient ) ;
126+ const template = await templatesApi . createTemplate ( args . accountId , {
127+ envelopeTemplate : templateCaller ( ) ,
128+ } ) ;
129+
130+ return {
131+ templateId : template . templateId ,
132+ templateName : template . name ,
133+ createdNewTemplate : false ,
134+ } ;
135+ } ;
136+
113137 static createWorkflow = async ( { templateId, accessToken, basePath, accountId, templateType } ) => {
114- const workflowCaller = this . selectWorkflow ( templateType ) ;
138+ const { workflowCaller } = this . selectWorkflow ( templateType ) ;
115139 const workflowTemplate = workflowCaller ( templateId , accountId ) ;
116140 workflowTemplate . workflowDefinition . workflowName += ` - ${ this . workflowSuffix } ` ;
117141
0 commit comments