/
createService.js
44 lines (33 loc) · 918 Bytes
/
createService.js
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class createService {
constructor(moduleName) {
this.moduleName = moduleName;
}
capitalizeModule(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
generateService() {
const serviceEndpoint = this.moduleName.toLowerCase();
const module = this.capitalizeModule(this.moduleName);
return `
import http from "../httpServer";
class ${module}Service {
static create(data) {
return http.post("/${serviceEndpoint}/add", data);
}
static get() {
return http.get("/${serviceEndpoint}/get");
}
static getById(id) {
return http.get("/${serviceEndpoint}/get/" + id);
}
static deleteById(id) {
return http.delete("/${serviceEndpoint}/delete/" + id);
}
static update(data, id) {
return http.put("/${serviceEndpoint}/update/" + id, data);
}
}
export default ${module}Service;`;
}
}
module.exports = createService;