Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically add small and asynchronous classes to merge groups #164

Merged
merged 4 commits into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading