monitor/core/lib/player/playerFinder.ts
2025-04-16 22:30:27 +07:00

16 lines
631 B
TypeScript

import { DatabasePlayerType } from "@modules/Database/databaseTypes.js";
import { DatabasePlayer } from "./playerClasses.js"
/**
* Finds all players in the database with a particular matching identifier
*/
export const findPlayersByIdentifier = (identifier: string): DatabasePlayer[] => {
if(typeof identifier !== 'string' || !identifier.length) throw new Error(`invalid identifier`);
const filter = (player: DatabasePlayerType) => player.ids.includes(identifier);
const playersData = txCore.database.players.findMany(filter);
return playersData.map((dbData) => new DatabasePlayer(dbData.license, dbData))
}