api web service add join for show name

This commit is contained in:
Warunee Tamkoo 2026-05-21 13:44:03 +07:00
parent b071bc2d92
commit 44793fbfbb
3 changed files with 290 additions and 31 deletions

View file

@ -530,18 +530,20 @@ export class KeycloakAttributeService {
// Initialize rate limiter if rate limiting is enabled
if (rateLimit && rateLimit > 0) {
rateLimiter = new RateLimiter(rateLimit);
console.log(`[syncMissingEmpTypeByMonth] Rate limiting enabled: ${rateLimit} requests/second`);
console.log(
`[syncMissingEmpTypeByMonth] Rate limiting enabled: ${rateLimit} requests/second`,
);
}
// Select repository based on profile type
const repo =
profileType === "PROFILE" ? this.profileRepo : this.profileEmployeeRepo;
const repo = profileType === "PROFILE" ? this.profileRepo : this.profileEmployeeRepo;
// Query profiles updated within the month
const profiles = await repo
.createQueryBuilder("p")
.where("p.keycloak IS NOT NULL")
.andWhere("p.keycloak != :empty", { empty: "" })
.andWhere({ "p.isDeleted": false })
.andWhere("p.lastUpdatedAt BETWEEN :start AND :end", {
start: startDate,
end: endDate,
@ -579,8 +581,7 @@ export class KeycloakAttributeService {
try {
// Check if empType is empty in Keycloak
const { isEmpty, currentEmpType } =
await this.checkEmpTypeEmpty(keycloakUserId);
const { isEmpty, currentEmpType } = await this.checkEmpTypeEmpty(keycloakUserId);
result.profilesChecked++;
@ -607,8 +608,7 @@ export class KeycloakAttributeService {
// Sync the profile
const success = await withRetry(
async () =>
this.syncOnOrganizationChange(profile.id, profileType),
async () => this.syncOnOrganizationChange(profile.id, profileType),
3, // maxRetries
1000, // baseDelay
);
@ -768,7 +768,13 @@ export class KeycloakAttributeService {
maxRetries?: number; // Retry attempts for failed operations
rateLimit?: number; // Requests per second
clearProgress?: boolean; // Start fresh, ignore existing progress
}): Promise<{ total: number; success: number; failed: number; details: any[]; resumed?: boolean }> {
}): Promise<{
total: number;
success: number;
failed: number;
details: any[];
resumed?: boolean;
}> {
const limit = options?.limit;
const concurrency = options?.concurrency ?? 5;
const resume = options?.resume ?? false;
@ -922,7 +928,10 @@ export class KeycloakAttributeService {
// Save progress after each batch
SyncProgressManager.save(updatedState);
// Log progress every 50 items
if (updatedState.lastSyncedIndex % 50 === 0 || updatedState.lastSyncedIndex === updatedState.totalProfiles) {
if (
updatedState.lastSyncedIndex % 50 === 0 ||
updatedState.lastSyncedIndex === updatedState.totalProfiles
) {
SyncProgressManager.logProgress(updatedState);
}
},