update #141
This commit is contained in:
parent
9ec19fd22b
commit
66b2f10fee
1 changed files with 48 additions and 7 deletions
|
|
@ -20,6 +20,7 @@ import { Profile } from "../entities/Profile";
|
||||||
import { isPermissionRequest } from "../middlewares/authWebService";
|
import { isPermissionRequest } from "../middlewares/authWebService";
|
||||||
import { RequestWithUserWebService } from "../middlewares/user";
|
import { RequestWithUserWebService } from "../middlewares/user";
|
||||||
import { OrgRevision } from "../entities/OrgRevision";
|
import { OrgRevision } from "../entities/OrgRevision";
|
||||||
|
import { ApiHistory } from "../entities/ApiHistory";
|
||||||
@Route("api/v2/org/api-service")
|
@Route("api/v2/org/api-service")
|
||||||
@Tags("ApiKey")
|
@Tags("ApiKey")
|
||||||
@Security("webServiceAuth")
|
@Security("webServiceAuth")
|
||||||
|
|
@ -30,6 +31,8 @@ import { OrgRevision } from "../entities/OrgRevision";
|
||||||
export class ApiWebServiceController extends Controller {
|
export class ApiWebServiceController extends Controller {
|
||||||
private apiNameRepository = AppDataSource.getRepository(ApiName);
|
private apiNameRepository = AppDataSource.getRepository(ApiName);
|
||||||
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
|
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
|
||||||
|
private apiHistoryRepository = AppDataSource.getRepository(ApiHistory);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list fields by systems
|
* list fields by systems
|
||||||
* @summary รายการ fields ตาม systems
|
* @summary รายการ fields ตาม systems
|
||||||
|
|
@ -113,21 +116,59 @@ export class ApiWebServiceController extends Controller {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// เพิ่ม Main.id เพราะจะใช้ pk ในการแมบและนับจำนวน
|
// // เพิ่ม Main.id เพราะจะใช้ pk ในการแมบและนับจำนวน
|
||||||
if (!propertyKey.includes(`${Main}.id`)) {
|
// if (!propertyKey.includes(`${Main}.id`)) {
|
||||||
propertyKey.push(`${Main}.id`);
|
// propertyKey.push(`${Main}.id`);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
// add FK
|
||||||
|
let pk:string = ""
|
||||||
|
const primaryColumns = metadata.primaryColumns;
|
||||||
|
primaryColumns.forEach(col => {
|
||||||
|
pk = col.propertyName;
|
||||||
|
if (!propertyKey.includes(`${Main}.${pk}`)) {
|
||||||
|
propertyKey.push(`${Main}.${pk}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const [items, total] = await queryBuilder
|
const [items, total] = await queryBuilder
|
||||||
.select(propertyKey)
|
.select(propertyKey)
|
||||||
.where(condition)
|
.where(condition)
|
||||||
// .orderBy(`${Main}.createdAt`, "DESC")
|
.orderBy(propertyKey[0], "ASC")
|
||||||
.skip(offset)
|
.skip(offset)
|
||||||
.take(pageSize)
|
.take(pageSize)
|
||||||
.getManyAndCount();
|
.getManyAndCount();
|
||||||
|
|
||||||
// ลบ Main.id
|
// ลบ Main.id
|
||||||
const results = items.map(({ id, ...x }) => x);
|
// const results = items.map(({ id, ...x }) => x);
|
||||||
return new HttpSuccess({ items: results, total });
|
// const results = items.map(({ pk, ...x }) => x);
|
||||||
|
|
||||||
|
// const results = items.map(item => {
|
||||||
|
// primaryColumns.forEach(col => delete item[col.propertyName]);
|
||||||
|
// return item;
|
||||||
|
// });
|
||||||
|
|
||||||
|
// save api history
|
||||||
|
const history = {
|
||||||
|
headerApi: JSON.stringify({
|
||||||
|
host: request.headers.host,
|
||||||
|
"x-api-key": request.headers["x-api-key"],
|
||||||
|
connection: request.headers.connection,
|
||||||
|
accept: request.headers.accept,
|
||||||
|
}),
|
||||||
|
tokenApi: Array.isArray(request.headers["x-api-key"])
|
||||||
|
? request.headers["x-api-key"][0] || ""
|
||||||
|
: request.headers["x-api-key"] || "",
|
||||||
|
requestApi: `${request.method} ${request.protocol}://${request.headers.host}${request.originalUrl || request.url}`,
|
||||||
|
responseApi: "OK",
|
||||||
|
ipApi: request.ip,
|
||||||
|
codeApi: code,
|
||||||
|
apiKeyId: request.user.id,
|
||||||
|
apiNameId: apiName.id,
|
||||||
|
createdFullName: request.user.name,
|
||||||
|
lastUpdateFullName: request.user.name,
|
||||||
|
};
|
||||||
|
await this.apiHistoryRepository.save(history);
|
||||||
|
return new HttpSuccess({ items: items, total });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue