Skip to content

Commit 4911fa7

Browse files
committed
refactor: Update chord data fetching logic and improve code consistency
- Add sorting options to database queries in both chords.js and chordTables.ts for consistent data retrieval. - Enhance code readability by standardizing the formatting of promises and object properties. - Ensure proper handling of empty states in the data fetching logic, improving overall robustness.
1 parent 22b77cf commit 4911fa7

2 files changed

Lines changed: 34 additions & 22 deletions

File tree

admin_panel/store/chords.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ export default {
44
state() {
55
return {
66
tables: [],
7-
chords: []
7+
chords: [],
88
};
99
},
1010

1111
getters: {
1212
chords(state) {
1313
return state.chords || [];
14-
}
14+
},
1515
},
1616

1717
mutations: {
@@ -20,7 +20,7 @@ export default {
2020
},
2121
SET_CHORDS(state, list) {
2222
state.chords = list;
23-
}
23+
},
2424
},
2525

2626
actions: {
@@ -36,6 +36,7 @@ export default {
3636
database: "chord",
3737
collection: "table",
3838
query: {},
39+
options: { sort: "_id" },
3940
populates: [
4041
"keySignature",
4142
"type",
@@ -46,12 +47,12 @@ export default {
4647
"chromaticRows.one",
4748
"chromaticRows.two",
4849
"chromaticRows.three",
49-
"chromaticRows.four"
50-
]
50+
"chromaticRows.four",
51+
],
5152
})
52-
.then(list => commit("SET_TABLES", list));
53+
.then((list) => commit("SET_TABLES", list));
5354
} else {
54-
return new Promise(done => done());
55+
return new Promise((done) => done());
5556
}
5657
},
5758
getChords({ commit, state }) {
@@ -64,9 +65,9 @@ export default {
6465
.find({
6566
database: "chord",
6667
collection: "chord",
67-
query: {}
68+
query: {},
6869
})
69-
.then(list => commit("SET_CHORDS", list));
70-
}
71-
}
70+
.then((list) => commit("SET_CHORDS", list));
71+
},
72+
},
7273
};

end_user/stores/chordTables.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,29 @@ export const useChordTablesStore = defineStore('chordTables', () => {
7373
database: CHORD_DATABASE_NAME,
7474
collection: CHORD_COLLECTION_NAME.TABLE,
7575
query: {},
76+
options:{sort: '_id'},
7677
populates: [
77-
'keySignature',
78-
'type',
79-
'rows.major',
80-
'rows.naturalMinor',
81-
'rows.harmonicMinor',
82-
'rows.melodicMinor',
83-
'chromaticRows.one',
84-
'chromaticRows.two',
85-
'chromaticRows.three',
86-
'chromaticRows.four',
87-
],
78+
// @ts-ignore
79+
"keySignature",
80+
// @ts-ignore
81+
"type",
82+
// @ts-ignore
83+
"rows.major",
84+
// @ts-ignore
85+
"rows.naturalMinor",
86+
// @ts-ignore
87+
"rows.harmonicMinor",
88+
// @ts-ignore
89+
"rows.melodicMinor",
90+
// @ts-ignore
91+
"chromaticRows.one",
92+
// @ts-ignore
93+
"chromaticRows.two",
94+
// @ts-ignore
95+
"chromaticRows.three",
96+
// @ts-ignore
97+
"chromaticRows.four"
98+
]
8899
})
89100

90101
if (fetchedTables && fetchedTables.length > 0) {

0 commit comments

Comments
 (0)