Skip to content

Commit

Permalink
Merge pull request #164 from Carifio24/merge-on-create
Browse files Browse the repository at this point in the history
Automatically add small and asynchronous classes to merge groups
  • Loading branch information
Carifio24 authored Dec 3, 2024
2 parents 76132eb + b9f8062 commit 19dbc31
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { StudentOption, StudentOptions } from "./models/student_options";
import { Question } from "./models/question";
import { logger } from "./logger";
import { Stage } from "./models/stage";
import { addClassToMergeGroup } from "./stories/hubbles_law/database";

export type LoginResponse = {
type: "none" | "student" | "educator" | "admin",
Expand Down Expand Up @@ -329,23 +330,34 @@ export async function createClass(options: CreateClassOptions): Promise<CreateCl
}

try {
const transactionResult = await db.transaction(async transaction => {
const cls = await db.transaction(async transaction => {

const cls = await Class.create(creationInfo, { transaction });

// For the pilot, the Hubble Data Story will be the only option,
// so we'll automatically associate that with the class
// TODO: When there are more classes available, we need to make
// this functionality more generic
if (cls) {
await ClassStories.create({
story_name: "hubbles_law",
class_id: cls.id
}, { transaction });

}

return creationInfo;
return cls;
});

return { result: result, class: transactionResult };
// Another piece of Hubble-specific functionality
// Note that we need to reload the class so that the virtual `small_class`
// column has its value populated
await cls.reload();
if (cls.asynchronous || cls.small_class) {
await addClassToMergeGroup(cls.id);
}

return { result: result, class: creationInfo };
} catch (error) {
result = (error instanceof BaseError) ? createClassResultFromError(error) : CreateClassResult.Error;
console.log(error);
Expand Down

0 comments on commit 19dbc31

Please sign in to comment.