add embeddings, remove userId from business & commercialProperty replaced by email

This commit is contained in:
Andreas Knuth 2024-07-13 19:44:07 +02:00
parent bf4bd69337
commit b7b34dacab
17 changed files with 123 additions and 763 deletions

View File

@ -1,34 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("dotenv/config");
var node_postgres_1 = require("drizzle-orm/node-postgres");
var pg_1 = require("pg");
var Client = pg_1.default.Client;
var schema = require("./schema.js");
var fs_1 = require("fs");
var connectionString = process.env.DATABASE_URL;
// const pool = new Pool({connectionString})
var client = new Client({ connectionString: connectionString });
var db = (0, node_postgres_1.drizzle)(client, { schema: schema, logger: true });
//Broker
var filePath = "./data/broker.json";
var data = (0, fs_1.readFileSync)(filePath, 'utf8');
var jsonData = JSON.parse(data); // Erwartet ein Array von Objekten
await db.delete(schema.users);
console.log(jsonData.length);
for (var _i = 0, jsonData_1 = jsonData; _i < jsonData_1.length; _i++) {
var user = jsonData_1[_i];
delete user.id;
await db.insert(schema.users).values(user);
}
//Business Listings
// filePath = `./data/businesses.json`
// data = readFileSync(filePath, 'utf8');
// jsonData = JSON.parse(data); // Erwartet ein Array von Objekten
// db.delete(schema.businesses);
// for (const business of jsonData) {
// delete business.id
// await db.insert(schema.businesses).values(business);
// }
//End
//await client.end()

View File

