Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can create the Session model using the existing sessionSchema on line 23 (see below)

const sessionSchema = new Schema({
name: { type: String, required: true },
tasks: [taskInstanceSchema],
});

export const CustomizedSession = model(
"CustomizedSession",
sessionSchema
);

);
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[];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can get rid of these because creating sessions will remain the same as before, it uses CreateSession/ISession from lines 10-18. We will need to add CreateSessionInstance/ISessionInstance interfaces like how CreateTaskInstance/ITaskInstance is done. CreateSessionInstance will have an optional id and the ObjectId of the session it points to.

Loading