schedule-kernel
Version:
The back-end core module used for storing/displaying the course schedule
64 lines • 1.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SubjectManager = void 0;
class SubjectManager {
constructor(config) {
this.config = config;
}
/**
* 获取所有科目列表
* @returns {subjectTarget[]} 所有科目
*/
getAllSubjects() {
return this.config.subjects;
}
/**
* 根据科目名称获取科目
* @param {string} name - 科目名称
* @returns {subjectTarget | undefined} 匹配的科目或 undefined
*/
getSubject(name) {
return this.config.subjects.find((subject) => subject.name === name);
}
/**
* 根据科目UUID获取科目
* @param {UUID} uuid - 科目UUID
* @returns {subjectTarget | undefined} 匹配的科目或 undefined
*/
createSubject(subject) {
if (this.config.subjects.some((s) => s.name === subject.name)) {
return false;
}
this.config.subjects.push(subject);
return true;
}
/**
* 编辑科目
* @param {string} name - 科目名称
* @param {Partial<subjectTarget>} subject - 要更新的科目属性
* @returns {boolean} 是否编辑成功
*/
editSubject(name, subject) {
const index = this.config.subjects.findIndex((s) => s.name === name);
if (index === -1) {
return false;
}
this.config.subjects[index] = Object.assign(Object.assign({}, this.config.subjects[index]), subject);
return true;
}
/**
* 删除科目
* @param {string} name - 科目名称
* @returns {boolean} 是否删除成功
*/
deleteSubject(name) {
const index = this.config.subjects.findIndex((s) => s.name === name);
if (index === -1) {
return false;
}
this.config.subjects.splice(index, 1);
return true;
}
}
exports.SubjectManager = SubjectManager;
//# sourceMappingURL=subjectManager.js.map