|
|
@ -1,5 +1,7 @@ |
|
|
import changeCase from 'change-case'; |
|
|
import changeCase from 'change-case'; |
|
|
import { replacer } from '../../utils/replacer'; |
|
|
import { replacer } from '../../utils/replacer'; |
|
|
|
|
|
import { Argument } from '../../utils/generators'; |
|
|
|
|
|
import snq from 'snq'; |
|
|
|
|
|
|
|
|
export namespace ServiceTemplates { |
|
|
export namespace ServiceTemplates { |
|
|
export function classTemplate(name: string, content: string) { |
|
|
export function classTemplate(name: string, content: string) { |
|
|
@ -16,19 +18,24 @@ export class ${changeCase.pascalCase(name)}Service { |
|
|
}`;
|
|
|
}`;
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export function getMethodTemplate( |
|
|
export function getMethodTemplate(name: string, url: string, args: string = '', queryParams?: boolean) { |
|
|
name: string, |
|
|
|
|
|
url: string, |
|
|
|
|
|
args: string = '', |
|
|
|
|
|
params: string[] = [], |
|
|
|
|
|
queryParams?: object, |
|
|
|
|
|
) { |
|
|
|
|
|
return ` |
|
|
return ` |
|
|
${changeCase.camelCase(replacer(name))}(${args}): Observable<any> { |
|
|
${changeCase.camelCase(replacer(name))}(${args}${queryParams ? ', queryParams: any' : ''}): Observable<any> { |
|
|
return this.restService.request<void, any>({ |
|
|
${requestTemplate('GET', url, false, !!queryParams)} |
|
|
method: 'GET', |
|
|
|
|
|
url: '/${url}${params.length ? '/' + params.join('/') : ''}', |
|
|
|
|
|
}); |
|
|
|
|
|
}`;
|
|
|
}`;
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function requestTemplate(method: string, url: string, body?: boolean, queryParams?: boolean) { |
|
|
|
|
|
const reg = /(?<=\{)(.*)(?=\})/g; |
|
|
|
|
|
|
|
|
|
|
|
(url.match(reg) || []).forEach(matched => { |
|
|
|
|
|
const index = url.indexOf(`{${matched}}`); |
|
|
|
|
|
url = url.slice(0, index) + '$' + url.slice(index); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return `return this.restService.request<void, any>({
|
|
|
|
|
|
method: '${method}', |
|
|
|
|
|
url: \`/${url}\`,${queryParams ? 'params: queryParams,' : ''}${body ? 'body,' : ''} |
|
|
|
|
|
});`;
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|