bizmatch-project/bizmatch-server/src/models/main.model.ts

212 lines
4.4 KiB
TypeScript

import { BusinessListing, CommercialPropertyListing, User } from './db.model';
export interface StatesResult {
state: string;
count: number;
}
export interface KeyValue {
name: string;
value: string;
}
export interface KeyValueRatio {
label: string;
value: number;
}
export interface KeyValueStyle {
name: string;
value: string;
icon: string;
bgColorClass: string;
textColorClass: string;
}
export type SelectOption<T = number> = {
value: T;
label: string;
};
export type ImageType = {
name: 'propertyPicture' | 'companyLogo' | 'profile';
upload: string;
delete: string;
};
export type ListingCategory = {
name: 'business' | 'commercialProperty';
};
export type ListingType = BusinessListing | CommercialPropertyListing;
export type ResponseBusinessListingArray = {
data: BusinessListing[];
total: number;
};
export type ResponseBusinessListing = {
data: BusinessListing;
};
export type ResponseCommercialPropertyListingArray = {
data: CommercialPropertyListing[];
total: number;
};
export type ResponseCommercialPropertyListing = {
data: CommercialPropertyListing;
};
export type ResponseUsersArray = {
data: User[];
total: number;
};
export interface ListingCriteria {
start: number;
length: number;
page: number;
pageCount: number;
type: number;
state: string;
minPrice: number;
maxPrice: number;
realEstateChecked: boolean;
title: string;
category: 'professional' | 'broker';
name: string;
}
export interface KeycloakUser {
id: string;
createdTimestamp?: number;
username?: string;
enabled?: boolean;
totp?: boolean;
emailVerified?: boolean;
firstName: string;
lastName: string;
email: string;
disableableCredentialTypes?: any[];
requiredActions?: any[];
notBefore?: number;
access?: Access;
}
export interface JwtUser {
userId: string;
username: string;
roles: string[];
}
export interface Access {
manageGroupMembership: boolean;
view: boolean;
mapRoles: boolean;
impersonate: boolean;
manage: boolean;
}
export interface Subscription {
id: string;
userId: string;
level: string;
start: Date;
modified: Date;
end: Date;
status: string;
invoices: Array<Invoice>;
}
export interface Invoice {
id: string;
date: Date;
price: number;
}
export interface JwtToken {
exp: number;
iat: number;
auth_time: number;
jti: string;
iss: string;
aud: string;
sub: string;
typ: string;
azp: string;
nonce: string;
session_state: string;
acr: string;
realm_access: Realmaccess;
resource_access: Resourceaccess;
scope: string;
sid: string;
email_verified: boolean;
name: string;
preferred_username: string;
given_name: string;
family_name: string;
email: string;
user_id: string;
}
interface Resourceaccess {
account: Realmaccess;
}
interface Realmaccess {
roles: string[];
}
export interface PageEvent {
first: number;
rows: number;
page: number;
pageCount: number;
}
export interface AutoCompleteCompleteEvent {
originalEvent: Event;
query: string;
}
export interface MailInfo {
sender: Sender;
userId: string;
email: string;
url: string;
listing?: BusinessListing;
}
export interface Sender {
name?: string;
email?: string;
phoneNumber?: string;
state?: string;
comments?: string;
}
export interface ImageProperty {
id: string;
code: string;
name: string;
}
export interface ErrorResponse {
fields?: FieldError[];
general?: string[];
}
export interface FieldError {
fieldname: string;
message: string;
}
export function isEmpty(value: any): boolean {
// Check for undefined or null
if (value === undefined || value === null) {
return true;
}
// Check for empty string or string with only whitespace
if (typeof value === 'string') {
return value.trim().length === 0;
}
// Check for number and NaN
if (typeof value === 'number') {
return isNaN(value);
}
// If it's not a string or number, it's not considered empty by this function
return false;
}
export function emailToDirName(email: string): string {
// Entferne ungültige Zeichen und ersetze sie durch Unterstriche
const sanitizedEmail = email.replace(/[^a-zA-Z0-9_-]/g, '_');
// Entferne führende und nachfolgende Unterstriche
const trimmedEmail = sanitizedEmail.replace(/^_+|_+$/g, '');
// Ersetze mehrfache aufeinanderfolgende Unterstriche durch einen einzelnen Unterstrich
const normalizedEmail = trimmedEmail.replace(/_+/g, '_');
return normalizedEmail;
}