Skip to content

Commit

Permalink
review comment: type guard for user
Browse files Browse the repository at this point in the history
  • Loading branch information
casparneumann-cap committed Nov 20, 2023
1 parent 7977671 commit 3c92235
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ function isLibrariesContentType(object: any): object is LibrariesContentType {
return 'h5p_libraries' in object;
}

function isUserType(object: any): object is IUser {
return true;
}

@Injectable()
export class H5PLibraryManagementService {
contentTypeCache: ContentTypeCache;
Expand Down Expand Up @@ -98,9 +102,20 @@ export class H5PLibraryManagementService {
if (contentType === undefined) {
throw new NotFoundException('this library does not exist');
}
const user: IUser = { canUpdateAndInstallLibraries: true } as IUser;
await this.contentTypeRepo.installContentType(librariesToInstall[lastPositionLibrariesToInstallArray], user);
await this.installLibraries(librariesToInstall.slice(0, lastPositionLibrariesToInstallArray));
const userObj = {
canCreateRestricted: true,
canInstallRecommended: true,
canUpdateAndInstallLibraries: true,
email: '[email protected]',
id: 'a',
name: 'a',
type: 'local',
};
if (isUserType(userObj)) {
const user: IUser = userObj;
await this.contentTypeRepo.installContentType(librariesToInstall[lastPositionLibrariesToInstallArray], user);
await this.installLibraries(librariesToInstall.slice(0, lastPositionLibrariesToInstallArray));
}
}

public async run(): Promise<void> {
Expand Down

0 comments on commit 3c92235

Please sign in to comment.