Überarbeitung des Stripe Prozesses
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import { BadRequestException, Inject, Injectable } from '@nestjs/common';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { and, count, eq, ilike, inArray, or, SQL, sql } from 'drizzle-orm';
|
||||
import { NodePgDatabase } from 'drizzle-orm/node-postgres/driver.js';
|
||||
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
|
||||
import { Logger } from 'winston';
|
||||
import { ZodError } from 'zod';
|
||||
import * as schema from '../drizzle/schema.js';
|
||||
import { customerSubTypeEnum, PG_CONNECTION } from '../drizzle/schema.js';
|
||||
import { FileService } from '../file/file.service.js';
|
||||
@@ -97,7 +96,7 @@ export class UserService {
|
||||
.where(sql`email = ${email}`)) as User[];
|
||||
if (users.length === 0) {
|
||||
const user: User = { id: undefined, customerType: 'buyer', ...createDefaultUser(email, jwtuser.firstname, jwtuser.lastname, null) };
|
||||
const u = await this.saveUser(user);
|
||||
const u = await this.saveUser(user, false);
|
||||
return convertDrizzleUserToUser(u);
|
||||
} else {
|
||||
const user = users[0];
|
||||
@@ -117,7 +116,7 @@ export class UserService {
|
||||
user.hasProfile = this.fileService.hasProfile(emailToDirName(user.email));
|
||||
return convertDrizzleUserToUser(user);
|
||||
}
|
||||
async saveUser(user: User): Promise<User> {
|
||||
async saveUser(user: User, processValidation = true): Promise<User> {
|
||||
try {
|
||||
user.updated = new Date();
|
||||
if (user.id) {
|
||||
@@ -125,7 +124,10 @@ export class UserService {
|
||||
} else {
|
||||
user.created = new Date();
|
||||
}
|
||||
const validatedUser = UserSchema.parse(user);
|
||||
let validatedUser = user;
|
||||
if (processValidation) {
|
||||
validatedUser = UserSchema.parse(user);
|
||||
}
|
||||
const drizzleUser = convertUserToDrizzleUser(validatedUser);
|
||||
if (user.id) {
|
||||
const [updateUser] = await this.conn.update(schema.users).set(drizzleUser).where(eq(schema.users.id, user.id)).returning();
|
||||
@@ -135,15 +137,6 @@ export class UserService {
|
||||
return convertDrizzleUserToUser(newUser) as User;
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user