crud test controller and class validator mocker generate classes
This commit is contained in:
parent
6c85616c99
commit
9617d313a1
24 changed files with 242 additions and 108 deletions
24
server/src/core/repository/http_repository.ts
Normal file
24
server/src/core/repository/http_repository.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import axios from "axios";
|
||||
import { Result } from "../helpers/result";
|
||||
import { HttpMethodType } from "../controllers/http_controller";
|
||||
|
||||
export class HttpRepository {
|
||||
serverUrl = "http://localhost:4001";
|
||||
|
||||
constructor(serverURL: string) {
|
||||
this.serverUrl = serverURL;
|
||||
}
|
||||
|
||||
async jsonRequest<T>(url: string, method: HttpMethodType, reqBody?: any): Promise<Result<Error, T>> {
|
||||
try {
|
||||
const result = await axios(this.serverUrl + url, { method: method, data: reqBody });
|
||||
if (result.status !== 200) {
|
||||
return Result.error(Error("status code" + String(result.status)));
|
||||
}
|
||||
return Result.ok(result.data);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return Result.error(error);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue