mirror of
https://github.com/CaramelFur/Picsur.git
synced 2025-11-13 23:35:39 +01:00
Add half of preferences controller
This commit is contained in:
@@ -7,6 +7,7 @@ import Config from './env';
|
||||
import { DemoManagerModule } from './managers/demo/demomanager.module';
|
||||
import { EImageBackend } from './models/entities/image.entity';
|
||||
import { EUserBackend } from './models/entities/user.entity';
|
||||
import { PrefModule } from './routes/api/pref/pref.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -27,6 +28,7 @@ import { EUserBackend } from './models/entities/user.entity';
|
||||
AuthModule,
|
||||
ImageModule,
|
||||
DemoManagerModule,
|
||||
PrefModule,
|
||||
],
|
||||
})
|
||||
export class AppModule {
|
||||
|
||||
26
backend/src/routes/api/pref/pref.controller.ts
Normal file
26
backend/src/routes/api/pref/pref.controller.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Controller, Post, UseGuards } from '@nestjs/common';
|
||||
import { AdminGuard } from '../auth/admin.guard';
|
||||
import { JwtAuthGuard } from '../auth/jwt.guard';
|
||||
|
||||
@Controller('pref')
|
||||
export class PrefController {
|
||||
@UseGuards(JwtAuthGuard, AdminGuard)
|
||||
@Post('set/:key')
|
||||
async register(
|
||||
@Request() req: AuthFasityRequest,
|
||||
@Body() register: AuthRegisterRequest,
|
||||
) {
|
||||
const user = await this.authService.createUser(
|
||||
register.username,
|
||||
register.password,
|
||||
);
|
||||
|
||||
if (HasFailed(user)) throw new ConflictException('User already exists');
|
||||
|
||||
if (register.isAdmin) {
|
||||
await this.authService.makeAdmin(user);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
||||
7
backend/src/routes/api/pref/pref.module.ts
Normal file
7
backend/src/routes/api/pref/pref.module.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { PrefController } from './pref.controller';
|
||||
|
||||
@Module({
|
||||
controllers: [PrefController]
|
||||
})
|
||||
export class PrefModule {}
|
||||
Reference in New Issue
Block a user