fix: remove order in game schema

This commit is contained in:
Chen, Tai-Lin authored and wancat committed 2023-10-29 17:41:38 +08:00
1 parent f864cecfa4
commit b4a37f7606
7 files changed
+45 -34

No files matched your search

+1 -1
View File
@@ -1,4 +1,4 @@
{
"watch": ["src", "swagger.yaml"],
"watch": ["src", "swagger.yaml", "../quests"],
"ext": "js,yaml"
}
+29 -25
View File
@@ -10,35 +10,39 @@ export default async function loadAndUpdateQuests() {
const questNames = await fs.readdir(questDirectory)
const quests = Promise.all(
questNames.map(async (id) => {
// Check if id is directory
const stat = await fs.stat(path.join(questDirectory, id))
if (!stat.isDirectory()) {
return null
}
const fullPath = path.join(questDirectory, id, 'game.yml')
questNames
.filter((name) => !name.startsWith('.'))
.map(async (id) => {
// Check if id is directory
const stat = await fs.stat(path.join(questDirectory, id))
if (!stat.isDirectory()) {
return null
}
const fullPath = path.join(questDirectory, id, 'game.yml')
try {
// Read and parse the README.md file.
const body = await fs.readFile(fullPath, 'utf-8')
try {
// Read and parse the README.md file.
const body = await fs.readFile(fullPath, 'utf-8')
const quest = yaml.parse(body)
const quest = yaml.parse(body, {
merge: true,
})
return Quest.findByIdAndUpdate(
id,
{
return Quest.findByIdAndUpdate(
id,
...quest,
},
{
upsert: true,
}
)
} catch (error) {
console.error(`Error parsing quest ${id}:`, error)
throw error
}
})
{
id,
...quest,
},
{
upsert: true,
}
)
} catch (error) {
console.error(`Error parsing quest ${id}:`, error)
throw error
}
})
)
return quests