Files
SWE/TeacherDashboard/js/subjects/SubjectModel.js
Kelvi Yawo Jules Agbessi Awuklu 5e192bf14f Update 13 files
- /TeacherDashboard/index.html
- /TeacherDashboard/TeacherDashboard.code-workspace
- /TeacherDashboard/components/resourceModal.html
- /TeacherDashboard/components/subjectModal.html
- /TeacherDashboard/components/topicModal.html
- /TeacherDashboard/js/main.js
- /TeacherDashboard/js/subjects/colors.js
- /TeacherDashboard/js/subjects/subjectManager.js
- /TeacherDashboard/js/subjects/SubjectModel.js
- /TeacherDashboard/js/subjects/SubjectStorage.js
- /TeacherDashboard/js/topics/TopicModel.js
- /TeacherDashboard/js/topics/topicManager.js
- /TeacherDashboard/styles/main.css
2024-12-13 13:43:58 +01:00

48 lines
1.5 KiB
JavaScript

export class SubjectModel {
constructor(data) {
this.id = data.id || crypto.randomUUID();
this.name = data.name;
this.description = data.description || '';
this.color = data.color;
this.icon = data.icon;
this.createdAt = data.createdAt || new Date().toISOString();
this.updatedAt = new Date().toISOString();
this.topics = data.topics || [];
this.resources = data.resources || [];
this.metadata = {
lastAccessed: new Date().toISOString(),
topicCount: 0,
resourceCount: 0
};
this.content = data.content || '';
this.materials = data.materials || [];
}
validate() {
const required = ['name', 'color', 'icon'];
const missing = required.filter(field => !this[field]);
if (missing.length > 0) {
throw new Error(`Missing required fields: ${missing.join(', ')}`);
}
return true;
}
toJSON() {
return {
id: this.id,
name: this.name,
description: this.description,
color: this.color,
icon: this.icon,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
topics: this.topics,
resources: this.resources,
metadata: this.metadata,
content: this.content,
materials: this.materials
};
}
}