Commit 8673d2e8 authored by Christopher Mark Fullarton's avatar Christopher Mark Fullarton
Browse files

Adds syncing of local quizzes to the server

parent 9cddb3f5
import { ObjectId } from 'bson';
import { MemberEntity } from '../entities/member/MemberEntity';
import { QuizEntity } from '../entities/quiz/QuizEntity';
import { DbCollection, DbEvent } from '../enums/DbOperation';
import { IMemberEntity } from '../interfaces/entities/Member/IMemberEntity';
import { IMemberSerialized } from '../interfaces/entities/Member/IMemberSerialized';
import { IQuizEntity } from '../interfaces/quizzes/IQuizEntity';
import { AbstractDAO } from './AbstractDAO';
import DbDAO from './DbDAO';
import QuizDAO from './quiz/QuizDAO';
......@@ -86,6 +88,10 @@ class MemberDAO extends AbstractDAO<Array<MemberEntity>> {
return this.storage.find(val => val.token === token);
}
public removeMembersOfQuiz(removedQuiz: QuizEntity | IQuizEntity): void {
DbDAO.deleteMany(DbCollection.Members, { currentQuizName: removedQuiz.name });
}
private notifyQuizDAO(member: MemberEntity): void {
const quiz = QuizDAO.getQuizByName(member.currentQuizName);
if (!quiz) {
......@@ -98,7 +104,6 @@ class MemberDAO extends AbstractDAO<Array<MemberEntity>> {
private getMemberById(id: ObjectId | string): MemberEntity {
return this.storage.find(val => val.id.equals(id));
}
}
export default MemberDAO.getInstance();
......@@ -12,6 +12,7 @@ import { generateToken } from '../../lib/generateToken';
import { setPath } from '../../lib/resolveNestedObjectProperty';
import { AbstractDAO } from '../AbstractDAO';
import DbDAO from '../DbDAO';
import MemberDAO from '../MemberDAO';
class QuizDAO extends AbstractDAO<Array<IQuizEntity>> {
......@@ -52,7 +53,10 @@ class QuizDAO extends AbstractDAO<Array<IQuizEntity>> {
}
public removeQuiz(id: ObjectId): void {
this.storage.splice(this.storage.findIndex(val => val.id.equals(id)), 1);
const removedQuiz = this.storage.splice(this.storage.findIndex(val => val.id.equals(id)), 1);
removedQuiz[0].onRemove();
removedQuiz[0].state = 0;
MemberDAO.removeMembersOfQuiz(removedQuiz[0]);
}
public clearStorage(): void {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment