mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-28 08:17:43 +02:00
chore: archive finance, mail, moodlit apps and rename voxel-lava
- Move finance, mail, moodlit to apps-archived for later development - Rename games/voxel-lava to games/voxelava 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
c3c272abc9
commit
ace7fa8f7f
427 changed files with 0 additions and 0 deletions
|
|
@ -0,0 +1 @@
|
|||
export * from './update-settings.dto';
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
import { IsString, IsOptional, IsNumber, MaxLength, Min, Max } from 'class-validator';
|
||||
|
||||
export class UpdateSettingsDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(3)
|
||||
defaultCurrency?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(10)
|
||||
locale?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(20)
|
||||
dateFormat?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@Min(0)
|
||||
@Max(6)
|
||||
weekStartsOn?: number;
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
import { Controller, Get, Put, Body, UseGuards } from '@nestjs/common';
|
||||
import { JwtAuthGuard, CurrentUser, type CurrentUserData } from '@manacore/shared-nestjs-auth';
|
||||
import { SettingsService } from './settings.service';
|
||||
import { UpdateSettingsDto } from './dto';
|
||||
|
||||
@Controller('settings')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
export class SettingsController {
|
||||
constructor(private readonly settingsService: SettingsService) {}
|
||||
|
||||
@Get()
|
||||
get(@CurrentUser() user: CurrentUserData) {
|
||||
return this.settingsService.get(user.userId);
|
||||
}
|
||||
|
||||
@Put()
|
||||
update(@CurrentUser() user: CurrentUserData, @Body() dto: UpdateSettingsDto) {
|
||||
return this.settingsService.update(user.userId, dto);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { SettingsController } from './settings.controller';
|
||||
import { SettingsService } from './settings.service';
|
||||
|
||||
@Module({
|
||||
controllers: [SettingsController],
|
||||
providers: [SettingsService],
|
||||
exports: [SettingsService],
|
||||
})
|
||||
export class SettingsModule {}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
import { Injectable, Inject } from '@nestjs/common';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { DATABASE_CONNECTION, type Database } from '../db/connection';
|
||||
import { userSettings } from '../db/schema';
|
||||
import { UpdateSettingsDto } from './dto';
|
||||
|
||||
const DEFAULT_SETTINGS = {
|
||||
defaultCurrency: 'EUR',
|
||||
locale: 'de-DE',
|
||||
dateFormat: 'dd.MM.yyyy',
|
||||
weekStartsOn: 1, // Monday
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class SettingsService {
|
||||
constructor(@Inject(DATABASE_CONNECTION) private db: Database) {}
|
||||
|
||||
async get(userId: string) {
|
||||
const [settings] = await this.db
|
||||
.select()
|
||||
.from(userSettings)
|
||||
.where(eq(userSettings.userId, userId));
|
||||
|
||||
if (!settings) {
|
||||
// Create default settings
|
||||
const [newSettings] = await this.db
|
||||
.insert(userSettings)
|
||||
.values({
|
||||
userId,
|
||||
...DEFAULT_SETTINGS,
|
||||
})
|
||||
.returning();
|
||||
return newSettings;
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
async update(userId: string, dto: UpdateSettingsDto) {
|
||||
// Ensure settings exist
|
||||
await this.get(userId);
|
||||
|
||||
const [settings] = await this.db
|
||||
.update(userSettings)
|
||||
.set({
|
||||
...(dto.defaultCurrency !== undefined && { defaultCurrency: dto.defaultCurrency }),
|
||||
...(dto.locale !== undefined && { locale: dto.locale }),
|
||||
...(dto.dateFormat !== undefined && { dateFormat: dto.dateFormat }),
|
||||
...(dto.weekStartsOn !== undefined && { weekStartsOn: dto.weekStartsOn }),
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
.where(eq(userSettings.userId, userId))
|
||||
.returning();
|
||||
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue