diverse BugFixes

This commit is contained in:
2024-08-12 17:18:32 +02:00
parent 3a6a64cce9
commit ec0576e7b8
17 changed files with 118 additions and 100 deletions

View File

@@ -102,7 +102,7 @@ const USStates = z.enum([
'WY',
]);
export const AreasServedSchema = z.object({
county: z.string().nonempty('County is required'),
county: z.string().optional().nullable(),
state: z.string().nonempty('State is required'),
});

View File

@@ -92,8 +92,7 @@ export interface CommercialPropertyListingCriteria extends ListCriteria {
criteriaType: 'commercialPropertyListings';
}
export interface UserListingCriteria extends ListCriteria {
firstname: string;
lastname: string;
brokerName: string;
companyName: string;
counties: string[];
criteriaType: 'brokerListings';

View File

@@ -10,7 +10,7 @@ import { FileService } from '../file/file.service.js';
import { GeoService } from '../geo/geo.service.js';
import { User, UserSchema } from '../models/db.model.js';
import { createDefaultUser, emailToDirName, JwtUser, UserListingCriteria } from '../models/main.model.js';
import { convertDrizzleUserToUser, convertUserToDrizzleUser, getDistanceQuery } from '../utils.js';
import { convertDrizzleUserToUser, convertUserToDrizzleUser, getDistanceQuery, splitName } from '../utils.js';
type CustomerSubType = (typeof customerSubTypeEnum.enumValues)[number];
@Injectable()
@@ -37,12 +37,9 @@ export class UserService {
whereConditions.push(inArray(schema.users.customerSubType, criteria.types as CustomerSubType[]));
}
if (criteria.firstname) {
whereConditions.push(ilike(schema.users.firstname, `%${criteria.firstname}%`));
}
if (criteria.lastname) {
whereConditions.push(ilike(schema.users.lastname, `%${criteria.lastname}%`));
if (criteria.brokerName) {
const { firstname, lastname } = splitName(criteria.brokerName);
whereConditions.push(or(ilike(schema.users.firstname, `%${firstname}%`), ilike(schema.users.lastname, `%${lastname}%`)));
}
if (criteria.companyName) {

View File

@@ -139,3 +139,16 @@ function unflattenObject(obj: any, separator: string = '_'): any {
return result;
}
export function splitName(fullName: string): { firstname: string; lastname: string } {
const parts = fullName.trim().split(/\s+/); // Teile den Namen am Leerzeichen auf
if (parts.length === 1) {
// Falls es nur ein Teil gibt, ist firstname und lastname gleich
return { firstname: parts[0], lastname: parts[0] };
} else {
// Ansonsten ist der letzte Teil der lastname, der Rest der firstname
const lastname = parts.pop()!;
const firstname = parts.join(' ');
return { firstname, lastname };
}
}