contributors license import type { TelegramUserInterface } from "@app/types/databases.type" ; import configs from "@configs/config" ; import lowdb from "lowdb" ; import lowdbFileSync from "lowdb/adapters/FileSync" ; const databases = { users : lowdb ( new lowdbFileSync < { users : TelegramUserInterface [ ] ; } > ( configs . databases . users ) ) } ; databases . users = lowdb ( new lowdbFileSync ( configs . databases . users ) ) ; databases . users . defaults ( { users : [ ] } ) . write ( ) ; Context interface param { TelegramUserInterface } json const writeUser = async ( json ) : Promise < void > => { const user_id = databases . users . get ( "users" ) . find ( { id : json . id } ) . value ( ) ; if ( user_id ) { databases . users . get ( "users" ) . find ( { id : user_id . id } ) . assign ( json ) . write ( ) ; } else { databases . users . get ( "users" ) . push ( json ) . write ( ) ; } } ; export { databases , writeUser } ; export default databases ;