Skip to content

Commit

Permalink
fix backend was writing at the same time to db ...
Browse files Browse the repository at this point in the history
  • Loading branch information
mono424 committed Sep 30, 2023
1 parent b057ced commit 2e81910
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions web/ts/api/admin-lecture-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,26 +236,26 @@ export const AdminLectureList = {
* @param request
*/
updateMetadata: async function (courseId: number, lectureId: number, request: UpdateLectureMetaRequest) {
const promises = [];
const promises: (() => Promise<Response>)[] = [];
if (request.name !== undefined) {
promises.push(
post(`/api/course/${courseId}/renameLecture/${lectureId}`, {
() => post(`/api/course/${courseId}/renameLecture/${lectureId}`, {
name: request.name,
}),
);
}

if (request.description !== undefined) {
promises.push(
put(`/api/course/${courseId}/updateDescription/${lectureId}`, {
() => put(`/api/course/${courseId}/updateDescription/${lectureId}`, {
name: request.description,
}),
);
}

if (request.lectureHallId !== undefined) {
promises.push(
post("/api/setLectureHall", {
() => post("/api/setLectureHall", {
streamIds: [lectureId],
lectureHall: request.lectureHallId,
}),
Expand All @@ -264,15 +264,22 @@ export const AdminLectureList = {

if (request.isChatEnabled !== undefined) {
promises.push(
patch(`/api/stream/${lectureId}/chat/enabled`, {
() => patch(`/api/stream/${lectureId}/chat/enabled`, {
lectureId,
isChatEnabled: request.isChatEnabled,
}),
);
}

const errors = (await Promise.all(promises)).filter((res) => res.status !== StatusCodes.OK);
if (errors.length > 0) {
let errors = 0;
for (const promise of promises) {
const res = await promise();
if (res.status !== StatusCodes.OK) {
errors++;
}
}

if (errors > 0) {
console.error(errors);
throw Error("Failed to update all data.");
}
Expand Down

0 comments on commit 2e81910

Please sign in to comment.