work on the list call

This commit is contained in:
iamBadgers
2025-06-16 00:20:23 -07:00
parent 1f43ff468b
commit a62fe1aba9
3 changed files with 69 additions and 16 deletions

View File

@@ -16,26 +16,47 @@ export class DatabaseService {
return this.characterCollection
.insertOne(character)
.then((insertResult) => {
console.log(insertResult)
console.log("Adding new character record:", insertResult)
return this.characterCollection.findOne({
_id: insertResult.insertedId,
})
})
.then(recordToCharacter)
.then(record => {
const character = recordToCharacter(record)
console.log(`New character result: \n _id: ${record._id}`, character)
return character
})
}
fetchCharactersForPlayer(playerName: string): Promise<Array<Character>> {
return this.characterCollection
.find({ playerName: playerName })
.toArray()
.then((results) =>
results.map(recordToCharacter),
)
.then((results) => results.map(recordToCharacter))
}
fetchCharactersForCharacterName(playerName: string): Array<Character> {
return []
}
listCharacters(
playerName: string,
characterName: string,
): Promise<Array<Character>> {
let query = {}
if (playerName != '') query['playerName'] = playerName
if (characterName != '')
query['$or'] = [
{ characterName: characterName },
{ characterAlias: characterName},
]
return this.characterCollection
.find(query)
.toArray()
.then((results) => results.map(recordToCharacter))
}
}
function recordToCharacter(record): Character {
@@ -43,5 +64,8 @@ function recordToCharacter(record): Character {
playerName: record.playerName,
characterName: record.characterName,
characterAlias: record.characterAlias,
version: record.version,
sourceTable: record.sourceTable,
json: record.json,
}
}