add api find dna by keycloak
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m0s

This commit is contained in:
Adisak 2026-02-05 11:23:38 +07:00
parent dbc46e2fb9
commit 39a07482cd

View file

@ -280,6 +280,75 @@ export class OrganizationController extends Controller {
return new HttpSuccess(requestBody); return new HttpSuccess(requestBody);
} }
/**
* API
*
* @summary ORG_022 - #23
*
*/
@Post("finddna-by-keycloak/{keycloakId}")
async FindDnaOrgByKeycloakId(
@Path() keycloakId: string
) {
let reply: any;
const profileByKeycloak: any = await this.profileRepo.findOne({
where: { keycloak: keycloakId },
select: ["id", "keycloak"]
})
const orgRevision = await this.orgRevisionRepository.findOne({
select: ["id"],
where: {
orgRevisionIsDraft: false,
orgRevisionIsCurrent: true,
},
});
const posMaster = await AppDataSource.getRepository(PosMaster)
.createQueryBuilder("pos")
.leftJoin("pos.orgRoot", "orgRoot")
.leftJoin("pos.orgChild1", "orgChild1")
.leftJoin("pos.orgChild2", "orgChild2")
.leftJoin("pos.orgChild3", "orgChild3")
.leftJoin("pos.orgChild4", "orgChild4")
.where("pos.current_holderId = :holderId", {
holderId: profileByKeycloak.id,
})
.andWhere("pos.orgRevisionId = :revId", {
revId: orgRevision?.id,
})
.select([
"pos.id",
"orgRoot.ancestorDNA as rootDnaId",
"orgChild1.ancestorDNA as child1DnaId",
"orgChild2.ancestorDNA as child2DnaId",
"orgChild3.ancestorDNA as child3DnaId",
"orgChild4.ancestorDNA as child4DnaId",
])
.getRawOne();
if (!posMaster) {
reply = {
rootDnaId: null,
child1DnaId: null,
child2DnaId: null,
child3DnaId: null,
child4DnaId: null,
};
} else {
reply = {
rootDnaId: posMaster.rootDnaId,
child1DnaId: posMaster.child1DnaId,
child2DnaId: posMaster.child2DnaId,
child3DnaId: posMaster.child3DnaId,
child4DnaId: posMaster.child4DnaId,
};
}
return new HttpSuccess(reply);
}
/** /**
* API * API
* *