-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into dev
- Loading branch information
Showing
15 changed files
with
182 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Global, Module } from '@nestjs/common'; | ||
// import { TeamTrackingService } from '@app/teamtracking/teamtracking.service'; | ||
import { GrassTrackingService } from './grasstracking.service'; | ||
|
||
@Global() | ||
@Module({ | ||
providers: [GrassTrackingService], | ||
exports: [GrassTrackingService], | ||
}) | ||
export class GrasstrackingModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { Subject, Observable } from 'rxjs'; | ||
|
||
@Injectable() | ||
export class GrassTrackingService { | ||
private teamStatusUpdates: Record<string, Subject<string>> = {}; | ||
|
||
getTeamStatusUpdateObservable(teamId: string): Observable<string> { | ||
const statusKey = `team_${teamId}_status`; | ||
if (!this.teamStatusUpdates[statusKey]) { | ||
this.teamStatusUpdates[statusKey] = new Subject<string>(); | ||
} | ||
console.log(Object.keys(this.teamStatusUpdates)); | ||
return this.teamStatusUpdates[statusKey].asObservable(); | ||
} | ||
|
||
pushTeamStatusUpdate(teamId: string, status: string): void { | ||
const statusKey = `team_${teamId}_status`; | ||
if (!this.teamStatusUpdates[statusKey]) { | ||
this.teamStatusUpdates[statusKey] = new Subject<string>(); | ||
} | ||
// console.log(statusKey); | ||
this.teamStatusUpdates[statusKey].next(status); | ||
} | ||
|
||
streamTeamStatus(teamId: string): Observable<string> { | ||
return this.getTeamStatusUpdateObservable(`${teamId}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './grasstracking.service'; | ||
export * from './grasstracking.module'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// import { Team } from '../entities/team.entity'; | ||
|
||
import { Team } from 'src/team/entities/team.entity'; | ||
|
||
export class GrassStatusEvent { | ||
static readonly EVENT_NAME = 'grass.status'; | ||
|
||
readonly team: Team; | ||
|
||
constructor(team: Team) { | ||
this.team = team; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { GrassStatusEvent } from '../events/grass-status.event'; | ||
import { OnEvent } from '@nestjs/event-emitter'; | ||
// import { TeamRepository } from '../team.repository'; | ||
// import { TeamTrackingService } from '@app/teamtracking'; | ||
// import { TeamStreamDto } from '../dto/team.dto'; | ||
import { GrassStreamDto } from '../dto/grass.dto'; | ||
import { TeamRepository } from 'src/team/team.repository'; | ||
import { GrassTrackingService } from 'libs/grasstracking/src'; | ||
|
||
@Injectable() | ||
export class GrassStatusListener { | ||
constructor( | ||
private readonly teamRepository: TeamRepository, | ||
private readonly grassTrackingService: GrassTrackingService, | ||
) {} | ||
|
||
@OnEvent(GrassStatusEvent.EVENT_NAME, { async: true }) | ||
async handleTeamStatusUpdate(grassStreamDTO: GrassStreamDto) { | ||
const teamCode = grassStreamDTO.teamCode.toString(); | ||
|
||
this.grassTrackingService.pushTeamStatusUpdate( | ||
teamCode, | ||
JSON.stringify({ data: grassStreamDTO }), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters