Skip to content

Commit

Permalink
feat: get number of online instances
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrdsilva committed Jun 23, 2024
1 parent 5574246 commit ebb1f01
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/providers/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,18 @@ export class UserService {
return isOnline;
}

async setToOffline(username: string) {
async onlineInstances(request: Request) {
const user: User = request['user'];
const jobs = await this.onlineUsersQueue.getWaiting();
const onlineInstances = jobs.filter((job) => job.data === user.username);

return onlineInstances.length;
}

async setToOffline(request: Request) {
const user: User = request['user'];
const jobs = await this.onlineUsersQueue.getWaiting();
const onlineUser = jobs.find((job) => job.data === username);
const onlineUser = jobs.find((job) => job.data === user.username);

return await onlineUser
.remove()
Expand Down
11 changes: 9 additions & 2 deletions src/resolvers/user.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,15 @@ export class UserResolver {
return this.userService.isCurrentlyOnline(username);
}

@UseGuards(JwtAuthGuard)
@Query(() => Int)
onlineInstances(@Context() context: { req: Request }) {
return this.userService.onlineInstances(context.req);
}

@UseGuards(JwtAuthGuard)
@Mutation(() => Boolean)
setToOffline(@Args('username') username: string) {
return this.userService.setToOffline(username);
setToOffline(@Context() context: { req: Request }) {
return this.userService.setToOffline(context.req);
}
}

0 comments on commit ebb1f01

Please sign in to comment.