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 { RequestWithUserWebService } from "../middlewares/user";
|
||||
import { OrgRevision } from "../entities/OrgRevision";
|
||||
import { ApiHistory } from "../entities/ApiHistory";
|
||||
@Route("api/v2/org/api-service")
|
||||
@Tags("ApiKey")
|
||||
@Security("webServiceAuth")
|
||||
|
|
@ -30,6 +31,8 @@ import { OrgRevision } from "../entities/OrgRevision";
|
|||
export class ApiWebServiceController extends Controller {
|
||||
private apiNameRepository = AppDataSource.getRepository(ApiName);
|
||||
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
|
||||
private apiHistoryRepository = AppDataSource.getRepository(ApiHistory);
|
||||
|
||||
/**
|
||||
* list fields by systems
|
||||
* @summary รายการ fields ตาม systems
|
||||
|
|
@ -113,21 +116,59 @@ export class ApiWebServiceController extends Controller {
|
|||
});
|
||||
}
|
||||
|
||||
// เพิ่ม Main.id เพราะจะใช้ pk ในการแมบและนับจำนวน
|
||||
if (!propertyKey.includes(`${Main}.id`)) {
|
||||
propertyKey.push(`${Main}.id`);
|
||||
}
|
||||
// // เพิ่ม Main.id เพราะจะใช้ pk ในการแมบและนับจำนวน
|
||||
// if (!propertyKey.includes(`${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
|
||||
.select(propertyKey)
|
||||
.where(condition)
|
||||
// .orderBy(`${Main}.createdAt`, "DESC")
|
||||
.orderBy(propertyKey[0], "ASC")
|
||||
.skip(offset)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
// ลบ Main.id
|
||||
const results = items.map(({ id, ...x }) => x);
|
||||
return new HttpSuccess({ items: results, total });
|
||||
// const results = items.map(({ id, ...x }) => x);
|
||||
// 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