fix(backend): nodeNumber handmatig invullen
Om MikroORM bug die optreedt bij het persisteren van een kind van een entity met automatisch gegenereerde PK te vermijden.
This commit is contained in:
parent
ffa0915647
commit
a803b45046
5 changed files with 28 additions and 11 deletions
|
@ -5,12 +5,12 @@ import { Language } from '@dwengo-1/common/util/language';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class LearningPathNode {
|
export class LearningPathNode {
|
||||||
@ManyToOne({ entity: () => LearningPath, primary: true })
|
|
||||||
learningPath!: Rel<LearningPath>;
|
|
||||||
|
|
||||||
@PrimaryKey({ type: 'integer', autoincrement: true })
|
@PrimaryKey({ type: 'integer', autoincrement: true })
|
||||||
nodeNumber?: number;
|
nodeNumber?: number;
|
||||||
|
|
||||||
|
@ManyToOne({ entity: () => LearningPath, primary: true })
|
||||||
|
learningPath!: Rel<LearningPath>;
|
||||||
|
|
||||||
@Property({ type: 'string' })
|
@Property({ type: 'string' })
|
||||||
learningObjectHruid!: string;
|
learningObjectHruid!: string;
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ export class LearningPathNode {
|
||||||
startNode!: boolean;
|
startNode!: boolean;
|
||||||
|
|
||||||
@OneToMany({ entity: () => LearningPathTransition, mappedBy: 'node' })
|
@OneToMany({ entity: () => LearningPathTransition, mappedBy: 'node' })
|
||||||
transitions: Collection<LearningPathTransition> = new Collection<LearningPathTransition>(this);
|
transitions!: Collection<LearningPathTransition>;
|
||||||
|
|
||||||
@Property({ length: 3 })
|
@Property({ length: 3 })
|
||||||
createdAt: Date = new Date();
|
createdAt: Date = new Date();
|
||||||
|
|
|
@ -3,12 +3,12 @@ import { LearningPathNode } from './learning-path-node.entity.js';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class LearningPathTransition {
|
export class LearningPathTransition {
|
||||||
@ManyToOne({ entity: () => LearningPathNode, primary: true })
|
|
||||||
node!: Rel<LearningPathNode>;
|
|
||||||
|
|
||||||
@PrimaryKey({ type: 'numeric' })
|
@PrimaryKey({ type: 'numeric' })
|
||||||
transitionNumber!: number;
|
transitionNumber!: number;
|
||||||
|
|
||||||
|
@ManyToOne({ entity: () => LearningPathNode, primary: true })
|
||||||
|
node!: Rel<LearningPathNode>;
|
||||||
|
|
||||||
@Property({ type: 'string' })
|
@Property({ type: 'string' })
|
||||||
condition!: string;
|
condition!: string;
|
||||||
|
|
||||||
|
|
|
@ -29,10 +29,11 @@ export function mapToLearningPath(
|
||||||
admins,
|
admins,
|
||||||
image: dto.image ? Buffer.from(base64ToArrayBuffer(dto.image)) : null
|
image: dto.image ? Buffer.from(base64ToArrayBuffer(dto.image)) : null
|
||||||
});
|
});
|
||||||
const nodes = dto.nodes.map((nodeDto: LearningObjectNode) =>
|
const nodes = dto.nodes.map((nodeDto: LearningObjectNode, i: number) =>
|
||||||
repo.createNode({
|
repo.createNode({
|
||||||
learningPath: path,
|
learningPath: path,
|
||||||
learningObjectHruid: nodeDto.learningobject_hruid,
|
learningObjectHruid: nodeDto.learningobject_hruid,
|
||||||
|
nodeNumber: i,
|
||||||
language: nodeDto.language,
|
language: nodeDto.language,
|
||||||
version: nodeDto.version,
|
version: nodeDto.version,
|
||||||
startNode: nodeDto.start_node ?? false,
|
startNode: nodeDto.start_node ?? false,
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
|
import {fileURLToPath} from "node:url";
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the asset at the given path.
|
* Load the asset at the given path.
|
||||||
|
|
|
@ -49,12 +49,24 @@ export async function seedDatabase(): Promise<void> {
|
||||||
const answers = makeTestAnswers(em, teachers, questions);
|
const answers = makeTestAnswers(em, teachers, questions);
|
||||||
const submissions = makeTestSubmissions(em, students, groups);
|
const submissions = makeTestSubmissions(em, students, groups);
|
||||||
|
|
||||||
|
|
||||||
// Persist all entities
|
// Persist all entities
|
||||||
await em.persistAndFlush([
|
/*await em.persistAndFlush([
|
||||||
...students,
|
...students,
|
||||||
...teachers,
|
...teachers,
|
||||||
...learningObjects,
|
...learningObjects,
|
||||||
...learningPaths,
|
]);*/
|
||||||
|
|
||||||
|
try {
|
||||||
|
await em.persistAndFlush(learningPaths[0]);
|
||||||
|
} catch (e) {
|
||||||
|
"hey";
|
||||||
|
}
|
||||||
|
/*await em.persistAndFlush(learningPaths[1]);
|
||||||
|
await em.persistAndFlush(learningPaths[2]);
|
||||||
|
await em.persistAndFlush(learningPaths[3]);
|
||||||
|
|
||||||
|
await em.persistAndFlush([
|
||||||
...classes,
|
...classes,
|
||||||
...assignments,
|
...assignments,
|
||||||
...groups,
|
...groups,
|
||||||
|
@ -64,7 +76,7 @@ export async function seedDatabase(): Promise<void> {
|
||||||
...questions,
|
...questions,
|
||||||
...answers,
|
...answers,
|
||||||
...submissions,
|
...submissions,
|
||||||
]);
|
])*/
|
||||||
|
|
||||||
logger.info('Development database seeded successfully!');
|
logger.info('Development database seeded successfully!');
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue