Merge branch 'main' into feature/cloud-sync-improvements

This commit is contained in:
Zamitto
2024-10-22 17:32:55 -03:00
committed by GitHub
31 changed files with 846 additions and 94 deletions

View File

@@ -7,7 +7,7 @@ import {
gamesPlaytime,
} from "@main/services";
import { dataSource } from "@main/data-source";
import { DownloadQueue, Game, UserAuth } from "@main/entity";
import { DownloadQueue, Game, UserAuth, UserSubscription } from "@main/entity";
const signOut = async (_event: Electron.IpcMainInvokeEvent) => {
const databaseOperations = dataSource
@@ -19,6 +19,10 @@ const signOut = async (_event: Electron.IpcMainInvokeEvent) => {
await transactionalEntityManager
.getRepository(UserAuth)
.delete({ id: 1 });
await transactionalEntityManager
.getRepository(UserSubscription)
.delete({ id: 1 });
})
.then(() => {
/* Removes all games being played */

View File

@@ -1,43 +1,11 @@
import { registerEvent } from "../register-event";
import { logger } from "@main/services";
import type { ProfileVisibility, UserDetails } from "@types";
import { userAuthRepository } from "@main/repository";
import { UserNotLoggedInError } from "@shared";
import type { UserDetails } from "@types";
import { getUserData } from "@main/services/user/get-user-data";
const getMe = async (
_event: Electron.IpcMainInvokeEvent
): Promise<UserDetails | null> => {
return getUserData().catch(async (err) => {
if (err instanceof UserNotLoggedInError) {
return null;
}
logger.error("Failed to get logged user", err);
const loggedUser = await userAuthRepository.findOne({ where: { id: 1 } });
if (loggedUser) {
return {
...loggedUser,
id: loggedUser.userId,
username: "",
bio: "",
profileVisibility: "PUBLIC" as ProfileVisibility,
subscription: loggedUser.subscription
? {
id: loggedUser.subscription.subscriptionId,
status: loggedUser.subscription.status,
plan: {
id: loggedUser.subscription.planId,
name: loggedUser.subscription.planName,
},
expiresAt: loggedUser.subscription.expiresAt,
}
: null,
};
}
return null;
});
return getUserData();
};
registerEvent("getMe", getMe);