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

Refactoring Admin Apis #201

Merged
merged 6 commits into from
Jul 19, 2024
Merged
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
73 changes: 73 additions & 0 deletions drizzle/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3447,4 +3447,77 @@ export const quizTrackingRelation = relations(
references: [zuvyModuleQuiz.id],
}),
})
);


export const zuvyModuleForm = main.table('zuvy_module_form', {
id: serial('id').primaryKey().notNull(),
chapterId: integer('chapter_id').references(() => zuvyModuleChapter.id).notNull(),
question: text('question'),
options: jsonb('options'),
typeId: integer('type_id').references(() => zuvyQuestionTypes.id),
isRequired: boolean('is_required').notNull(),
createdAt: timestamp("created_at", { withTimezone: true, mode: 'string' }),
updatedAt: timestamp("updated_at", { withTimezone: true, mode: 'string' }),
usage: integer('usage').default(0),
});

export const zuvyQuestionTypes = main.table('zuvy_question_type', {
id: serial('id').primaryKey().notNull(),
questionType: varchar('question_type'),
});

export const zuvyFormTracking = main.table("zuvy_form_tracking", {
id: serial("id").primaryKey().notNull(),
userId: integer("user_id").references(() => users.id),
moduleId: integer("module_id"),
questionId: integer("question_id"),
chapterId: integer("chapter_id"),
status: varchar("status", { length: 255 }),
// assessmentSubmissionId: integer("assessment_submission_id").references(() => zuvyAssessmentSubmission.id, {
// onDelete: 'cascade',
// onUpdate: 'cascade',
// }),
chosenOptions: text("chosen_options").array(),
answer: text("answer"),
createdAt: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true, mode: 'string' }).defaultNow(),
});

// export const zuvyFormTrackingRelations = relations(zuvyFormTracking, ({ one }) => ({

// formSubmissions: one(zuvyAssessmentSubmission, {
// fields: [zuvyFormTracking.assessmentSubmissionId],
// references: [zuvyAssessmentSubmission.id]
// })

// }))

// export const formChapterRelations = relations(
// zuvyCourseModules,
// ({many, one }) => ({
// moduleChapterData: many(zuvyModuleChapter),
// chapterTrackingData: many(zuvyChapterTracking),
// moduleTracking: many(zuvyModuleTracking),
// formTrackingData: many(zuvyFormTracking),
// moduleFormData: many (zuvyModuleForm)
// }),
// );

export const formModuleRelation= relations(
zuvyModuleForm,
({many})=>({
formTrackingData: many(zuvyFormTracking)
})

);

export const formTrackingRelation = relations(
zuvyFormTracking,
({ one }) => ({
formQuestion: one(zuvyModuleForm, {
fields: [zuvyFormTracking.questionId],
references: [zuvyModuleForm.id],
}),
})
);
101 changes: 100 additions & 1 deletion src/controller/content/content.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ import {
UpdateOpenEndedDto,
CreateTagDto,
projectDto,
CreateChapterDto
CreateChapterDto,
formBatchDto,
editFormBatchDto,
CreateTypeDto,
CreateAndEditFormBody
} from './dto/content.dto';
import { CreateProblemDto } from '../codingPlatform/dto/codingPlatform.dto';
import { difficulty } from 'drizzle/schema';
Expand Down Expand Up @@ -599,4 +603,99 @@ export class ContentController {
}
return this.contentService.getAssessmentDetailsOfOpenEnded(assessmentOutsourseId, userId);
}


@Post('/createQuestionType')
@ApiOperation({ summary: 'Create a Question Type for the form' })
@ApiBearerAuth()
async createQuestionType(@Body() questionType: CreateTypeDto) {
const res = await this.contentService.createQuestionType(questionType);
return res;
}

@Get('/allQuestionType')
@ApiOperation({ summary: 'Get all the available Question Types' })
@ApiBearerAuth()
async getAllQuestionTypes() {
const res = await this.contentService.getAllQuestionTypes();
return res;
}

@Post('/form')
@ApiOperation({ summary: 'Create a form' })
@ApiBearerAuth()
async createFormForModule (
@Query('chapterId') chapterId: number,
@Body() formQuestion: formBatchDto
){
const res = await this.contentService.createFormForModule(
chapterId,
formQuestion
);
return res;
}

@Get('/allFormQuestions/:chapterId')
@ApiOperation({ summary: 'Get all form Questions' })
@ApiQuery({
name: 'typeId',
required: false,
type: Number,
description: 'typeId',
})
@ApiQuery({
name: 'searchTerm',
required: false,
type: String,
description: 'Search by name or email',
})
@ApiBearerAuth()
async getAllFormQuestions(
@Param('chapterId') chapterId: number,
@Query('typeId') typeId: number,
@Query('searchTerm') searchTerm: string,
): Promise<object> {
const res = await this.contentService.getAllFormQuestions(
chapterId,
typeId,
searchTerm,
);
return res;
}

@Post('/editform')
@ApiOperation({ summary: 'Create a form' })
@ApiBearerAuth()
async editFormForModule(
@Query('chapterId') chapterId: number,
@Body() formQuestions: editFormBatchDto) {
const res = await this.contentService.editFormQuestions(
chapterId,
formQuestions
);
return res;
}


@Post('/createAndEditForm/:chapterId')
@ApiOperation({ summary: 'Create a form' })
@ApiBearerAuth()
async createAndEditForm(
@Param('chapterId') chapterId: number,
@Body() formQuestions: CreateAndEditFormBody) {
const res = await this.contentService.createAndEditFormQuestions(
chapterId,
formQuestions
);
return res;
}

// @Delete('/deleteFormQuestion')
// @ApiOperation({ summary: 'Delete form question' })
// @ApiBearerAuth()
// async deleteFormQuestion(@Body() questionIds: deleteQuestionDto) {
// const res = await this.contentService.deleteForm(questionIds);
// return res;
// }

}
Loading