add manual swagger json & fix check use before delete api
This commit is contained in:
parent
ca4bb683ea
commit
4c0b729b81
1 changed files with 92 additions and 0 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { ApiKey } from "./../entities/ApiKey";
|
||||||
import { ApiAttribute } from "./../entities/ApiAttribute";
|
import { ApiAttribute } from "./../entities/ApiAttribute";
|
||||||
import { CreateApi } from "./../entities/ApiName";
|
import { CreateApi } from "./../entities/ApiName";
|
||||||
import { PosMaster } from "../entities/PosMaster";
|
import { PosMaster } from "../entities/PosMaster";
|
||||||
|
|
@ -596,6 +597,19 @@ export class ApiManageController extends Controller {
|
||||||
throw new HttpError(HttpStatusCode.FORBIDDEN, "คุณไม่มีสิทธิ์ในการเข้าถึงข้อมูลนี้");
|
throw new HttpError(HttpStatusCode.FORBIDDEN, "คุณไม่มีสิทธิ์ในการเข้าถึงข้อมูลนี้");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const checkUsed = await AppDataSource.getRepository(ApiKey)
|
||||||
|
.createQueryBuilder("apiKey")
|
||||||
|
.innerJoin("apiKey.apiNames", "apiName")
|
||||||
|
.where("apiName.id = :id", { id })
|
||||||
|
.getCount();
|
||||||
|
|
||||||
|
if (checkUsed > 0) {
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatusCode.BAD_REQUEST,
|
||||||
|
"ไม่สามารถลบ API นี้ได้ เนื่องจากมีการใช้งานอยู่",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await queryRunner.manager.getRepository(ApiAttribute).delete({ apiNameId: id });
|
await queryRunner.manager.getRepository(ApiAttribute).delete({ apiNameId: id });
|
||||||
await queryRunner.manager.getRepository(ApiName).delete({ id });
|
await queryRunner.manager.getRepository(ApiName).delete({ id });
|
||||||
|
|
||||||
|
|
@ -615,4 +629,82 @@ export class ApiManageController extends Controller {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list systems
|
||||||
|
* @summary รายการ systems
|
||||||
|
*/
|
||||||
|
@Get("/manual/swagger")
|
||||||
|
async getManualRequestWebService() {
|
||||||
|
const json: any = {};
|
||||||
|
// create swagger documentation for manual request only ApiWebServiceController
|
||||||
|
json["openapi"] = "3.0.0";
|
||||||
|
json["info"] = {
|
||||||
|
title: "Request Web Service",
|
||||||
|
version: "1.0.0",
|
||||||
|
description: "This is a manual request web service.",
|
||||||
|
};
|
||||||
|
json["servers"] = [
|
||||||
|
{
|
||||||
|
url: process.env.API_URL?.replace("/api/v1", "") || "http://localhost:13009",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "http://localhost:13009",
|
||||||
|
description: "Local server",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
json["paths"] = {
|
||||||
|
"/api/v2/org/api-service/{system}/{code}": {
|
||||||
|
get: {
|
||||||
|
summary: "Get Registry Data",
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
name: "system",
|
||||||
|
in: "path",
|
||||||
|
required: true,
|
||||||
|
schema: {
|
||||||
|
type: "string",
|
||||||
|
enum: ["registry", "registry_emp", "registry_temp", "organization"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "code",
|
||||||
|
in: "path",
|
||||||
|
required: true,
|
||||||
|
schema: {
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
description: "Successful response",
|
||||||
|
},
|
||||||
|
400: {
|
||||||
|
description: "Bad request",
|
||||||
|
},
|
||||||
|
500: {
|
||||||
|
description: "Internal server error",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
json["components"] = {
|
||||||
|
securitySchemes: {
|
||||||
|
ApiKeyAuth: {
|
||||||
|
type: "apiKey",
|
||||||
|
in: "header",
|
||||||
|
name: "X-API-Key",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
json["security"] = [
|
||||||
|
{
|
||||||
|
ApiKeyAuth: [],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
return new HttpSuccess(json);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue