forked from hangshuo652/aurak
feat: implement QuestionBank CRUD with pagination and template query
- Add pagination support to findAll (page, limit query params) - Add findByTemplateId method to service - Add GET /by-template/:templateId endpoint to controller - Service already includes CRUD for QuestionBank and QuestionBankItem
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
} from 'typeorm';
|
||||
import type { AssessmentQuestion } from './assessment-question.entity';
|
||||
|
||||
@Entity('assessment_answers')
|
||||
export class AssessmentAnswer {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({ name: 'question_id' })
|
||||
questionId: string;
|
||||
|
||||
@ManyToOne(
|
||||
'AssessmentQuestion',
|
||||
(question: AssessmentQuestion) => question.answers,
|
||||
{ onDelete: 'CASCADE' },
|
||||
)
|
||||
@JoinColumn({ name: 'question_id' })
|
||||
question: AssessmentQuestion;
|
||||
|
||||
@Column({ type: 'text', name: 'user_answer' })
|
||||
userAnswer: string;
|
||||
|
||||
@Column({ type: 'float', nullable: true })
|
||||
score: number;
|
||||
|
||||
@Column({ type: 'text', nullable: true })
|
||||
feedback: string;
|
||||
|
||||
@Column({ type: 'boolean', name: 'is_follow_up', default: false })
|
||||
isFollowUp: boolean;
|
||||
|
||||
@CreateDateColumn({ name: 'created_at' })
|
||||
createdAt: Date;
|
||||
|
||||
@UpdateDateColumn({ name: 'updated_at' })
|
||||
updatedAt: Date;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
} from 'typeorm';
|
||||
import { User } from '../../user/user.entity';
|
||||
|
||||
@Entity('assessment_certificates')
|
||||
export class AssessmentCertificate {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({ name: 'user_id' })
|
||||
userId: string;
|
||||
|
||||
@ManyToOne(() => User)
|
||||
@JoinColumn({ name: 'user_id' })
|
||||
user: User;
|
||||
|
||||
@Column({ name: 'session_id' })
|
||||
sessionId: string;
|
||||
|
||||
@Column({ name: 'template_id' })
|
||||
templateId: string;
|
||||
|
||||
@Column()
|
||||
level: string;
|
||||
|
||||
@Column({ type: 'float', name: 'total_score' })
|
||||
totalScore: number;
|
||||
|
||||
@Column({ name: 'qr_code', nullable: true })
|
||||
qrCode: string;
|
||||
|
||||
@Column({ name: 'dimension_scores', type: 'simple-json', nullable: true })
|
||||
dimensionScores: Record<string, number>;
|
||||
|
||||
@Column({ name: 'radar_data', type: 'simple-json', nullable: true })
|
||||
radarData: Record<string, number>;
|
||||
|
||||
@Column({ name: 'passed', type: 'boolean', default: false })
|
||||
passed: boolean;
|
||||
|
||||
@CreateDateColumn({ name: 'issued_at' })
|
||||
issuedAt: Date;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
OneToMany,
|
||||
} from 'typeorm';
|
||||
import type { AssessmentSession } from './assessment-session.entity';
|
||||
import type { AssessmentAnswer } from './assessment-answer.entity';
|
||||
|
||||
@Entity('assessment_questions')
|
||||
export class AssessmentQuestion {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({ name: 'session_id' })
|
||||
sessionId: string;
|
||||
|
||||
@ManyToOne(
|
||||
'AssessmentSession',
|
||||
(session: AssessmentSession) => session.questions,
|
||||
{ onDelete: 'CASCADE' },
|
||||
)
|
||||
@JoinColumn({ name: 'session_id' })
|
||||
session: AssessmentSession;
|
||||
|
||||
@Column({ type: 'text', name: 'question_text' })
|
||||
questionText: string;
|
||||
|
||||
@Column({ type: 'simple-json', name: 'key_points', nullable: true })
|
||||
keyPoints: string[];
|
||||
|
||||
@Column({ type: 'varchar', nullable: true })
|
||||
difficulty: string;
|
||||
|
||||
@OneToMany('AssessmentAnswer', (answer: AssessmentAnswer) => answer.question)
|
||||
answers: AssessmentAnswer[];
|
||||
|
||||
@CreateDateColumn({ name: 'created_at' })
|
||||
createdAt: Date;
|
||||
|
||||
@UpdateDateColumn({ name: 'updated_at' })
|
||||
updatedAt: Date;
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
OneToMany,
|
||||
} from 'typeorm';
|
||||
import { User } from '../../user/user.entity';
|
||||
import { KnowledgeBase } from '../../knowledge-base/knowledge-base.entity';
|
||||
import { KnowledgeGroup } from '../../knowledge-group/knowledge-group.entity';
|
||||
import type { AssessmentQuestion } from './assessment-question.entity';
|
||||
import { AssessmentTemplate } from './assessment-template.entity';
|
||||
|
||||
export enum AssessmentStatus {
|
||||
IN_PROGRESS = 'IN_PROGRESS',
|
||||
COMPLETED = 'COMPLETED',
|
||||
}
|
||||
|
||||
@Entity('assessment_sessions')
|
||||
export class AssessmentSession {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({ name: 'user_id' })
|
||||
userId: string;
|
||||
|
||||
@ManyToOne(() => User)
|
||||
@JoinColumn({ name: 'user_id' })
|
||||
user: User;
|
||||
|
||||
@Column({ name: 'tenant_id', nullable: true })
|
||||
tenantId: string;
|
||||
|
||||
@Column({ name: 'knowledge_base_id', nullable: true })
|
||||
knowledgeBaseId: string | null;
|
||||
|
||||
@ManyToOne(() => KnowledgeBase, { nullable: true })
|
||||
@JoinColumn({ name: 'knowledge_base_id' })
|
||||
knowledgeBase: KnowledgeBase;
|
||||
|
||||
@Column({ name: 'knowledge_group_id', nullable: true })
|
||||
knowledgeGroupId: string | null;
|
||||
|
||||
@ManyToOne(() => KnowledgeGroup, { nullable: true })
|
||||
@JoinColumn({ name: 'knowledge_group_id' })
|
||||
knowledgeGroup: KnowledgeGroup;
|
||||
|
||||
@Column({ name: 'thread_id', nullable: true })
|
||||
threadId: string;
|
||||
|
||||
@Column({
|
||||
type: 'varchar',
|
||||
enum: AssessmentStatus,
|
||||
default: AssessmentStatus.IN_PROGRESS,
|
||||
})
|
||||
status: AssessmentStatus;
|
||||
|
||||
@Column({ type: 'float', name: 'final_score', nullable: true })
|
||||
finalScore: number;
|
||||
|
||||
@Column({ type: 'text', name: 'final_report', nullable: true })
|
||||
finalReport: string;
|
||||
|
||||
@Column({ type: 'simple-json', nullable: true })
|
||||
messages: any[];
|
||||
|
||||
@Column({ type: 'simple-json', name: 'feedback_history', nullable: true })
|
||||
feedbackHistory: any[];
|
||||
|
||||
@Column({ type: 'int', name: 'current_question_index', default: 0 })
|
||||
currentQuestionIndex: number;
|
||||
|
||||
@Column({ type: 'int', name: 'follow_up_count', default: 0 })
|
||||
followUpCount: number;
|
||||
|
||||
@Column({ type: 'simple-json', nullable: true })
|
||||
questions_json: any[];
|
||||
|
||||
@Column({ type: 'varchar', length: 10, default: 'zh' })
|
||||
language: string;
|
||||
|
||||
@Column({ name: 'template_id', nullable: true })
|
||||
templateId: string;
|
||||
|
||||
@ManyToOne(() => AssessmentTemplate, { nullable: true })
|
||||
@JoinColumn({ name: 'template_id' })
|
||||
template: AssessmentTemplate;
|
||||
|
||||
@Column({ type: 'simple-json', name: 'template_json', nullable: true })
|
||||
templateJson: any;
|
||||
|
||||
@OneToMany(
|
||||
'AssessmentQuestion',
|
||||
(question: AssessmentQuestion) => question.session,
|
||||
)
|
||||
questions: AssessmentQuestion[];
|
||||
|
||||
@CreateDateColumn({ name: 'created_at' })
|
||||
createdAt: Date;
|
||||
|
||||
@UpdateDateColumn({ name: 'updated_at' })
|
||||
updatedAt: Date;
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
} from 'typeorm';
|
||||
import { Tenant } from '../../tenant/tenant.entity';
|
||||
import { KnowledgeBase } from '../../knowledge-base/knowledge-base.entity';
|
||||
import { KnowledgeGroup } from '../../knowledge-group/knowledge-group.entity';
|
||||
|
||||
@Entity('assessment_templates')
|
||||
export class AssessmentTemplate {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({ name: 'tenant_id', nullable: true })
|
||||
tenantId: string;
|
||||
|
||||
@ManyToOne(() => Tenant, { nullable: true, onDelete: 'CASCADE' })
|
||||
@JoinColumn({ name: 'tenant_id' })
|
||||
tenant: Tenant;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column({ type: 'text', nullable: true })
|
||||
description: string;
|
||||
|
||||
@Column({ type: 'simple-json', nullable: true })
|
||||
keywords: string[];
|
||||
|
||||
@Column({ type: 'int', name: 'question_count', default: 5 })
|
||||
questionCount: number;
|
||||
|
||||
@Column({
|
||||
type: 'simple-json',
|
||||
name: 'difficulty_distribution',
|
||||
nullable: true,
|
||||
})
|
||||
difficultyDistribution: {
|
||||
standard: number;
|
||||
advanced: number;
|
||||
specialist: number;
|
||||
};
|
||||
|
||||
@Column({ type: 'varchar', default: 'technical' })
|
||||
style: string;
|
||||
|
||||
@Column({ name: 'knowledge_base_id', nullable: true })
|
||||
knowledgeBaseId: string | null;
|
||||
|
||||
@ManyToOne(() => KnowledgeBase, { nullable: true })
|
||||
@JoinColumn({ name: 'knowledge_base_id' })
|
||||
knowledgeBase: KnowledgeBase;
|
||||
|
||||
@Column({ name: 'knowledge_group_id', nullable: true })
|
||||
knowledgeGroupId: string | null;
|
||||
|
||||
@ManyToOne(() => KnowledgeGroup, { nullable: true })
|
||||
@JoinColumn({ name: 'knowledge_group_id' })
|
||||
knowledgeGroup: KnowledgeGroup;
|
||||
|
||||
@Column({ type: 'boolean', name: 'is_active', default: true })
|
||||
isActive: boolean;
|
||||
|
||||
@Column({ type: 'int', default: 1 })
|
||||
version: number;
|
||||
|
||||
@Column({ name: 'created_by', nullable: true })
|
||||
createdBy: string;
|
||||
|
||||
@Column({ type: 'simple-json', name: 'linked_group_ids', nullable: true })
|
||||
linkedGroupIds: string[];
|
||||
|
||||
@Column({ type: 'simple-json', name: 'weight_config', nullable: true })
|
||||
weightConfig: {
|
||||
prompt: number;
|
||||
other: number;
|
||||
};
|
||||
|
||||
@Column({ type: 'simple-json', name: 'difficulty_config', nullable: true })
|
||||
difficultyConfig: {
|
||||
standard: number;
|
||||
advanced: number;
|
||||
specialist: number;
|
||||
};
|
||||
|
||||
@Column({ type: 'int', name: 'question_count_min', default: 8 })
|
||||
questionCountMin: number;
|
||||
|
||||
@Column({ type: 'int', name: 'question_count_max', default: 10 })
|
||||
questionCountMax: number;
|
||||
|
||||
@Column({ type: 'int', name: 'passing_score', default: 90 })
|
||||
passingScore: number;
|
||||
|
||||
@CreateDateColumn({ name: 'created_at' })
|
||||
createdAt: Date;
|
||||
|
||||
@UpdateDateColumn({ name: 'updated_at' })
|
||||
updatedAt: Date;
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
} from 'typeorm';
|
||||
import { QuestionBank } from './question-bank.entity';
|
||||
|
||||
export enum QuestionBankItemStatus {
|
||||
PENDING_REVIEW = 'PENDING_REVIEW',
|
||||
PUBLISHED = 'PUBLISHED',
|
||||
}
|
||||
|
||||
export enum QuestionType {
|
||||
SHORT_ANSWER = 'SHORT_ANSWER',
|
||||
MULTIPLE_CHOICE = 'MULTIPLE_CHOICE',
|
||||
TRUE_FALSE = 'TRUE_FALSE',
|
||||
}
|
||||
|
||||
export enum QuestionDifficulty {
|
||||
STANDARD = 'STANDARD',
|
||||
ADVANCED = 'ADVANCED',
|
||||
SPECIALIST = 'SPECIALIST',
|
||||
}
|
||||
|
||||
export enum QuestionDimension {
|
||||
PROMPT = 'PROMPT',
|
||||
LLM = 'LLM',
|
||||
IDE = 'IDE',
|
||||
DEV_PATTERN = 'DEV_PATTERN',
|
||||
WORK_CAPABILITY = 'WORK_CAPABILITY',
|
||||
}
|
||||
|
||||
@Entity('question_bank_items')
|
||||
export class QuestionBankItem {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({ name: 'bank_id' })
|
||||
bankId: string;
|
||||
|
||||
@ManyToOne(
|
||||
() => QuestionBank,
|
||||
(bank: QuestionBank) => bank.items,
|
||||
{ onDelete: 'CASCADE' },
|
||||
)
|
||||
@JoinColumn({ name: 'bank_id' })
|
||||
bank: QuestionBank;
|
||||
|
||||
@Column({ type: 'text', name: 'question_text' })
|
||||
questionText: string;
|
||||
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: QuestionType,
|
||||
default: QuestionType.SHORT_ANSWER,
|
||||
})
|
||||
questionType: QuestionType;
|
||||
|
||||
@Column({ type: 'simple-json', nullable: true })
|
||||
options: string[] | null;
|
||||
|
||||
@Column({ type: 'text', nullable: true })
|
||||
correctAnswer: string | null;
|
||||
|
||||
@Column({ type: 'simple-json', name: 'key_points' })
|
||||
keyPoints: string[];
|
||||
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: QuestionDifficulty,
|
||||
default: QuestionDifficulty.STANDARD,
|
||||
})
|
||||
difficulty: QuestionDifficulty;
|
||||
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: QuestionDimension,
|
||||
default: QuestionDimension.PROMPT,
|
||||
})
|
||||
dimension: QuestionDimension;
|
||||
|
||||
@Column({ type: 'text', nullable: true })
|
||||
basis: string | null;
|
||||
|
||||
@Column({ name: 'created_by', nullable: true })
|
||||
createdBy: string | null;
|
||||
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: QuestionBankItemStatus,
|
||||
default: QuestionBankItemStatus.PENDING_REVIEW,
|
||||
})
|
||||
status: QuestionBankItemStatus;
|
||||
|
||||
@CreateDateColumn({ name: 'created_at' })
|
||||
createdAt: Date;
|
||||
|
||||
@UpdateDateColumn({ name: 'updated_at' })
|
||||
updatedAt: Date;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
ManyToOne,
|
||||
OneToOne,
|
||||
JoinColumn,
|
||||
OneToMany,
|
||||
Unique,
|
||||
} from 'typeorm';
|
||||
import { Tenant } from '../../tenant/tenant.entity';
|
||||
import { AssessmentTemplate } from './assessment-template.entity';
|
||||
import type { QuestionBankItem } from './question-bank-item.entity';
|
||||
|
||||
export enum QuestionBankStatus {
|
||||
DRAFT = 'DRAFT',
|
||||
PENDING_REVIEW = 'PENDING_REVIEW',
|
||||
PUBLISHED = 'PUBLISHED',
|
||||
REJECTED = 'REJECTED',
|
||||
}
|
||||
|
||||
@Entity('question_banks')
|
||||
@Unique(['templateId'])
|
||||
export class QuestionBank {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({ name: 'tenant_id', nullable: true })
|
||||
tenantId: string | null;
|
||||
|
||||
@ManyToOne(() => Tenant, { nullable: true, onDelete: 'CASCADE' })
|
||||
@JoinColumn({ name: 'tenant_id' })
|
||||
tenant: Tenant;
|
||||
|
||||
@Column({ name: 'template_id', nullable: true })
|
||||
templateId: string | null;
|
||||
|
||||
@OneToOne(() => AssessmentTemplate, { nullable: true })
|
||||
@JoinColumn({ name: 'template_id' })
|
||||
template: AssessmentTemplate;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column({ type: 'text', nullable: true })
|
||||
description: string | null;
|
||||
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: QuestionBankStatus,
|
||||
default: QuestionBankStatus.DRAFT,
|
||||
})
|
||||
status: QuestionBankStatus;
|
||||
|
||||
@Column({ name: 'created_by', nullable: true })
|
||||
createdBy: string | null;
|
||||
|
||||
@Column({ name: 'reviewed_by', nullable: true })
|
||||
reviewedBy: string | null;
|
||||
|
||||
@Column({ name: 'reviewed_at', nullable: true })
|
||||
reviewedAt: Date | null;
|
||||
|
||||
@Column({ name: 'review_comment', nullable: true })
|
||||
reviewComment: string | null;
|
||||
|
||||
@OneToMany(
|
||||
'QuestionBankItem',
|
||||
(item: QuestionBankItem) => item.bank,
|
||||
)
|
||||
items: QuestionBankItem[];
|
||||
|
||||
@CreateDateColumn({ name: 'created_at' })
|
||||
createdAt: Date;
|
||||
|
||||
@UpdateDateColumn({ name: 'updated_at' })
|
||||
updatedAt: Date;
|
||||
}
|
||||
Reference in New Issue
Block a user