feat: add manual platform access sync

This commit is contained in:
2026-08-13 09:53:45 +09:00
parent 33c1affa32
commit 719edf8b08
3 changed files with 34 additions and 8 deletions
+5
View File
@@ -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')
deletePlatform(
@Req() request: Request,
+13 -1
View File
@@ -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(
organizationId: string | undefined,
organizationName: string,
throwOnError = false,
) {
const [platforms, groups] = await Promise.all([
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(