Files
samreshu_backend/src/db/schema/testQuestions.ts
2026-03-04 13:38:19 +03:00

26 lines
1.2 KiB
TypeScript

import { pgTable, uuid, text, integer, boolean, timestamp } from 'drizzle-orm/pg-core';
import { jsonb } from 'drizzle-orm/pg-core';
import { questionTypeEnum } from './enums.js';
import { tests } from './tests.js';
import { questionBank } from './questionBank.js';
export const testQuestions = pgTable('test_questions', {
id: uuid('id').primaryKey().defaultRandom(),
testId: uuid('test_id')
.notNull()
.references(() => tests.id, { onDelete: 'cascade' }),
questionBankId: uuid('question_bank_id').references(() => questionBank.id, { onDelete: 'set null' }),
orderNumber: integer('order_number').notNull(),
type: questionTypeEnum('type').notNull(),
questionText: text('question_text').notNull(),
options: jsonb('options').$type<Array<{ key: string; text: string }>>(),
correctAnswer: jsonb('correct_answer').$type<string | string[]>().notNull(),
explanation: text('explanation').notNull(),
userAnswer: jsonb('user_answer').$type<string | string[]>(),
isCorrect: boolean('is_correct'),
answeredAt: timestamp('answered_at', { withTimezone: true }),
});
export type TestQuestion = typeof testQuestions.$inferSelect;
export type NewTestQuestion = typeof testQuestions.$inferInsert;