Skip to content

Commit

Permalink
remove obsolete Sentry ; add userCount
Browse files Browse the repository at this point in the history
  • Loading branch information
anteeek committed Dec 8, 2020
1 parent b820293 commit 4b6cefc
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 55 deletions.
3 changes: 0 additions & 3 deletions __tests__/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ import { inMemoryFileService } from "../src/infrastructure/filesystem";

Container.set("eventEmitter", new EventEmitter());

Container.set("errorTracker", {
submit: jest.fn()
})

Container.set("THIS_INSTANCE_ADDRESS", "dummyhost:202020");

Expand Down
8 changes: 7 additions & 1 deletion src/application/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@
| along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import jwt from "jsonwebtoken";
import { EventEmitter } from "events";

import { Container, Service, Inject } from "typedi";

import { TUserCredentials, TAdminCredentials, ITokenClaims, TUserTokenClaims, TAdminTokenClaims } from "../types/auth";
import { AppError } from "../infrastructure/utils";

import { TChatroomRepository } from "../types/infrastructure";
import events from "./events/events";

@Service()
export default class AuthService {

constructor(
@Inject("chatroomRepository") private chatroomRepository: TChatroomRepository
@Inject("chatroomRepository") private chatroomRepository: TChatroomRepository,
@Inject("eventEmitter") private eventEmitter: EventEmitter
) {};

async login({ slug, ...credentials }: TUserCredentials) {
Expand All @@ -56,6 +60,8 @@ export default class AuthService {

await this.chatroomRepository.persist(chatroom);

this.eventEmitter.emit(events.USER_JOINED_CHATROOM);

return await signToken({
slug,
name: "@"+credentials.name,
Expand Down
1 change: 1 addition & 0 deletions src/application/events/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
*/
export default {
NEW_CHATROOM: "chatrooms:new",
USER_JOINED_CHATROOM: "chatrooms:user-joined"
}
10 changes: 10 additions & 0 deletions src/application/events/subscribers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,14 @@ export default () => {
keyValueStore.setItem("CHATROOM_COUNT", chatroomCount + 1);
});

emitter.on(events.USER_JOINED_CHATROOM, async () => {

let userCount = keyValueStore.getItem("USER_COUNT");

if((typeof userCount) !== "number")
userCount = 0;

keyValueStore.setItem("USER_COUNT", userCount + 1);
})

}
2 changes: 0 additions & 2 deletions src/infrastructure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import config from "./config";
import Logger from "./logs/logger";
import eventEmitter from "./emitter";
import jobScheduler from "./jobs";
import errorTracker from "./logs/sentry";

import { alligatorFetcher } from "./fetcher";

Expand Down Expand Up @@ -57,7 +56,6 @@ Container.set("THIS_INSTANCE_ADDRESS", THIS_INSTANCE_ADDRESS);
Container.set("logger", Logger);
Container.set("eventEmitter", eventEmitter);
Container.set("jobScheduler", jobScheduler);
Container.set("errorTracker", errorTracker);

Container.set("fileService", memoryMode ? inMemoryFileService : fileService);
Container.set("keyValueStore", keyValueStore);
Expand Down
42 changes: 0 additions & 42 deletions src/infrastructure/logs/sentry.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/types/infrastructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,6 @@ export type TAlligatorWsConnector = {
};
}

/** /
* /------------------------------------------
*/

export type TErrorTracker = {
submit: (err: any) => Promise<void>;
}
/** /
* /------------------------------------------
*/
Expand Down

0 comments on commit 4b6cefc

Please sign in to comment.