Überarbeitung des Stripe Prozesses
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Body, Controller, Get, Inject, Param, Post, Query, Request, UseGuards } from '@nestjs/common';
|
||||
import { BadRequestException, Body, Controller, Get, Inject, Param, Post, Query, Request, UseGuards } from '@nestjs/common';
|
||||
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
|
||||
import { Logger } from 'winston';
|
||||
import { ZodError } from 'zod';
|
||||
import { FileService } from '../file/file.service.js';
|
||||
import { OptionalJwtAuthGuard } from '../jwt-auth/optional-jwt-auth.guard.js';
|
||||
import { User } from '../models/db.model';
|
||||
@@ -31,13 +32,32 @@ export class UserController {
|
||||
return user;
|
||||
}
|
||||
@Post()
|
||||
save(@Body() user: any): Promise<User> {
|
||||
async save(@Body() user: any): Promise<User> {
|
||||
this.logger.info(`Saving user: ${JSON.stringify(user)}`);
|
||||
const savedUser = this.userService.saveUser(user);
|
||||
this.logger.info(`User persisted: ${JSON.stringify(savedUser)}`);
|
||||
try {
|
||||
const savedUser = await this.userService.saveUser(user);
|
||||
this.logger.info(`User persisted: ${JSON.stringify(savedUser)}`);
|
||||
return savedUser;
|
||||
} catch (error) {
|
||||
if (error instanceof ZodError) {
|
||||
const filteredErrors = error.errors
|
||||
.map(item => ({
|
||||
...item,
|
||||
field: item.path[0],
|
||||
}))
|
||||
.filter((item, index, self) => index === self.findIndex(t => t.path[0] === item.path[0]));
|
||||
throw new BadRequestException(filteredErrors);
|
||||
}
|
||||
throw error; // Andere Fehler einfach durchreichen
|
||||
}
|
||||
}
|
||||
@Post('guaranteed')
|
||||
async saveGuaranteed(@Body() user: any): Promise<User> {
|
||||
this.logger.info(`Saving user guaranteed: ${JSON.stringify(user)}`);
|
||||
const savedUser = await this.userService.saveUser(user, false);
|
||||
this.logger.info(`User persisted guaranteed: ${JSON.stringify(savedUser)}`);
|
||||
return savedUser;
|
||||
}
|
||||
|
||||
@Post('search')
|
||||
find(@Body() criteria: UserListingCriteria): any {
|
||||
this.logger.info(`Searching for users with criteria: ${JSON.stringify(criteria)}`);
|
||||
|
||||
Reference in New Issue
Block a user