Skip to content

Commit c2a3d69

Browse files
committed
remove remaining forks, fix delete tutorial
1 parent 706b0fe commit c2a3d69

2 files changed

Lines changed: 5 additions & 17 deletions

File tree

server/src/module/tutorial/tutorial.service.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,10 @@ export class TutorialService implements CRUDService<ITutorial, TutorialDTO, Tuto
167167
throw new BadRequestException(`A tutorial with students can NOT be deleted.`);
168168
}
169169

170-
const em = this.entityManager.fork({ clear: false });
171-
await em.begin();
172-
try {
173-
tutorial.teams.getItems().map((team) => em.remove(team));
174-
em.remove(tutorial);
175-
await em.commit();
176-
} catch (e) {
177-
await em.rollback();
178-
throw new BadRequestException(e);
179-
}
170+
this.entityManager.remove(tutorial.teams.getItems());
171+
this.entityManager.remove(tutorial.substitutes.getItems())
172+
173+
await this.repository.removeAndFlush(tutorial);
180174
}
181175

182176
/**

server/src/module/user/user.service.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ export class UserService implements OnApplicationBootstrap, CRUDService<IUser, U
123123
* @returns Created users.
124124
*/
125125
async createMany(users: CreateUserDTO[]): Promise<IUser[]> {
126-
const em = this.entityManager.fork({ clear: false });
127-
await em.begin();
128126
const errors: string[] = [];
129127
const toCreate: User[] = [];
130128

@@ -139,12 +137,8 @@ export class UserService implements OnApplicationBootstrap, CRUDService<IUser, U
139137
}
140138

141139
if (errors.length === 0) {
142-
toCreate.forEach((user) => {
143-
em.persist(user);
144-
});
145-
await em.commit();
140+
await this.repository.persistAndFlush(toCreate)
146141
} else {
147-
await em.rollback();
148142
throw new BadRequestException(errors);
149143
}
150144

0 commit comments

Comments
 (0)