user.service

This commit is contained in:
Andreas Knuth 2025-02-13 14:21:59 -06:00
parent d180cd70e8
commit 71ddc7eb3e
6 changed files with 17 additions and 12 deletions

View File

@ -306,6 +306,7 @@ export class DrizzleService {
// Optional: Aktualisierung von Name und sign_in_provider, falls sich diese ändern sollten
name: createUserDto.name,
sign_in_provider: createUserDto.sign_in_provider,
numberOfLogins: sql`${users.numberOfLogins} + 1`,
})
.where(eq(users.email, createUserDto.email))
.returning();

View File

@ -1,9 +1,11 @@
// user.controller.ts
import { Body, Controller, Post } from '@nestjs/common';
import { Body, Controller, Post, UseGuards } from '@nestjs/common';
import type { InsertUser } from '../db/schema';
import { AuthGuard } from '../service/auth.guard';
import { DrizzleService } from './drizzle.service';
@Controller('users')
@UseGuards(AuthGuard)
export class UserController {
constructor(private readonly drizzleService: DrizzleService) {}

View File

@ -37,6 +37,7 @@ export const users = table(
role: rolesEnum().default('guest'),
sign_in_provider: t.varchar('sign_in_provider', { length: 50 }),
lastLogin: t.timestamp('lastLogin', { mode: 'date' }).defaultNow(),
numberOfLogins: t.integer('numberOfLogins').default(1), // Neue Spalte
},
table => [t.uniqueIndex('users_idx').on(table.id)],
);

View File

@ -25,7 +25,8 @@ CREATE TABLE "users" (
"email" varchar NOT NULL,
"role" "roles" DEFAULT 'guest',
"sign_in_provider" varchar(50),
"lastLogin" timestamp DEFAULT now()
"lastLogin" timestamp DEFAULT now(),
"numberOfLogins" integer DEFAULT 1
);
--> statement-breakpoint
CREATE UNIQUE INDEX "deck_idx" ON "deck" USING btree ("id");--> statement-breakpoint

View File

@ -1,5 +1,5 @@
{
"id": "2bed4eae-3e6e-414b-85e2-d16e632c17ef",
"id": "c323fb0d-9c45-4675-9d26-195222c7f89c",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
@ -195,19 +195,19 @@
"primaryKey": false,
"notNull": false
},
"inserted": {
"name": "inserted",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"lastLogin": {
"name": "lastLogin",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"numberOfLogins": {
"name": "numberOfLogins",
"type": "integer",
"primaryKey": false,
"notNull": false,
"default": 1
}
},
"indexes": {

View File

@ -5,8 +5,8 @@
{
"idx": 0,
"version": "7",
"when": 1739461160843,
"tag": "0000_fuzzy_invaders",
"when": 1739468475557,
"tag": "0000_giant_blink",
"breakpoints": true
}
]