-
Notifications
You must be signed in to change notification settings - Fork 0
/
AngularWebAPIService.nt
29 lines (25 loc) · 1.1 KB
/
AngularWebAPIService.nt
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
{{ for class in data.Classes | Types.ThatInheritFrom "ControllerBase"
capture output }}
module App {
export class {{ class.Name }} {
constructor(private $http: ng.IHttpService) {
}
{{ for method in class.Methods | Symbols.ThatArePublic
parameters = method | Action.Parameters | Parameters.ToTypeScript | Array.Join ", ";
bodyParameterName = (method | Action.BodyParameter)?.Name ?? "null"
returnType = method | Action.ReturnType | Type.ToTypeScriptType
}}
public {{ method.Name | String.ToCamelCase }} = ({{ parameters }}) : ng.IHttpPromise<{{returnType}}> => {
return this.$http<{{returnType}}>({
url: `{{ method | Action.Url }}`,
method: "{{ method | Action.HttpMethod }}",
data: {{ bodyParameterName }}
});
};
{{- end}}
}
angular.module("App").service("{{class.Name | String.Replace "Controller" "Service"}}", ["$http", {{class.Name}}]);
}
{{- end
Save output class.BareName + ".ts"
end }}