showInDirectory, loggingInterceptor, conditional Views props & profs
This commit is contained in:
@@ -33,6 +33,7 @@ export const users = pgTable(
|
||||
subscriptionId: text('subscriptionId'),
|
||||
subscriptionPlan: subscriptionTypeEnum('subscriptionPlan'),
|
||||
location: jsonb('location'),
|
||||
showInDirectory: boolean('showInDirectory').default(true),
|
||||
// city: varchar('city', { length: 255 }),
|
||||
// state: char('state', { length: 2 }),
|
||||
// latitude: doublePrecision('latitude'),
|
||||
|
||||
@@ -15,7 +15,7 @@ export class LoggingInterceptor implements NestInterceptor {
|
||||
|
||||
const ip = this.cls.get('ip') || 'unknown';
|
||||
const countryCode = this.cls.get('countryCode') || 'unknown';
|
||||
const username = this.cls.get('username') || 'unknown';
|
||||
const username = this.cls.get('email') || 'unknown';
|
||||
|
||||
const method = request.method;
|
||||
const url = request.originalUrl;
|
||||
|
||||
@@ -13,12 +13,12 @@ export class UserInterceptor implements NestInterceptor {
|
||||
const request = context.switchToHttp().getRequest();
|
||||
|
||||
// Überprüfe, ob der Benutzer authentifiziert ist
|
||||
if (request.user && request.user.username) {
|
||||
if (request.user && request.user.email) {
|
||||
try {
|
||||
this.cls.set('username', request.user.username);
|
||||
this.logger.log(`CLS context gesetzt: Username=${request.user.username}`);
|
||||
this.cls.set('email', request.user.email);
|
||||
this.logger.log(`CLS context gesetzt: EMail=${request.user.email}`);
|
||||
} catch (error) {
|
||||
this.logger.error('Fehler beim Setzen der Username im CLS-Kontext', error);
|
||||
this.logger.error('Fehler beim Setzen der EMail im CLS-Kontext', error);
|
||||
}
|
||||
} else {
|
||||
this.logger.log('Kein authentifizierter Benutzer gefunden');
|
||||
|
||||
@@ -186,6 +186,7 @@ export const UserSchema = z
|
||||
updated: z.date().optional().nullable(),
|
||||
subscriptionId: z.string().optional().nullable(),
|
||||
subscriptionPlan: SubscriptionTypeEnum.optional().nullable(),
|
||||
showInDirectory: z.boolean(),
|
||||
})
|
||||
.superRefine((data, ctx) => {
|
||||
if (data.customerType === 'professional') {
|
||||
@@ -233,7 +234,7 @@ export const UserSchema = z
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: 'Company location is required for professional customers',
|
||||
path: ['companyLocation'],
|
||||
path: ['location'],
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,10 @@ export class UserService {
|
||||
if (criteria.state) {
|
||||
whereConditions.push(sql`EXISTS (SELECT 1 FROM jsonb_array_elements(${schema.users.areasServed}) AS area WHERE area->>'state' = ${criteria.state})`);
|
||||
}
|
||||
|
||||
//never show user which denied
|
||||
whereConditions.push(eq(schema.users.showInDirectory, true))
|
||||
|
||||
return whereConditions;
|
||||
}
|
||||
async searchUserListings(criteria: UserListingCriteria): Promise<{ results: User[]; totalCount: number }> {
|
||||
@@ -59,7 +63,7 @@ export class UserService {
|
||||
const length = criteria.length ? criteria.length : 12;
|
||||
const query = this.conn.select().from(schema.users);
|
||||
const whereConditions = this.getWhereConditions(criteria);
|
||||
|
||||
|
||||
if (whereConditions.length > 0) {
|
||||
const whereClause = and(...whereConditions);
|
||||
query.where(whereClause);
|
||||
|
||||
Reference in New Issue
Block a user