Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/store/modules/dataSize.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const mutations = {
* @param {number|Object} data.data - The data to be setted.
*/
addRemoveSize(state, data) {
if(!state.dataSize) return;
state.dataSize[data.key] = data.data;
},
/**
Expand Down Expand Up @@ -85,6 +86,11 @@ const actions = {
db.collection("data-size")
.get()
.then(snapshot => {
if (snapshot.empty) {
commit("setDataSize", null);
commit("setLoading", false);
return;
}
const doc = snapshot.docs[0];

for (let key in doc.data()) {
Expand All @@ -108,8 +114,8 @@ const actions = {
* @param {Store} store - The vuex store.
*/
addTestsByWeek({ commit, state }) {
if(!state.dataSize || !state.dataSize.testsByWeek) return;
const thisWeek = getWeekInterval(new Date())[0];

let data = { ...state.dataSize.testsByWeek };

const lastWeeks = Object.keys(data);
Expand Down Expand Up @@ -166,6 +172,7 @@ const actions = {
* @param {Test[]} payload.tests - The tests that will be removed.
*/
async removeTestsByWeek({ commit, state }, payload) {
if (!state.dataSize || !state.dataSize.testsByWeek) return;
const { tests } = payload;

let data = { ...state.dataSize.testsByWeek };
Expand Down Expand Up @@ -241,7 +248,7 @@ const getters = {
* @returns {(subjectName: string) => number} The number of questions of the given subject.
*/
getNumberOfQuestionBySubject(state) {
return subjectName => state.dataSize.questions.subject[subjectName] || 0;
return subjectName => state.dataSize?.questions?.subject?.[subjectName] || 0;
},
/**
* Gets a sorted object of data size tests by week key.
Expand All @@ -250,6 +257,7 @@ const getters = {
* @returns {Object.<string, number>} The sorted data size tests by week key.
*/
getTestsByWeek(state) {
if (!state.dataSize || !state.dataSize.testsByWeek) return {};
return Object.fromEntries(
Object.entries(state.dataSize.testsByWeek).sort((a, b) =>
a[0] < b[0] ? -1 : 1
Expand All @@ -263,6 +271,7 @@ const getters = {
* @returns {string[]} The interval of all weeks in data size tests by week key.
*/
getTestsByWeekInterval(state) {
if (!state.dataSize || !state.dataSize.testsByWeek) return [];
const intervals = [];
Object.entries(state.dataSize.testsByWeek)
.sort((a, b) => (a[0] < b[0] ? -1 : 1))
Expand Down