diverse BugFixes
This commit is contained in:
@@ -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'),
|
||||
});
|
||||
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user