@@ -3,36 +3,41 @@ import { fetchFromLinear } from "../fetchFromLinear";
33import { omitBy } from "lodash" ;
44
55interface CustomerNeedCreateResponse {
6- data ?: { customerNeedCreate : { need : { id : string ; customerId ?: string , issueId ?: string , attachmentId ?: string } ; success : boolean } } ;
7- errors ?: {
8- message : string ;
9- extensions ?: {
10- userPresentableMessage ?: string ;
11- } ;
12- } [ ] ;
6+ data ?: {
7+ customerNeedCreate : {
8+ need : { id : string ; customerId ?: string ; issueId ?: string ; attachmentId ?: string } ;
9+ success : boolean ;
10+ } ;
11+ } ;
12+ errors ?: {
13+ message : string ;
14+ extensions ?: {
15+ userPresentableMessage ?: string ;
16+ } ;
17+ } [ ] ;
1318}
1419
1520const createCustomerNeedRequest = async ( z : ZObject , bundle : Bundle ) => {
16- const variables = omitBy (
17- {
18- customerId : bundle . inputData . customerId ,
19- customerExternalId : bundle . inputData . customerExternalId ,
20- issueId : bundle . inputData . issueId ,
21- attachmentId : bundle . inputData . attachmentId ,
22- attachmentUrl : bundle . inputData . attachmentUrl ,
23- body : bundle . inputData . body ,
24- priority : bundle . inputData . priority ,
25- } ,
26- ( v ) => v === undefined
27- ) ;
21+ const variables = omitBy (
22+ {
23+ customerId : bundle . inputData . customerId ,
24+ customerExternalId : bundle . inputData . customerExternalId ,
25+ issueId : bundle . inputData . issueId ,
26+ attachmentId : bundle . inputData . attachmentId ,
27+ attachmentUrl : bundle . inputData . attachmentUrl ,
28+ body : bundle . inputData . body ,
29+ priority : bundle . inputData . priority ,
30+ } ,
31+ ( v ) => v === undefined
32+ ) ;
2833
29- if ( variables . attachmentId && variables . attachmentUrl ) {
30- throw new Error ( "Cannot specify both attachmentId and attachmentUrl" ) ;
31- } else if ( variables . customerId && variables . customerExternalId ) {
32- throw new Error ( "Cannot specify both customerId and customerExternalId" ) ;
33- }
34+ if ( variables . attachmentId && variables . attachmentUrl ) {
35+ throw new Error ( "Cannot specify both attachmentId and attachmentUrl" ) ;
36+ } else if ( variables . customerId && variables . customerExternalId ) {
37+ throw new Error ( "Cannot specify both customerId and customerExternalId" ) ;
38+ }
3439
35- const query = `
40+ const query = `
3641 mutation ZapierCustomerNeedCreate(
3742 $customerId: String,
3843 $customerExternalId: String,
@@ -67,92 +72,96 @@ const createCustomerNeedRequest = async (z: ZObject, bundle: Bundle) => {
6772 }
6873 }` ;
6974
70- const response = await fetchFromLinear ( z , bundle , query , variables ) ;
71- const data = response . json as CustomerNeedCreateResponse ;
75+ const response = await fetchFromLinear ( z , bundle , query , variables ) ;
76+ const data = response . json as CustomerNeedCreateResponse ;
7277
73- if ( data . errors && data . errors . length ) {
74- const error = data . errors [ 0 ] ;
75- throw new z . errors . Error (
76- ( error . extensions && error . extensions . userPresentableMessage ) || error . message ,
77- "invalid_input" ,
78- 400
79- ) ;
80- }
78+ if ( data . errors && data . errors . length ) {
79+ const error = data . errors [ 0 ] ;
80+ throw new z . errors . Error (
81+ ( error . extensions && error . extensions . userPresentableMessage ) || error . message ,
82+ "invalid_input" ,
83+ 400
84+ ) ;
85+ }
8186
82- if ( data . data && data . data . customerNeedCreate && data . data . customerNeedCreate . success ) {
83- return data . data . customerNeedCreate . need ;
84- } else {
85- const error = data . errors ? data . errors [ 0 ] . message : "Something went wrong" ;
86- throw new z . errors . Error ( "Failed to create a customer need" , error , 400 ) ;
87- }
87+ if ( data . data && data . data . customerNeedCreate && data . data . customerNeedCreate . success ) {
88+ return data . data . customerNeedCreate . need ;
89+ } else {
90+ const error = data . errors ? data . errors [ 0 ] . message : "Something went wrong" ;
91+ throw new z . errors . Error ( "Failed to create a customer need" , error , 400 ) ;
92+ }
8893} ;
8994
9095export const createCustomerNeed = {
91- key : "createCustomerNeed" ,
92- display : {
93- hidden : false ,
94- description : "Create a new customer need in Linear" ,
95- label : "Create Customer Need" ,
96- } ,
97- noun : "Customer Need" ,
98- operation : {
99- perform : createCustomerNeedRequest ,
100- inputFields : [
101- {
102- required : false ,
103- label : "Customer ID" ,
104- helpText : "The ID of the customer to create the need for" ,
105- key : "customerId" ,
106- } ,
107- {
108- required : false ,
109- label : "External Customer ID" ,
110- helpText : "The external ID of the customer the need belongs to" ,
111- key : "customerExternalId" ,
112- } ,
113- {
114- required : false ,
115- label : "Issue ID" ,
116- helpText : "The ID of the issue this need is for" ,
117- key : "issueId" ,
118- type : "text" ,
119- } ,
120- {
121- required : false ,
122- label : "Attachment ID" ,
123- helpText : "The ID of the attachment this need is associated with" ,
124- key : "attachmentId" ,
125- type : "text" ,
126- } ,
127- {
128- required : false ,
129- label : "Attachment URL" ,
130- helpText : "Optional URL for the attachment associated with the customer need" ,
131- key : "attachmentUrl" ,
132- type : "text" ,
133- } ,
134- {
135- required : false ,
136- label : "Body" ,
137- helpText : "The content of the need in markdown format." ,
138- key : "body" ,
139- type : "text" ,
140- } ,
141- {
142- required : false ,
143- label : "Priority" ,
144- helpText : "Whether the customer need is important or not. 0 = Not important, 1 = Important." ,
145- key : "priority" ,
146- type : "number" ,
147- } ,
148- ] ,
149- sample : {
150- data : {
151- customerNeedCreate : {
152- need : { id : "93a02c29-da90-4d06-ab1c-96956e94bcd0" , customerId : "6465f500-6626-4253-9073-144535a6c658" , issueId : "a8ea3bfa-5420-492a-84e9-ffe49ca5f22a" } ,
153- success : true ,
154- } ,
155- } ,
96+ key : "createCustomerNeed" ,
97+ display : {
98+ hidden : false ,
99+ description : "Create a new customer need in Linear" ,
100+ label : "Create Customer Need" ,
101+ } ,
102+ noun : "Customer Need" ,
103+ operation : {
104+ perform : createCustomerNeedRequest ,
105+ inputFields : [
106+ {
107+ required : false ,
108+ label : "Customer ID" ,
109+ helpText : "The ID of the customer to create the need for" ,
110+ key : "customerId" ,
111+ } ,
112+ {
113+ required : false ,
114+ label : "External Customer ID" ,
115+ helpText : "The external ID of the customer the need belongs to" ,
116+ key : "customerExternalId" ,
117+ } ,
118+ {
119+ required : false ,
120+ label : "Issue ID" ,
121+ helpText : "The ID of the issue this need is for" ,
122+ key : "issueId" ,
123+ type : "text" ,
124+ } ,
125+ {
126+ required : false ,
127+ label : "Attachment ID" ,
128+ helpText : "The ID of the attachment this need is associated with" ,
129+ key : "attachmentId" ,
130+ type : "text" ,
131+ } ,
132+ {
133+ required : false ,
134+ label : "Attachment URL" ,
135+ helpText : "Optional URL for the attachment associated with the customer need" ,
136+ key : "attachmentUrl" ,
137+ type : "text" ,
138+ } ,
139+ {
140+ required : false ,
141+ label : "Body" ,
142+ helpText : "The content of the need in markdown format." ,
143+ key : "body" ,
144+ type : "text" ,
145+ } ,
146+ {
147+ required : false ,
148+ label : "Priority" ,
149+ helpText : "Whether the customer need is important or not. 0 = Not important, 1 = Important." ,
150+ key : "priority" ,
151+ type : "number" ,
152+ } ,
153+ ] ,
154+ sample : {
155+ data : {
156+ customerNeedCreate : {
157+ need : {
158+ id : "93a02c29-da90-4d06-ab1c-96956e94bcd0" ,
159+ customerId : "6465f500-6626-4253-9073-144535a6c658" ,
160+ issueId : "a8ea3bfa-5420-492a-84e9-ffe49ca5f22a" ,
161+ } ,
162+ success : true ,
156163 } ,
164+ } ,
157165 } ,
166+ } ,
158167} ;
0 commit comments