-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
112 changed files
with
1,783 additions
and
1,619 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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
NODE_ENV=development | ||
API_DOMAIN=localhost | ||
PORT=3000 | ||
CORS_ORIGINS=http://localhost,http://localhost:3000 | ||
CORS_ORIGINS=http://localhost,http://localhost:3000,https://piquetde.stream | ||
|
||
REDIS_URL=redis://localhost:6379 |
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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/nest-cli", | ||
"collection": "@nestjs/schematics", | ||
"sourceRoot": "src", | ||
"compilerOptions": { | ||
"deleteOutDir": true | ||
} | ||
"$schema": "https://json.schemastore.org/nest-cli", | ||
"collection": "@nestjs/schematics", | ||
"sourceRoot": "src", | ||
"compilerOptions": { | ||
"plugins": [ | ||
"@nestjs/swagger" | ||
], | ||
"deleteOutDir": true | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,20 @@ | ||
import { Test, TestingModule } from "@nestjs/testing" | ||
import { CounterController } from "./counter.controller" | ||
import { CounterService } from "./counter.service" | ||
|
||
describe("CounterController", () => { | ||
let controller: CounterController | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [CounterService], | ||
controllers: [CounterController] | ||
}).compile() | ||
|
||
controller = module.get<CounterController>(CounterController) | ||
}) | ||
|
||
it("should be defined", () => { | ||
expect(controller).toBeDefined() | ||
}) | ||
}) |
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,24 @@ | ||
import { Controller, Get, Sse } from "@nestjs/common" | ||
import { ApiTags } from "@nestjs/swagger" | ||
import { from, map, Observable } from "rxjs" | ||
import { CounterService } from "./counter.service" | ||
import { CounterMessage, CounterMessagePayload } from "./interfaces/counter-message.interface" | ||
|
||
@ApiTags("Counter") | ||
@Controller("counter") | ||
export class CounterController { | ||
constructor(private readonly counterService: CounterService) {} | ||
|
||
@Sse("sse") | ||
counterSse(): Observable<CounterMessage> { | ||
return from(this.counterService.counterSubject).pipe(map((data) => data)) | ||
} | ||
|
||
@Get("state") | ||
getState(): CounterMessagePayload { | ||
return { | ||
amount: 0, | ||
updatedAt: Date.now() | ||
} | ||
} | ||
} |
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,9 @@ | ||
import { Module } from "@nestjs/common" | ||
import { CounterController } from "./counter.controller" | ||
import { CounterService } from "./counter.service" | ||
|
||
@Module({ | ||
controllers: [CounterController], | ||
providers: [CounterService] | ||
}) | ||
export class CounterModule {} |
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,18 @@ | ||
import { Test, TestingModule } from "@nestjs/testing" | ||
import { CounterService } from "./counter.service" | ||
|
||
describe("CounterService", () => { | ||
let service: CounterService | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [CounterService] | ||
}).compile() | ||
|
||
service = module.get<CounterService>(CounterService) | ||
}) | ||
|
||
it("should be defined", () => { | ||
expect(service).toBeDefined() | ||
}) | ||
}) |
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 { Subject } from "rxjs" | ||
import { CounterMessage, CounterMessagePayload } from "./interfaces/counter-message.interface" | ||
|
||
@Injectable() | ||
export class CounterService { | ||
public counterSubject: Subject<CounterMessage> | ||
|
||
constructor() { | ||
this.counterSubject = new Subject() | ||
} | ||
|
||
public updateCounter(amount: number): void { | ||
const payload: CounterMessagePayload = { | ||
amount, | ||
updatedAt: Date.now() | ||
} | ||
this.counterSubject.next({ data: payload, type: "counter-update" }) | ||
} | ||
|
||
public newDonation(amount: number): void { | ||
const payload: CounterMessagePayload = { | ||
amount | ||
} | ||
this.counterSubject.next({ data: payload, type: "new-donation" }) | ||
} | ||
} |
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 @@ | ||
export interface NewDonationEvent { | ||
data: NewDonationPayload | ||
id?: string | ||
type: "new-donation" | ||
retry?: number | ||
} | ||
|
||
export interface NewDonationPayload { | ||
// Amount of the donation in euros | ||
amount: number | ||
} | ||
|
||
export interface CounterUpdateEvent { | ||
data: CounterUpdatePayload | ||
id?: string | ||
type: "counter-update" | ||
retry?: number | ||
} | ||
|
||
export interface CounterUpdatePayload { | ||
// Total amount of donations in euros | ||
amount: number | ||
// Timestamp in milliseconds | ||
updatedAt: number | ||
} | ||
|
||
export type CounterMessage = NewDonationEvent | CounterUpdateEvent | ||
|
||
export type CounterMessagePayload = NewDonationPayload | CounterUpdatePayload |
Oops, something went wrong.