Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7f98d56

Browse files
authoredApr 20, 2024
fix(hooks): generate other https methods (#74)
1 parent e6eb1d8 commit 7f98d56

File tree

3 files changed

+176
-142
lines changed

3 files changed

+176
-142
lines changed
 

‎examples/react-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@tanstack/react-query": "^5.18.1",
1717
"axios": "^1.6.7",
1818
"form-data": "~4.0.0",
19+
"prettier": "^3.2.5",
1920
"react": "^18.2.0",
2021
"react-dom": "^18.2.0"
2122
},

‎pnpm-lock.yaml

Lines changed: 146 additions & 138 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/createExports.mts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,36 @@ export const createExports = (service: Service) => {
66
const { klasses } = service;
77
const methods = klasses.map((k) => k.methods).flat();
88

9-
const allGet = methods.filter((m) => m.httpMethodName === "'GET'");
10-
const allPost = methods.filter((m) => m.httpMethodName === "'POST'");
9+
const allGet = methods.filter((m) =>
10+
m.httpMethodName.toUpperCase().includes("GET")
11+
);
12+
const allPost = methods.filter((m) =>
13+
m.httpMethodName.toUpperCase().includes("POST")
14+
);
15+
const allPut = methods.filter((m) =>
16+
m.httpMethodName.toUpperCase().includes("PUT")
17+
);
18+
const allPatch = methods.filter((m) =>
19+
m.httpMethodName.toUpperCase().includes("PATCH")
20+
);
21+
const allDelete = methods.filter((m) =>
22+
m.httpMethodName.toUpperCase().includes("DELETE")
23+
);
1124

12-
const allQueries = allGet.map((m) => createUseQuery(m));
13-
const allMutations = allPost.map((m) => createUseMutation(m));
25+
const allGetQueries = allGet.map((m) => createUseQuery(m));
26+
27+
const allPostMutations = allPost.map((m) => createUseMutation(m));
28+
const allPutMutations = allPut.map((m) => createUseMutation(m));
29+
const allPatchMutations = allPatch.map((m) => createUseMutation(m));
30+
const allDeleteMutations = allDelete.map((m) => createUseMutation(m));
31+
32+
const allQueries = [...allGetQueries];
33+
const allMutations = [
34+
...allPostMutations,
35+
...allPutMutations,
36+
...allPatchMutations,
37+
...allDeleteMutations,
38+
];
1439

1540
const commonInQueries = allQueries
1641
.map(({ apiResponse, returnType, key }) => [apiResponse, returnType, key])

0 commit comments

Comments
 (0)
Please sign in to comment.