@ -7,6 +7,7 @@ import { join } from 'path';
import pkg from 'pg';
import { rimraf } from 'rimraf';
import sharp from 'sharp';
import winston from 'winston';
import { BusinessListing, CommercialPropertyListing, User, UserData } from '../models/db.model.js';
import { emailToDirName, KeyValueStyle } from '../models/main.model.js';
import * as schema from './schema.js';
@ -35,7 +36,9 @@ const connectionString = process.env.DATABASE_URL;
// const pool = new Pool({connectionString})
const client = new Pool({ connectionString });
const db = drizzle(client, { schema, logger: true });
const logger = winston.createLogger({
transports: [new winston.transports.Console()],
});
//Delete Content
await db.delete(schema.commercials);
await db.delete(schema.businesses);
@ -59,7 +62,10 @@ deleteFilesOfDir(targetPathProperty);
fs.ensureDirSync(`./pictures/logo`);
fs.ensureDirSync(`./pictures/profile`);
fs.ensureDirSync(`./pictures/property`);
for (const userData of usersData) {
type UserProfile = Omit<User, 'created' | 'updated' | 'hasCompanyLogo' | 'hasProfile' | 'id'>;
//for (const userData of usersData) {
for (let index = 0; index < usersData.length; index++) {
const userData = usersData[index];
const user: User = { firstname: '', lastname: '', email: '' };
user.licensedIn = [];
userData.licensedIn.forEach(l => {
@ -87,7 +93,22 @@ for (const userData of usersData) {
user.customerSubType = 'broker';
user.created = new Date();
user.updated = new Date();
const u = await db.insert(schema.users).values(user).returning({ insertedId: schema.users.id, gender: schema.users.gender, email: schema.users.email });
const createUserProfile = (user: User): UserProfile => {
const { id, created, updated, hasCompanyLogo, hasProfile, ...userProfile } = user;
return userProfile;
};
const userProfile = createUserProfile(user);
logger.info(`${index} - ${JSON.stringify(userProfile)}`);
const embedding = await createEmbedding(JSON.stringify(userProfile));
sleep(500);
const u = await db
.insert(schema.users)
.values({
...user,
embedding: embedding,
})
.returning({ insertedId: schema.users.id, gender: schema.users.gender, email: schema.users.email });
// const u = await db.insert(schema.users).values(user).returning({ insertedId: schema.users.id, gender: schema.users.gender, email: schema.users.email });
generatedUserData.push(u[0]);
i++;
@ -113,7 +134,7 @@ for (const business of businessJsonData) {
business.created = new Date(business.created);
business.updated = new Date(business.created);
const user = getRandomItem(generatedUserData);
business.userId = user.insertedId;
business.email = user.email;
business.imageName = emailToDirName(user.email);
const embeddingText = JSON.stringify({
type: typesOfBusiness.find(b => b.value === String(business.type))?.name,
@ -133,6 +154,7 @@ for (const business of businessJsonData) {
reasonForSale: business.reasonForSale,
});
const embedding = await createEmbedding(embeddingText);
sleep(300);
await db.insert(schema.businesses).values({
...business,
embedding: embedding,
@ -151,10 +173,9 @@ for (const commercial of commercialJsonData) {
const insertionDate = getRandomDateWithinLastYear();
commercial.created = insertionDate;
commercial.updated = insertionDate;
commercial.userId = user.insertedId;
commercial.email = user.email;
commercial.draft = false;
const result = await db.insert(schema.commercials).values(commercial).returning();
//fs.ensureDirSync(`./pictures/property/${result[0].imagePath}/${result[0].serialId}`);
try {
fs.copySync(`./pictures_base/property/${id}`, `./pictures/property/${result[0].imagePath}/${result[0].serialId}`);
} catch (err) {
@ -165,6 +186,9 @@ for (const commercial of commercialJsonData) {
//End
await client.end();
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function createEmbedding(text: string): Promise<number[]> {
const response = await openai.embeddings.create({
model: 'text-embedding-3-small',

View File

@ -1,24 +1,24 @@
DO $$ BEGIN
CREATE TYPE "customerSubType" AS ENUM('broker', 'cpa', 'attorney', 'titleCompany', 'surveyor', 'appraiser');
CREATE TYPE "public"."customerSubType" AS ENUM('broker', 'cpa', 'attorney', 'titleCompany', 'surveyor', 'appraiser');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "customerType" AS ENUM('buyer', 'professional');
CREATE TYPE "public"."customerType" AS ENUM('buyer', 'professional');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "gender" AS ENUM('male', 'female');
CREATE TYPE "public"."gender" AS ENUM('male', 'female');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "businesses" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"userId" uuid,
"email" varchar(255),
"type" integer,
"title" varchar(255),
"description" text,
@ -44,13 +44,14 @@ CREATE TABLE IF NOT EXISTS "businesses" (
"created" timestamp,
"updated" timestamp,
"visits" integer,
"lastVisit" timestamp
"lastVisit" timestamp,
"embedding" vector(1536)
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "commercials" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"serial_id" serial NOT NULL,
"userId" uuid,
"email" varchar(255),
"type" integer,
"title" varchar(255),
"description" text,
@ -63,15 +64,13 @@ CREATE TABLE IF NOT EXISTS "commercials" (
"draft" boolean,
"zipCode" integer,
"county" varchar(255),
"email" varchar(255),
"website" varchar(255),
"phoneNumber" varchar(255),
"imageOrder" varchar(200)[],
"imagePath" varchar(200),
"created" timestamp,
"updated" timestamp,
"visits" integer,
"lastVisit" timestamp
"lastVisit" timestamp,
"embedding" vector(1536)
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "users" (
@ -94,17 +93,19 @@ CREATE TABLE IF NOT EXISTS "users" (
"customerType" "customerType",
"customerSubType" "customerSubType",
"created" timestamp,
"updated" timestamp
"updated" timestamp,
"embedding" vector(1536),
CONSTRAINT "users_email_unique" UNIQUE("email")
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "businesses" ADD CONSTRAINT "businesses_userId_users_id_fk" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE no action ON UPDATE no action;
ALTER TABLE "businesses" ADD CONSTRAINT "businesses_email_users_email_fk" FOREIGN KEY ("email") REFERENCES "public"."users"("email") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "commercials" ADD CONSTRAINT "commercials_userId_users_id_fk" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE no action ON UPDATE no action;
ALTER TABLE "commercials" ADD CONSTRAINT "commercials_email_users_email_fk" FOREIGN KEY ("email") REFERENCES "public"."users"("email") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;

View File

@ -1 +0,0 @@
ALTER TABLE "businesses" ADD COLUMN "embedding" vector(1536);

View File

@ -1,4 +1,6 @@
{
"id": "2d8edad3-5544-4cb1-a543-84c07737ea9f",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
"tables": {
@ -13,9 +15,9 @@
"notNull": true,
"default": "gen_random_uuid()"
},
"userId": {
"name": "userId",
"type": "uuid",
"email": {
"name": "email",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
@ -174,22 +176,28 @@
"type": "timestamp",
"primaryKey": false,
"notNull": false
},
"embedding": {
"name": "embedding",
"type": "vector(1536)",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"businesses_userId_users_id_fk": {
"name": "businesses_userId_users_id_fk",
"businesses_email_users_email_fk": {
"name": "businesses_email_users_email_fk",
"tableFrom": "businesses",
"columnsFrom": [
"userId"
],
"tableTo": "users",
"columnsTo": [
"id"
"columnsFrom": [
"email"
],
"onUpdate": "no action",
"onDelete": "no action"
"columnsTo": [
"email"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
@ -212,9 +220,9 @@
"primaryKey": false,
"notNull": true
},
"userId": {
"name": "userId",
"type": "uuid",
"email": {
"name": "email",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
@ -290,24 +298,6 @@
"primaryKey": false,
"notNull": false
},
"email": {
"name": "email",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"website": {
"name": "website",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"phoneNumber": {
"name": "phoneNumber",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"imageOrder": {
"name": "imageOrder",
"type": "varchar(200)[]",
@ -343,22 +333,28 @@
"type": "timestamp",
"primaryKey": false,
"notNull": false
},
"embedding": {
"name": "embedding",
"type": "vector(1536)",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"commercials_userId_users_id_fk": {
"name": "commercials_userId_users_id_fk",
"commercials_email_users_email_fk": {
"name": "commercials_email_users_email_fk",
"tableFrom": "commercials",
"columnsFrom": [
"userId"
],
"tableTo": "users",
"columnsTo": [
"id"
"columnsFrom": [
"email"
],
"onUpdate": "no action",
"onDelete": "no action"
"columnsTo": [
"email"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
@ -462,18 +458,21 @@
"gender": {
"name": "gender",
"type": "gender",
"typeSchema": "public",
"primaryKey": false,
"notNull": false
},
"customerType": {
"name": "customerType",
"type": "customerType",
"typeSchema": "public",
"primaryKey": false,
"notNull": false
},
"customerSubType": {
"name": "customerSubType",
"type": "customerSubType",
"typeSchema": "public",
"primaryKey": false,
"notNull": false
},
@ -488,12 +487,26 @@
"type": "timestamp",
"primaryKey": false,
"notNull": false
},
"embedding": {
"name": "embedding",
"type": "vector(1536)",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
"uniqueConstraints": {
"users_email_unique": {
"name": "users_email_unique",
"nullsNotDistinct": false,
"columns": [
"email"
]
}
}
}
},
"enums": {
@ -527,11 +540,10 @@
}
},
"schemas": {},
"sequences": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {},
"columns": {}
},
"id": "f8241dfe-8f15-4656-aeb5-c9ef0ad65f28",
"prevId": "00000000-0000-0000-0000-000000000000"
"tables": {}
}
}

View File

@ -1,547 +0,0 @@
{
"id": "aac13d99-fd8d-44f9-bfb0-f00cef85809d",
"prevId": "f8241dfe-8f15-4656-aeb5-c9ef0ad65f28",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.businesses": {
"name": "businesses",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"userId": {
"name": "userId",
"type": "uuid",
"primaryKey": false,
"notNull": false
},
"type": {
"name": "type",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"title": {
"name": "title",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false
},
"city": {
"name": "city",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"state": {
"name": "state",
"type": "char(2)",
"primaryKey": false,
"notNull": false
},
"price": {
"name": "price",
"type": "double precision",
"primaryKey": false,
"notNull": false
},
"favoritesForUser": {
"name": "favoritesForUser",
"type": "varchar(30)[]",
"primaryKey": false,
"notNull": false
},
"draft": {
"name": "draft",
"type": "boolean",
"primaryKey": false,
"notNull": false
},
"listingsCategory": {
"name": "listingsCategory",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"realEstateIncluded": {
"name": "realEstateIncluded",
"type": "boolean",
"primaryKey": false,
"notNull": false
},
"leasedLocation": {
"name": "leasedLocation",
"type": "boolean",
"primaryKey": false,
"notNull": false
},
"franchiseResale": {
"name": "franchiseResale",
"type": "boolean",
"primaryKey": false,
"notNull": false
},
"salesRevenue": {
"name": "salesRevenue",
"type": "double precision",
"primaryKey": false,
"notNull": false
},
"cashFlow": {
"name": "cashFlow",
"type": "double precision",
"primaryKey": false,
"notNull": false
},
"supportAndTraining": {
"name": "supportAndTraining",
"type": "text",
"primaryKey": false,
"notNull": false
},
"employees": {
"name": "employees",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"established": {
"name": "established",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"internalListingNumber": {
"name": "internalListingNumber",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"reasonForSale": {
"name": "reasonForSale",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"brokerLicencing": {
"name": "brokerLicencing",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"internals": {
"name": "internals",
"type": "text",
"primaryKey": false,
"notNull": false
},
"imagePath": {
"name": "imagePath",
"type": "varchar(200)",
"primaryKey": false,
"notNull": false
},
"created": {
"name": "created",
"type": "timestamp",
"primaryKey": false,
"notNull": false
},
"updated": {
"name": "updated",
"type": "timestamp",
"primaryKey": false,
"notNull": false
},
"visits": {
"name": "visits",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"lastVisit": {
"name": "lastVisit",
"type": "timestamp",
"primaryKey": false,
"notNull": false
},
"embedding": {
"name": "embedding",
"type": "vector(1536)",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"businesses_userId_users_id_fk": {
"name": "businesses_userId_users_id_fk",
"tableFrom": "businesses",
"tableTo": "users",
"columnsFrom": [
"userId"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.commercials": {
"name": "commercials",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"serial_id": {
"name": "serial_id",
"type": "serial",
"primaryKey": false,
"notNull": true
},
"userId": {
"name": "userId",
"type": "uuid",
"primaryKey": false,
"notNull": false
},
"type": {
"name": "type",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"title": {
"name": "title",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false
},
"city": {
"name": "city",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"state": {
"name": "state",
"type": "char(2)",
"primaryKey": false,
"notNull": false
},
"price": {
"name": "price",
"type": "double precision",
"primaryKey": false,
"notNull": false
},
"favoritesForUser": {
"name": "favoritesForUser",
"type": "varchar(30)[]",
"primaryKey": false,
"notNull": false
},
"listingsCategory": {
"name": "listingsCategory",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"hideImage": {
"name": "hideImage",
"type": "boolean",
"primaryKey": false,
"notNull": false
},
"draft": {
"name": "draft",
"type": "boolean",
"primaryKey": false,
"notNull": false
},
"zipCode": {
"name": "zipCode",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"county": {
"name": "county",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"email": {
"name": "email",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"website": {
"name": "website",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"phoneNumber": {
"name": "phoneNumber",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"imageOrder": {
"name": "imageOrder",
"type": "varchar(200)[]",
"primaryKey": false,
"notNull": false
},
"imagePath": {
"name": "imagePath",
"type": "varchar(200)",
"primaryKey": false,
"notNull": false
},
"created": {
"name": "created",
"type": "timestamp",
"primaryKey": false,
"notNull": false
},
"updated": {
"name": "updated",
"type": "timestamp",
"primaryKey": false,
"notNull": false
},
"visits": {
"name": "visits",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"lastVisit": {
"name": "lastVisit",
"type": "timestamp",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"commercials_userId_users_id_fk": {
"name": "commercials_userId_users_id_fk",
"tableFrom": "commercials",
"tableTo": "users",
"columnsFrom": [
"userId"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.users": {
"name": "users",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"firstname": {
"name": "firstname",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"lastname": {
"name": "lastname",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"email": {
"name": "email",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"phoneNumber": {
"name": "phoneNumber",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false
},
"companyName": {
"name": "companyName",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"companyOverview": {
"name": "companyOverview",
"type": "text",
"primaryKey": false,
"notNull": false
},
"companyWebsite": {
"name": "companyWebsite",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"companyLocation": {
"name": "companyLocation",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"offeredServices": {
"name": "offeredServices",
"type": "text",
"primaryKey": false,
"notNull": false
},
"areasServed": {
"name": "areasServed",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"hasProfile": {
"name": "hasProfile",
"type": "boolean",
"primaryKey": false,
"notNull": false
},
"hasCompanyLogo": {
"name": "hasCompanyLogo",
"type": "boolean",
"primaryKey": false,
"notNull": false
},
"licensedIn": {
"name": "licensedIn",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"gender": {
"name": "gender",
"type": "gender",
"typeSchema": "public",
"primaryKey": false,
"notNull": false
},
"customerType": {
"name": "customerType",
"type": "customerType",
"typeSchema": "public",
"primaryKey": false,
"notNull": false
},
"customerSubType": {
"name": "customerSubType",
"type": "customerSubType",
"typeSchema": "public",
"primaryKey": false,
"notNull": false
},
"created": {
"name": "created",
"type": "timestamp",
"primaryKey": false,
"notNull": false
},
"updated": {
"name": "updated",
"type": "timestamp",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {
"public.customerSubType": {
"name": "customerSubType",
"schema": "public",
"values": [
"broker",
"cpa",
"attorney",
"titleCompany",
"surveyor",
"appraiser"
]
},
"public.customerType": {
"name": "customerType",
"schema": "public",
"values": [
"buyer",
"professional"
]
},
"public.gender": {
"name": "gender",
"schema": "public",
"values": [
"male",
"female"
]
}
},
"schemas": {},
"sequences": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}

View File

@ -1,19 +1,12 @@
{
"version": "5",
"dialect": "pg",
"version": "7",
"dialect": "postgresql",
"entries": [
{
"idx": 0,
"version": "5",
"when": 1717933164279,
"tag": "0000_known_havok",
"breakpoints": true
},
{
"idx": 1,
"version": "7",
"when": 1720777203223,
"tag": "0001_eager_sandman",
"when": 1720872296432,
"tag": "0000_slim_nova",
"breakpoints": true
}
]

View File

@ -1,75 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.commercials = exports.businesses = exports.users = exports.PG_CONNECTION = void 0;
var pg_core_1 = require("drizzle-orm/pg-core");
exports.PG_CONNECTION = 'PG_CONNECTION';
exports.users = (0, pg_core_1.pgTable)('users', {
id: (0, pg_core_1.uuid)('id').primaryKey().defaultRandom(),
firstname: (0, pg_core_1.varchar)('firstname', { length: 255 }).notNull(),
lastname: (0, pg_core_1.varchar)('lastname', { length: 255 }).notNull(),
email: (0, pg_core_1.varchar)('email', { length: 255 }).notNull(),
phoneNumber: (0, pg_core_1.varchar)('phoneNumber', { length: 255 }),
description: (0, pg_core_1.text)('description'),
companyName: (0, pg_core_1.varchar)('companyName', { length: 255 }),
companyOverview: (0, pg_core_1.text)('companyOverview'),
companyWebsite: (0, pg_core_1.varchar)('companyWebsite', { length: 255 }),
companyLocation: (0, pg_core_1.varchar)('companyLocation', { length: 255 }),
offeredServices: (0, pg_core_1.text)('offeredServices'),
areasServed: (0, pg_core_1.varchar)('areasServed', { length: 100 }).array(),
hasProfile: (0, pg_core_1.boolean)('hasProfile'),
hasCompanyLogo: (0, pg_core_1.boolean)('hasCompanyLogo'),
licensedIn: (0, pg_core_1.varchar)('licensedIn', { length: 50 }).array(),
});
exports.businesses = (0, pg_core_1.pgTable)('businesses', {
id: (0, pg_core_1.uuid)('id').primaryKey().defaultRandom(),
userId: (0, pg_core_1.uuid)('userId').references(function () { return exports.users.id; }),
type: (0, pg_core_1.varchar)('type', { length: 255 }),
title: (0, pg_core_1.varchar)('title', { length: 255 }),
description: (0, pg_core_1.text)('description'),
city: (0, pg_core_1.varchar)('city', { length: 255 }),
state: (0, pg_core_1.char)('state', { length: 2 }),
price: (0, pg_core_1.numeric)('price', { precision: 10, scale: 2 }),
favoritesForUser: (0, pg_core_1.varchar)('favoritesForUser', { length: 30 }).array(),
draft: (0, pg_core_1.boolean)('draft'),
listingsCategory: (0, pg_core_1.varchar)('listingsCategory', { length: 255 }),
realEstateIncluded: (0, pg_core_1.boolean)('realEstateIncluded'),
leasedLocation: (0, pg_core_1.boolean)('leasedLocation'),
franchiseResale: (0, pg_core_1.boolean)('franchiseResale'),
salesRevenue: (0, pg_core_1.numeric)('salesRevenue', { precision: 10, scale: 2 }),
cashFlow: (0, pg_core_1.numeric)('cashFlow', { precision: 10, scale: 2 }),
supportAndTraining: (0, pg_core_1.text)('supportAndTraining'),
employees: (0, pg_core_1.integer)('employees'),
established: (0, pg_core_1.integer)('established'),
internalListingNumber: (0, pg_core_1.integer)('internalListingNumber'),
reasonForSale: (0, pg_core_1.varchar)('reasonForSale', { length: 255 }),
brokerLicencing: (0, pg_core_1.varchar)('brokerLicencing', { length: 255 }),
internals: (0, pg_core_1.text)('internals'),
created: (0, pg_core_1.timestamp)('created'),
updated: (0, pg_core_1.timestamp)('updated'),
visits: (0, pg_core_1.integer)('visits'),
lastVisit: (0, pg_core_1.timestamp)('lastVisit'),
});
exports.commercials = (0, pg_core_1.pgTable)('commercials', {
id: (0, pg_core_1.uuid)('id').primaryKey().defaultRandom(),
userId: (0, pg_core_1.uuid)('userId').references(function () { return exports.users.id; }),
type: (0, pg_core_1.varchar)('type', { length: 255 }),
title: (0, pg_core_1.varchar)('title', { length: 255 }),
description: (0, pg_core_1.text)('description'),
city: (0, pg_core_1.varchar)('city', { length: 255 }),
state: (0, pg_core_1.char)('state', { length: 2 }),
price: (0, pg_core_1.numeric)('price', { precision: 10, scale: 2 }),
favoritesForUser: (0, pg_core_1.varchar)('favoritesForUser', { length: 30 }).array(),
hideImage: (0, pg_core_1.boolean)('hideImage'),
draft: (0, pg_core_1.boolean)('draft'),
zipCode: (0, pg_core_1.integer)('zipCode'),
county: (0, pg_core_1.varchar)('county', { length: 255 }),
email: (0, pg_core_1.varchar)('email', { length: 255 }),
website: (0, pg_core_1.varchar)('website', { length: 255 }),
phoneNumber: (0, pg_core_1.varchar)('phoneNumber', { length: 255 }),
imageOrder: (0, pg_core_1.varchar)('imageOrder', { length: 30 }).array(),
imagePath: (0, pg_core_1.varchar)('imagePath', { length: 30 }).array(),
created: (0, pg_core_1.timestamp)('created'),
updated: (0, pg_core_1.timestamp)('updated'),
visits: (0, pg_core_1.integer)('visits'),
lastVisit: (0, pg_core_1.timestamp)('lastVisit'),
});

View File

@ -9,7 +9,7 @@ export const users = pgTable('users', {
id: uuid('id').primaryKey().defaultRandom(),
firstname: varchar('firstname', { length: 255 }).notNull(),
lastname: varchar('lastname', { length: 255 }).notNull(),
email: varchar('email', { length: 255 }).notNull(),
email: varchar('email', { length: 255 }).notNull().unique(),
phoneNumber: varchar('phoneNumber', { length: 255 }),
description: text('description'),
companyName: varchar('companyName', { length: 255 }),
@ -26,11 +26,12 @@ export const users = pgTable('users', {
customerSubType: customerSubTypeEnum('customerSubType'),
created: timestamp('created'),
updated: timestamp('updated'),
embedding: vector('embedding', { dimensions: 1536 }),
});
export const businesses = pgTable('businesses', {
id: uuid('id').primaryKey().defaultRandom(),
userId: uuid('userId').references(() => users.id),
email: varchar('email', { length: 255 }).references(() => users.email),
type: integer('type'),
title: varchar('title', { length: 255 }),
description: text('description'),
@ -59,13 +60,12 @@ export const businesses = pgTable('businesses', {
lastVisit: timestamp('lastVisit'),
// Neue Spalte für das OpenAI Embedding
embedding: vector('embedding', { dimensions: 1536 }),
// embedding: sql`vector(1536)`,
});
export const commercials = pgTable('commercials', {
id: uuid('id').primaryKey().defaultRandom(),
serialId: serial('serial_id'),
userId: uuid('userId').references(() => users.id),
email: varchar('email', { length: 255 }).references(() => users.email),
type: integer('type'),
title: varchar('title', { length: 255 }),
description: text('description'),
@ -78,13 +78,11 @@ export const commercials = pgTable('commercials', {
draft: boolean('draft'),
zipCode: integer('zipCode'),
county: varchar('county', { length: 255 }),
email: varchar('email', { length: 255 }),
website: varchar('website', { length: 255 }),
phoneNumber: varchar('phoneNumber', { length: 255 }),
imageOrder: varchar('imageOrder', { length: 200 }).array(),
imagePath: varchar('imagePath', { length: 200 }),
created: timestamp('created'),
updated: timestamp('updated'),
visits: integer('visits'),
lastVisit: timestamp('lastVisit'),
embedding: vector('embedding', { dimensions: 1536 }),
});

View File

@ -44,7 +44,7 @@ export interface UserData {
}
export interface BusinessListing {
id: string;
userId?: string;
email?: string;
type?: number;
title?: string;
description?: string;
@ -76,7 +76,7 @@ export interface BusinessListing {
export interface CommercialPropertyListing {
id: string;
serialId?: number;
userId?: string;
email?: string;
type?: number;
title?: string;
description?: string;
@ -88,9 +88,6 @@ export interface CommercialPropertyListing {
draft?: boolean;
zipCode?: number;
county?: string;
email?: string;
website?: string;
phoneNumber?: string;
imageOrder?: string[];
imagePath?: string;
created?: Date;

View File

@ -160,7 +160,6 @@ export interface AutoCompleteCompleteEvent {
}
export interface MailInfo {
sender: Sender;
userId: string;
email: string;
url: string;
listing?: BusinessListing;

View File

@ -69,7 +69,7 @@ export class DetailsBusinessListingComponent {
this.history.push(event.urlAfterRedirects);
}
});
this.mailinfo = { sender: {}, userId: '', email: '', url: environment.mailinfoUrl };
this.mailinfo = { sender: {}, email: '', url: environment.mailinfoUrl };
this.criteria = onChange(getCriteriaStateObject(), getSessionStorageHandler);
}
@ -81,7 +81,7 @@ export class DetailsBusinessListingComponent {
this.mailinfo.sender = { name: `${this.user.firstname} ${this.user.lastname}`, email: this.user.email, phoneNumber: this.user.phoneNumber, state: this.user.companyLocation };
}
this.listing = await lastValueFrom(this.listingsService.getListingById(this.id, 'business'));
this.listingUser = await this.userService.getById(this.listing.userId);
this.listingUser = await this.userService.getByMail(this.listing.email);
this.description = this.sanitizer.bypassSecurityTrustHtml(this.listing.description);
}
@ -90,7 +90,6 @@ export class DetailsBusinessListingComponent {
}
async mail() {
this.mailinfo.email = this.listingUser.email;
this.mailinfo.userId = this.listing.userId;
this.mailinfo.listing = this.listing;
await this.mailService.mail(this.mailinfo);
// this.messageService.add({ severity: 'info', summary: 'Confirmed', detail: 'Your message has been sent to the creator of the listing', life: 3000 });

View File

@ -71,7 +71,7 @@ export class DetailsCommercialPropertyListingComponent {
private imageService: ImageService,
private ngZone: NgZone,
) {
this.mailinfo = { sender: {}, userId: '', email: '', url: environment.mailinfoUrl };
this.mailinfo = { sender: {}, email: '', url: environment.mailinfoUrl };
this.criteria = onChange(getCriteriaStateObject(), getSessionStorageHandler);
}
@ -84,7 +84,7 @@ export class DetailsCommercialPropertyListingComponent {
this.mailinfo.sender = { name: `${this.user.firstname} ${this.user.lastname}`, email: this.user.email, phoneNumber: this.user.phoneNumber, state: this.user.companyLocation };
}
this.listing = await lastValueFrom(this.listingsService.getListingById(this.id, 'commercialProperty'));
this.listingUser = await this.userService.getById(this.listing.userId);
this.listingUser = await this.userService.getByMail(this.listing.email);
this.description = this.sanitizer.bypassSecurityTrustHtml(this.listing.description);
import('flowbite').then(flowbite => {
flowbite.initCarousels();
@ -113,7 +113,6 @@ export class DetailsCommercialPropertyListingComponent {
}
async mail() {
this.mailinfo.email = this.listingUser.email;
this.mailinfo.userId = this.listing.userId;
this.mailinfo.listing = this.listing;
const result = await this.mailService.mail(this.mailinfo);
if (result) {

View File

@ -85,7 +85,7 @@ export class EditBusinessListingComponent {
} else {
this.listing = createDefaultBusinessListing();
const listingUser = await this.userService.getByMail(keycloakUser.email);
this.listing.userId = listingUser.id;
this.listing.email = listingUser.email;
this.listing.imageName = emailToDirName(keycloakUser.email);
if (this.data) {
this.listing.title = this.data?.title;

View File

@ -36,7 +36,6 @@ import { TOOLBAR_OPTIONS } from '../../utils/defaults';
styleUrl: './edit-commercial-property-listing.component.scss',
})
export class EditCommercialPropertyListingComponent {
// @ViewChild(FileUpload) public fileUpload: FileUpload;
@ViewChild('fileInput') fileInput!: ElementRef<HTMLInputElement>;
listingsCategory = 'commercialProperty';
@ -125,7 +124,7 @@ export class EditCommercialPropertyListingComponent {
} else {
this.listing = createDefaultCommercialPropertyListing();
const listingUser = await this.userService.getByMail(keycloakUser.email);
this.listing.userId = listingUser.id;
this.listing.email = listingUser.email;
this.listing.imagePath = `${emailToDirName(keycloakUser.email)}`;
if (this.data) {
this.listing.title = this.data?.title;

View File

@ -22,7 +22,7 @@ export class EmailUsComponent {
user: User;
errorResponse: ErrorResponse;
constructor(private mailService: MailService, private userService: UserService, public keycloakService: KeycloakService) {
this.mailinfo = { sender: {}, userId: '', email: '', url: environment.mailinfoUrl };
this.mailinfo = { sender: {}, email: '', url: environment.mailinfoUrl };
}
async ngOnInit() {
const token = await this.keycloakService.getToken();

View File

@ -31,7 +31,7 @@ export function createDefaultUser(email: string, firstname: string, lastname: st
export function createDefaultCommercialPropertyListing(): CommercialPropertyListing {
return {
id: undefined,
userId: '',
email: '',
type: null,
title: '',
description: '',
@ -43,9 +43,6 @@ export function createDefaultCommercialPropertyListing(): CommercialPropertyList
draft: false,
zipCode: null,
county: '',
email: '',
website: '',
phoneNumber: '',
imageOrder: [],
imagePath: '',
created: null,
@ -58,7 +55,6 @@ export function createDefaultCommercialPropertyListing(): CommercialPropertyList
export function createDefaultBusinessListing(): BusinessListing {
return {
id: undefined,
userId: '',
type: null,
title: '',
description: '',