Compare commits
2 Commits
33c1affa32
...
5c03032921
| Author | SHA1 | Date | |
|---|---|---|---|
| 5c03032921 | |||
| 719edf8b08 |
@@ -412,28 +412,32 @@ export class CurriculumService {
|
|||||||
});
|
});
|
||||||
environmentProfilesByPlatformKey.set(profile.platformKey, items);
|
environmentProfilesByPlatformKey.set(profile.platformKey, items);
|
||||||
});
|
});
|
||||||
const fixedPlatforms = course.platforms
|
const configuredLocalPlatform = course.platforms.find((coursePlatform) => (
|
||||||
.filter((coursePlatform) => {
|
this.isFixedPlatform(coursePlatform.platform)
|
||||||
return this.isFixedPlatform(coursePlatform.platform);
|
));
|
||||||
})
|
const localPlatform = configuredLocalPlatform?.platform ?? await this.prisma.platform.findFirst({
|
||||||
.map((coursePlatform) => {
|
where: {
|
||||||
const isLocal = this.isFixedPlatform(coursePlatform.platform);
|
platformKey: 'futuredrive-local-pc',
|
||||||
return {
|
isActive: true,
|
||||||
id: coursePlatform.platform.id,
|
},
|
||||||
platformKey: coursePlatform.platform.platformKey,
|
|
||||||
title: coursePlatform.platform.displayName,
|
|
||||||
description: coursePlatform.platform.description,
|
|
||||||
organizationName: coursePlatform.platform.organizationName,
|
|
||||||
iconKey: coursePlatform.platform.iconKey,
|
|
||||||
sourceSettings: coursePlatform.platform.defaultStudioSettings,
|
|
||||||
vehicleRuntimeProfile: this.toVehicleRuntimeProfile(coursePlatform.platform),
|
|
||||||
environmentProfiles: environmentProfilesByPlatformKey.get(coursePlatform.platform.platformKey) ?? [],
|
|
||||||
status: isLocal ? '사용 가능' : coursePlatform.status,
|
|
||||||
action: isLocal ? '연결' : coursePlatform.action,
|
|
||||||
state: coursePlatform.state,
|
|
||||||
local: isLocal,
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
const fixedPlatforms = localPlatform
|
||||||
|
? [{
|
||||||
|
id: localPlatform.id,
|
||||||
|
platformKey: localPlatform.platformKey,
|
||||||
|
title: localPlatform.displayName,
|
||||||
|
description: localPlatform.description,
|
||||||
|
organizationName: localPlatform.organizationName,
|
||||||
|
iconKey: localPlatform.iconKey,
|
||||||
|
sourceSettings: localPlatform.defaultStudioSettings,
|
||||||
|
vehicleRuntimeProfile: this.toVehicleRuntimeProfile(localPlatform),
|
||||||
|
environmentProfiles: environmentProfilesByPlatformKey.get(localPlatform.platformKey) ?? [],
|
||||||
|
status: '사용 가능',
|
||||||
|
action: '연결',
|
||||||
|
state: configuredLocalPlatform?.state ?? 'ready',
|
||||||
|
local: true,
|
||||||
|
}]
|
||||||
|
: [];
|
||||||
const controlStates = await this.platformControlService.getControlStates(
|
const controlStates = await this.platformControlService.getControlStates(
|
||||||
{ organizationId, organizationName },
|
{ organizationId, organizationName },
|
||||||
lmsUser?.id ?? null,
|
lmsUser?.id ?? null,
|
||||||
|
|||||||
@@ -218,6 +218,11 @@ export class InstructorController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post('platforms/access-sync')
|
||||||
|
syncPlatformAccess(@Req() request: Request) {
|
||||||
|
return this.instructorService.syncPlatformAccess(this.getBearerToken(request));
|
||||||
|
}
|
||||||
|
|
||||||
@Delete('platforms/:platformId')
|
@Delete('platforms/:platformId')
|
||||||
deletePlatform(
|
deletePlatform(
|
||||||
@Req() request: Request,
|
@Req() request: Request,
|
||||||
|
|||||||
@@ -2927,9 +2927,20 @@ export class InstructorService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async syncPlatformAccess(accessToken: string | undefined) {
|
||||||
|
const { authUser } = await this.getInstructor(accessToken);
|
||||||
|
const organizationId = authUser.primaryAffiliation?.organizationId;
|
||||||
|
const organizationName = authUser.primaryAffiliation?.organizationName?.trim();
|
||||||
|
if (!organizationName) throw new BadRequestException('Instructor organization is required');
|
||||||
|
|
||||||
|
const assignmentCount = await this.syncPlatformAccessPolicy(organizationId, organizationName, true);
|
||||||
|
return { ok: true, assignmentCount, syncedAt: new Date().toISOString() };
|
||||||
|
}
|
||||||
|
|
||||||
private async syncPlatformAccessPolicy(
|
private async syncPlatformAccessPolicy(
|
||||||
organizationId: string | undefined,
|
organizationId: string | undefined,
|
||||||
organizationName: string,
|
organizationName: string,
|
||||||
|
throwOnError = false,
|
||||||
) {
|
) {
|
||||||
const [platforms, groups] = await Promise.all([
|
const [platforms, groups] = await Promise.all([
|
||||||
this.prisma.instructorPlatform.findMany({
|
this.prisma.instructorPlatform.findMany({
|
||||||
@@ -2987,7 +2998,8 @@ export class InstructorService {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.platformGatewayClient.syncAccess(assignments);
|
await this.platformGatewayClient.syncAccess(assignments, { throwOnError });
|
||||||
|
return assignments.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async findInstructorGroup(
|
private async findInstructorGroup(
|
||||||
|
|||||||
@@ -178,14 +178,23 @@ export class PlatformGatewayClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async syncAccess(assignments: GatewayAccessAssignment[]): Promise<void> {
|
async syncAccess(assignments: GatewayAccessAssignment[], options: { throwOnError?: boolean } = {}): Promise<boolean> {
|
||||||
if (!this.enabled) return;
|
if (!this.enabled) {
|
||||||
|
if (options.throwOnError) throw new Error('Platform Gateway integration is not configured.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
await this.request('/api/lms/access-sync', {
|
await this.request('/api/lms/access-sync', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ assignments }),
|
body: JSON.stringify({ assignments }),
|
||||||
}).catch((error) => {
|
|
||||||
this.logger.warn(`Platform access sync failed. message=${error instanceof Error ? error.message : String(error)}`);
|
|
||||||
});
|
});
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
if (options.throwOnError) throw error;
|
||||||
|
this.logger.warn(`Platform access sync failed. message=${error instanceof Error ? error.message : String(error)}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async request<T = unknown>(path: string, init: RequestInit): Promise<T> {
|
private async request<T = unknown>(path: string, init: RequestInit): Promise<T> {
|
||||||
|
|||||||
Reference in New Issue
Block a user