mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
qdb data file overwrite fix
This commit is contained in:
parent
9fc51a51bd
commit
0cc020b529
2 changed files with 16 additions and 7 deletions
|
@ -273,13 +273,22 @@ function writeNewData(
|
||||||
publicDir: string
|
publicDir: string
|
||||||
) {
|
) {
|
||||||
const qdbsToWrite = [...changedQuestionDbs, ...newQuestionDbs]
|
const qdbsToWrite = [...changedQuestionDbs, ...newQuestionDbs]
|
||||||
const qdbsFile: DataFile[] = qdbsToWrite.map((qdb) => {
|
const existingQdbs = utils.ReadJSON<DataFile[]>(dbsFilePath)
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
const { data, index, ...restOfQdb } = qdb
|
|
||||||
return restOfQdb
|
|
||||||
})
|
|
||||||
|
|
||||||
utils.WriteFile(JSON.stringify(qdbsFile, null, 2), dbsFilePath)
|
const qdbDataToWrite = qdbsToWrite.reduce((acc, qdb) => {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
const { data, index, ...qdbData } = qdb
|
||||||
|
const existingQdbData = acc.find((data) => {
|
||||||
|
return data.name === qdbData.name
|
||||||
|
})
|
||||||
|
if (!existingQdbData) {
|
||||||
|
return [...acc, qdbData]
|
||||||
|
} else {
|
||||||
|
return acc
|
||||||
|
}
|
||||||
|
}, existingQdbs)
|
||||||
|
|
||||||
|
utils.WriteFile(JSON.stringify(qdbDataToWrite, null, 2), dbsFilePath)
|
||||||
qdbsToWrite.forEach((qdb) => {
|
qdbsToWrite.forEach((qdb) => {
|
||||||
try {
|
try {
|
||||||
writeData(qdb.data, publicDir + qdb.path)
|
writeData(qdb.data, publicDir + qdb.path)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 338db8e1417ba4aa647a74e0a5bad70fb04bc79e
|
Subproject commit 62fb75ec5f96656d95e53f3aa2b92ff59dc38173
|
Loading…
Add table
Add a link
Reference in a new issue