fix(backend): Bugs omtrent leerpad-endpoints opgelost
This commit is contained in:
parent
6929288554
commit
1a768fedcc
6 changed files with 12 additions and 12 deletions
|
@ -12,7 +12,7 @@ export class LearningObjectRepository extends DwengoEntityRepository<LearningObj
|
||||||
version: identifier.version,
|
version: identifier.version,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
populate: ['keywords'],
|
populate: ['keywords', 'admins'],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,9 +35,7 @@ export class LearningPathRepository extends DwengoEntityRepository<LearningPath>
|
||||||
return this.findAll({
|
return this.findAll({
|
||||||
where: {
|
where: {
|
||||||
admins: {
|
admins: {
|
||||||
$contains: {
|
username: adminUsername
|
||||||
username: adminUsername
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import {
|
import {
|
||||||
ArrayType,
|
ArrayType,
|
||||||
|
Cascade,
|
||||||
Collection,
|
Collection,
|
||||||
Embedded,
|
Embedded,
|
||||||
Entity,
|
Entity,
|
||||||
|
@ -93,6 +94,7 @@ export class LearningObject {
|
||||||
@OneToMany({
|
@OneToMany({
|
||||||
entity: () => Attachment,
|
entity: () => Attachment,
|
||||||
mappedBy: 'learningObject',
|
mappedBy: 'learningObject',
|
||||||
|
cascade: [Cascade.ALL]
|
||||||
})
|
})
|
||||||
attachments: Collection<Attachment> = new Collection<Attachment>(this);
|
attachments: Collection<Attachment> = new Collection<Attachment>(this);
|
||||||
|
|
||||||
|
|
|
@ -12,5 +12,5 @@ export const onlyAdminsForLearningObject = authorize(async (auth: Authentication
|
||||||
language: language as Language,
|
language: language as Language,
|
||||||
version: parseInt(version as string)
|
version: parseInt(version as string)
|
||||||
});
|
});
|
||||||
return auth.username in admins;
|
return admins.includes(auth.username);
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,10 +3,10 @@ import { authorize } from "../auth";
|
||||||
import { AuthenticatedRequest } from "../authenticated-request";
|
import { AuthenticatedRequest } from "../authenticated-request";
|
||||||
import { AuthenticationInfo } from "../authentication-info";
|
import { AuthenticationInfo } from "../authentication-info";
|
||||||
|
|
||||||
export const onlyAdminsForLearningPath = authorize((auth: AuthenticationInfo, req: AuthenticatedRequest) => {
|
export const onlyAdminsForLearningPath = authorize(async (auth: AuthenticationInfo, req: AuthenticatedRequest) => {
|
||||||
const adminsForLearningPath = learningPathService.getAdmins({
|
const adminsForLearningPath = await learningPathService.getAdmins({
|
||||||
hruid: req.body.hruid,
|
hruid: req.body.hruid,
|
||||||
language: req.body.language
|
language: req.body.language
|
||||||
});
|
});
|
||||||
return adminsForLearningPath && auth.username in adminsForLearningPath;
|
return adminsForLearningPath && adminsForLearningPath.includes(auth.username);
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,7 +18,7 @@ export async function processLearningObjectZip(filePath: string): Promise<Learni
|
||||||
try {
|
try {
|
||||||
zip = await unzipper.Open.file(filePath);
|
zip = await unzipper.Open.file(filePath);
|
||||||
} catch(_: unknown) {
|
} catch(_: unknown) {
|
||||||
throw new BadRequestException("invalid_zip");
|
throw new BadRequestException("invalidZip");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ export async function processLearningObjectZip(filePath: string): Promise<Learni
|
||||||
let content: Buffer | undefined = undefined;
|
let content: Buffer | undefined = undefined;
|
||||||
|
|
||||||
if (zip.files.length === 0) {
|
if (zip.files.length === 0) {
|
||||||
throw new BadRequestException("empty_zip")
|
throw new BadRequestException("emptyZip")
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
|
@ -48,10 +48,10 @@ export async function processLearningObjectZip(filePath: string): Promise<Learni
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!metadata) {
|
if (!metadata) {
|
||||||
throw new BadRequestException("missing_metadata");
|
throw new BadRequestException("missingMetadata");
|
||||||
}
|
}
|
||||||
if (!content) {
|
if (!content) {
|
||||||
throw new BadRequestException("missing_index");
|
throw new BadRequestException("missingIndex");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue