Commit 88785a74 authored by Antonín Kadrmas's avatar Antonín Kadrmas
Browse files

ref (!5): search unique git sign in and signIn true

parent 88455d7d
Loading
Loading
Loading
Loading
(20.5 KiB)

File changed.

No diff preview for this file type.

+25 −0
Original line number Diff line number Diff line
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_GitAccount" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "displayName" TEXT NOT NULL,
    "username" TEXT NOT NULL,
    "profileUrl" TEXT NOT NULL,
    "photos" TEXT NOT NULL,
    "email" TEXT NOT NULL,
    "accessToken" TEXT NOT NULL,
    "provider" TEXT NOT NULL,
    "accountId" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "signIn" BOOLEAN NOT NULL DEFAULT false,
    CONSTRAINT "GitAccount_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_GitAccount" ("accessToken", "accountId", "displayName", "email", "id", "photos", "profileUrl", "provider", "signIn", "userId", "username") SELECT "accessToken", "accountId", "displayName", "email", "id", "photos", "profileUrl", "provider", "signIn", "userId", "username" FROM "GitAccount";
DROP TABLE "GitAccount";
ALTER TABLE "new_GitAccount" RENAME TO "GitAccount";
CREATE UNIQUE INDEX "GitAccount_provider_key" ON "GitAccount"("provider");
CREATE UNIQUE INDEX "GitAccount_accountId_key" ON "GitAccount"("accountId");
CREATE UNIQUE INDEX "GitAccount_userId_key" ON "GitAccount"("userId");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ model GitAccount {
  accessToken String
  provider String @unique
  accountId String @unique
  userId String
  userId String @unique
  signIn Boolean @default(false)
  user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
}
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
@@ -20,8 +20,8 @@ export class AuthGitService {
    userId: string | undefined = undefined,
  ): Promise<PayloadType> {
    if (userId == undefined) {
      const account = await this.prismaService.gitAccount.findFirst({
        where: { accountId: user.profile.id },
      const account = await this.prismaService.gitAccount.findUnique({
        where: { accountId: user.profile.id, signIn: true },
      });
      if (account && account.signIn) {
        return await this.authTokenService.getSignToken(account.userId);