Skip to content

Commit

Permalink
Merge pull request #140 from game-node-app/dev
Browse files Browse the repository at this point in the history
adds PSN to importer watch service
  • Loading branch information
Lamarcke authored Jan 6, 2025
2 parents 9d12ad6 + 4e24228 commit 3335de0
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/importer/importer-watch/importer-watch.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ import {
} from "../../notifications/notifications.constants";
import { UserConnectionDto } from "../../connections/dto/user-connection.dto";

const connectionToImporterSource = (connectionType: EConnectionType) => {
switch (connectionType) {
case EConnectionType.STEAM:
return EImporterSource.STEAM;
case EConnectionType.PSN:
return EImporterSource.PSN;
}
};

@Injectable()
export class ImporterWatchService {
private readonly logger = new Logger(ImporterWatchService.name);
Expand Down Expand Up @@ -87,20 +96,17 @@ export class ImporterWatchService {
}

private async findUnprocessedEntries(userConnection: UserConnectionDto) {
let unprocessedGames: GameExternalGame[] = [];
switch (userConnection.type) {
case EConnectionType.STEAM:
[unprocessedGames] =
await this.importerService.findUnprocessedEntries(
userConnection.profileUserId,
EImporterSource.STEAM,
{
offset: 0,
limit: 99999,
},
);
break;
}
const importerSource = connectionToImporterSource(userConnection.type);
const [unprocessedGames] =
await this.importerService.findUnprocessedEntries(
userConnection.profileUserId,
importerSource,
{
offset: 0,
limit: 999999,
},
);

if (unprocessedGames.length === 0) {
this.logger.log(
`No unprocessed entries found for userId: ${userConnection.profileUserId} on source ${userConnection.type}`,
Expand Down Expand Up @@ -135,17 +141,19 @@ export class ImporterWatchService {
await this.createNotification(
userConnection.profileUserId,
notAlreadyNotifiedGames,
importerSource,
);
}

private async createNotification(
userId: string,
externalGames: GameExternalGame[],
source: EImporterSource,
) {
const notification = await this.importerNotificationRepository.save({
libraryUserId: userId,
games: externalGames,
source: EImporterSource.STEAM,
source,
});

this.notificationsQueueService.registerNotification({
Expand Down

0 comments on commit 3335de0

Please sign in to comment.