Skip to content

Commit

Permalink
Merge pull request #75 from souravbhowmik1999/methodSet
Browse files Browse the repository at this point in the history
Distinct Data Handling for POST and PATCH Requests
  • Loading branch information
Shubham4026 authored Dec 18, 2024
2 parents 2a64ede + 2f9a39e commit 4dfb521
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/common/middleware/middleware.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export class MiddlewareServices {
return await this.gatewayService.handleRequestForMultipartData(
res,
fullUrl,
req.method,
formData,
token,
);
Expand Down
17 changes: 12 additions & 5 deletions src/middleware/gateway.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,24 @@ export class GatewayService {
async handleRequestForMultipartData(
res,
url: string,
method,
formData: any,
token?: string,
) {
try {
const response = await axios.patch(url, formData, {
headers: {
...formData.getHeaders(),
...(token ? { Authorization: `Bearer ${token}` } : {}),
},
let response;
const headers = {
...formData.getHeaders(),
...(token ? { Authorization: `Bearer ${token}` } : {}),
};
response = await axios({
method: method.toLowerCase(),
url,
data: formData,
headers,
});


res.locals.responseBody = response.data;
res.status(response.status);
return response.data;
Expand Down

0 comments on commit 4dfb521

Please sign in to comment.