Skip to content

Commit

Permalink
feat: Use class properties (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
ffflorian committed Aug 5, 2019
1 parent c76ae88 commit 9f0adf2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
17 changes: 10 additions & 7 deletions src/templates/Resource.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ export class {{{name}}} {
{{/each}}
*/
{{/if}}
async {{{this.parameterMethod}}}
(
{{{this.parameterMethod}}} = async (
{{#each this.pathParameters}}
{{{this.name}}}: {{{this.type}}},
{{/each}}
Expand All @@ -37,14 +36,16 @@ export class {{{name}}} {
{{/each}}
}
{{/if}}
): Promise<{{{this.returnType}}}> {
): Promise<{{{this.returnType}}}> => {
const resource = {{{this.formattedUrl}}};
{{#or this.queryParameters.length this.bodyParameters.length}}
{{#if this.needsDataObj}}
const config = {
{{#if this.bodyParameters.length}}
data: {
{{#each this.bodyParameters}}{{this.name}},{{/each}}
{{#each this.bodyParameters}}
{{this.name}},
{{/each}}
},
{{/if}}
{{#if this.queryParameters.length}}
Expand All @@ -57,7 +58,9 @@ export class {{{name}}} {
{{/eq}}
{{#gt this.bodyParameters.length}}
const data = {
{{#each this.bodyParameters}}{{{this.name}}},{{/each}}
{{#each this.bodyParameters}}
{{{this.name}}},
{{/each}}
};
{{/gt}}
{{#if this.queryParameters.length}}
Expand All @@ -76,13 +79,13 @@ export class {{{name}}} {
{{#if this.needsDataObj}}
config,
{{else}}
data
data,
{{/if}}
{{/or}}
);
{{#isnt this.returnType "void"}}
return response.data;
{{/isnt}}
}
};
{{/each}}
}
6 changes: 3 additions & 3 deletions src/test/snapshots/1-query-param-description.ts.fixture
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ export class ArchiveService {
/**
* @param instanceId ID of instance to return
*/
async postByInstanceId(
postByInstanceId = async (
instanceId: string,
body: {archive: {}; conversationId: string}
): Promise<{instanceId: string; name: string}> {
): Promise<{instanceId: string; name: string}> => {
const resource = `/instance/${instanceId}/archive`;
const data = body;
const response = await this.apiClient.post<{
instanceId: string;
name: string;
}>(resource, data);
return response.data;
}
};
}
4 changes: 2 additions & 2 deletions src/test/snapshots/3-delete-by-id-number.ts.fixture
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export class ExchangeService {
this.apiClient = apiClient;
}

async deleteById(id: number): Promise<void> {
deleteById = async (id: number): Promise<void> => {
const resource = `/api/v1/exchange/${id}`;
await this.apiClient.delete(resource);
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export class ExchangeService {
this.apiClient = apiClient;
}

async deleteById(id: number): Promise<number> {
deleteById = async (id: number): Promise<number> => {
const resource = `/api/v1/exchange/${id}`;
const response = await this.apiClient.delete<number>(resource);
return response.data;
}
};
}
6 changes: 3 additions & 3 deletions src/test/snapshots/5-query-param-required.ts.fixture
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ export class UserService {
this.apiClient = apiClient;
}

async getAll(params?: {
getAll = async (params?: {
firstname: string;
lastname: string;
age?: number;
}): Promise<string> {
}): Promise<string> => {
const resource = '/api/user';
const config = {
params,
};
const response = await this.apiClient.get<string>(resource, config);
return response.data;
}
};
}

0 comments on commit 9f0adf2

Please sign in to comment.