forked from noxious/server
use camelcase file names from now on...
This commit is contained in:
38
src/managers/userManager.ts
Normal file
38
src/managers/userManager.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { User } from '@prisma/client'
|
||||
import logger from '../utilities/logger'
|
||||
|
||||
type TLoggedInUsers = {
|
||||
users: User[]
|
||||
}
|
||||
|
||||
class UserManager {
|
||||
private loggedInUsers: TLoggedInUsers[] = []
|
||||
|
||||
// Method to initialize user manager
|
||||
public async boot() {
|
||||
logger.info('User manager loaded')
|
||||
}
|
||||
|
||||
// Function that adds user to logged in users
|
||||
public loginUser(user: User) {
|
||||
this.loggedInUsers.push({
|
||||
users: [user]
|
||||
})
|
||||
}
|
||||
|
||||
// Function that checks if a user is already logged in
|
||||
public findUser(user: User) {
|
||||
return this.loggedInUsers.find((loggedInUser) => {
|
||||
return loggedInUser.users.includes(user)
|
||||
})
|
||||
}
|
||||
|
||||
// Function that lists all logged in users
|
||||
public listUsers() {
|
||||
return this.loggedInUsers.map((loggedInUser) => {
|
||||
return loggedInUser.users
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default new UserManager()
|
Reference in New Issue
Block a user