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

128 refactor sessions to be session instances #135

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
23 changes: 22 additions & 1 deletion packages/api/src/models/study.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import type {
IStudy,
IStudyVariant,
ITaskInstance,
IOptionValue,
ICustomizedSession,
} from "@seitz/shared";

const taskInstanceSchema = new Schema<ITaskInstance>({
Expand All @@ -25,9 +27,11 @@ const sessionSchema = new Schema<ISession>({
tasks: [taskInstanceSchema],
});

export const Session = model<ISession>("Session", sessionSchema);

const variantSchema = new Schema<IStudyVariant>({
name: { type: String, default: "" },
sessions: [sessionSchema],
sessions: [{ type: Schema.Types.ObjectId, ref: "CustomizedSession" }],
serverCode: { type: String },
});

Expand Down Expand Up @@ -77,3 +81,20 @@ variantSchema.pre("save", async function (next) {
});

export const Study = model<IStudy, StudyModelType>("Study", studySchema);

// TODO: Tech Debt - is there a better typing for this?
const optionValueSchema = new Schema<IOptionValue>({
option: Schema.Types.ObjectId,
value: Schema.Types.Mixed,
});

export const customizedSessionSchema = new Schema<ICustomizedSession>({
battery: { type: Schema.Types.ObjectId, ref: "Session", required: true },
name: { type: String, required: true },
values: [optionValueSchema],
});

export const CustomizedSession = model<ICustomizedSession>(
"CustomizedSession",
customizedSessionSchema
);
19 changes: 19 additions & 0 deletions packages/shared/types/models/study.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,22 @@ export interface CreateStudy {
export interface IStudy extends Required<CreateStudy> {
variants: IStudyVariant[];
}

export interface CreateOptionValue {
_id?: Types.ObjectId;
option: Types.ObjectId;
value: unknown;
}

export type IOptionValue = Required<CreateOptionValue>;

export interface CreateCustomizedSession {
_id?: Types.ObjectId;
battery: Types.ObjectId;
name: string;
values: CreateOptionValue[];
}

export interface ICustomizedSession extends Required<CreateCustomizedSession> {
values: IOptionValue[];
}
Loading