Umbau zu location / companyLocation
This commit is contained in:
@@ -7,14 +7,53 @@ import { join } from 'path';
|
||||
import pkg from 'pg';
|
||||
import { rimraf } from 'rimraf';
|
||||
import sharp from 'sharp';
|
||||
import { BusinessListingService } from 'src/listings/business-listing.service.js';
|
||||
import { CommercialPropertyService } from 'src/listings/commercial-property.service.js';
|
||||
import { Geo } from 'src/models/server.model.js';
|
||||
import winston from 'winston';
|
||||
import { BusinessListing, CommercialPropertyListing, User, UserData } from '../models/db.model.js';
|
||||
import { createDefaultUser, emailToDirName, KeyValueStyle } from '../models/main.model.js';
|
||||
import { User, UserData } from '../models/db.model.js';
|
||||
import { createDefaultBusinessListing, createDefaultCommercialPropertyListing, createDefaultUser, emailToDirName, KeyValueStyle } from '../models/main.model.js';
|
||||
import { SelectOptionsService } from '../select-options/select-options.service.js';
|
||||
import { convertUserToDrizzleUser } from '../utils.js';
|
||||
import * as schema from './schema.js';
|
||||
|
||||
interface PropertyImportListing {
|
||||
id: string;
|
||||
userId: string;
|
||||
listingsCategory: 'commercialProperty';
|
||||
title: string;
|
||||
state: string;
|
||||
hasImages: boolean;
|
||||
price: number;
|
||||
city: string;
|
||||
description: string;
|
||||
type: number;
|
||||
imageOrder: any[];
|
||||
}
|
||||
interface BusinessImportListing {
|
||||
userId: string;
|
||||
listingsCategory: 'business';
|
||||
title: string;
|
||||
description: string;
|
||||
type: number;
|
||||
state: string;
|
||||
city: string;
|
||||
id: string;
|
||||
price: number;
|
||||
salesRevenue: number;
|
||||
leasedLocation: boolean;
|
||||
established: number;
|
||||
employees: number;
|
||||
reasonForSale: string;
|
||||
supportAndTraining: string;
|
||||
cashFlow: number;
|
||||
brokerLicencing: string;
|
||||
internalListingNumber: number;
|
||||
realEstateIncluded: boolean;
|
||||
franchiseResale: boolean;
|
||||
draft: boolean;
|
||||
internals: string;
|
||||
created: string;
|
||||
}
|
||||
const typesOfBusiness: Array<KeyValueStyle> = [
|
||||
{ name: 'Automotive', value: '1', icon: 'fa-solid fa-car', textColorClass: 'text-green-400' },
|
||||
{ name: 'Industrial Services', value: '2', icon: 'fa-solid fa-industry', textColorClass: 'text-yellow-400' },
|
||||
@@ -43,6 +82,8 @@ const db = drizzle(client, { schema, logger: true });
|
||||
const logger = winston.createLogger({
|
||||
transports: [new winston.transports.Console()],
|
||||
});
|
||||
const commService = new CommercialPropertyService(null, db);
|
||||
const businessService = new BusinessListingService(null, db);
|
||||
//Delete Content
|
||||
await db.delete(schema.commercials);
|
||||
await db.delete(schema.businesses);
|
||||
@@ -70,13 +111,11 @@ deleteFilesOfDir(targetPathProperty);
|
||||
fs.ensureDirSync(`./pictures/logo`);
|
||||
fs.ensureDirSync(`./pictures/profile`);
|
||||
fs.ensureDirSync(`./pictures/property`);
|
||||
// type UserProfile = Omit<User, 'created' | 'updated' | 'hasCompanyLogo' | 'hasProfile' | 'id'>;
|
||||
|
||||
// type NewUser = typeof users.$inferInsert;
|
||||
//for (const userData of usersData) {
|
||||
//User
|
||||
for (let index = 0; index < usersData.length; index++) {
|
||||
const userData = usersData[index];
|
||||
const user: User = createDefaultUser('', '', ''); //{ id: undefined, firstname: '', lastname: '', email: '' };
|
||||
const user: User = createDefaultUser('', '', '');
|
||||
user.licensedIn = [];
|
||||
userData.licensedIn.forEach(l => {
|
||||
console.log(l['value'], l['name']);
|
||||
@@ -133,89 +172,91 @@ for (let index = 0; index < usersData.length; index++) {
|
||||
//Corporate Listings
|
||||
filePath = `./data/commercials.json`;
|
||||
data = readFileSync(filePath, 'utf8');
|
||||
const commercialJsonData = JSON.parse(data) as CommercialPropertyListing[]; // Erwartet ein Array von Objekten
|
||||
const commercialJsonData = JSON.parse(data) as PropertyImportListing[]; // Erwartet ein Array von Objekten
|
||||
for (let index = 0; index < commercialJsonData.length; index++) {
|
||||
const commercial = commercialJsonData[index];
|
||||
const id = commercial.id;
|
||||
delete commercial.id;
|
||||
const user = getRandomItem(generatedUserData);
|
||||
const commercial = createDefaultCommercialPropertyListing();
|
||||
const id = commercialJsonData[index].id;
|
||||
delete commercial.id;
|
||||
|
||||
commercial.email = user.email;
|
||||
commercial.type = sso.typesOfCommercialProperty.find(e => e.oldValue === String(commercialJsonData[index].type)).value;
|
||||
commercial.title = commercialJsonData[index].title;
|
||||
commercial.description = commercialJsonData[index].description;
|
||||
try {
|
||||
const cityGeo = geos.states.find(s => s.state_code === commercialJsonData[index].state).cities.find(c => c.name === commercialJsonData[index].city);
|
||||
commercial.location = {};
|
||||
commercial.location.latitude = cityGeo.latitude;
|
||||
commercial.location.longitude = cityGeo.longitude;
|
||||
commercial.location.city = commercialJsonData[index].city;
|
||||
commercial.location.state = commercialJsonData[index].state;
|
||||
// console.log(JSON.stringify(commercial.location));
|
||||
} catch (e) {
|
||||
console.log(`----------------> ERROR ${commercialJsonData[index].state} - ${commercialJsonData[index].city}`);
|
||||
continue;
|
||||
}
|
||||
commercial.price = commercialJsonData[index].price;
|
||||
commercial.listingsCategory = 'commercialProperty';
|
||||
commercial.draft = false;
|
||||
commercial.imageOrder = getFilenames(id);
|
||||
commercial.imagePath = emailToDirName(user.email);
|
||||
const insertionDate = getRandomDateWithinLastYear();
|
||||
commercial.created = insertionDate;
|
||||
commercial.updated = insertionDate;
|
||||
commercial.email = user.email;
|
||||
commercial.draft = false;
|
||||
commercial.type = sso.typesOfCommercialProperty.find(e => e.oldValue === String(commercial.type)).value;
|
||||
const cityGeo = geos.states.find(s => s.state_code === commercial.state).cities.find(c => c.name === commercial.city);
|
||||
|
||||
const result = await commService.createListing(commercial); //await db.insert(schema.commercials).values(commercial).returning();
|
||||
try {
|
||||
commercial.latitude = cityGeo.latitude;
|
||||
commercial.longitude = cityGeo.longitude;
|
||||
} catch (e) {
|
||||
console.log(`----------------> ERROR ${commercial.state} - ${commercial.city}`);
|
||||
}
|
||||
// const reducedCommercial = {
|
||||
// city: commercial.city,
|
||||
// description: commercial.description,
|
||||
// email: commercial.email,
|
||||
// price: commercial.price,
|
||||
// state: sso.locations.find(l => l.value === commercial.state)?.name,
|
||||
// title: commercial.title,
|
||||
// name: `${user.firstname} ${user.lastname}`,
|
||||
// };
|
||||
// const embedding = await createEmbedding(JSON.stringify(reducedCommercial));
|
||||
// sleep(200);
|
||||
const result = await db.insert(schema.commercials).values(commercial).returning();
|
||||
// logger.info(`commercial_${index} inserted`);
|
||||
try {
|
||||
fs.copySync(`./pictures_base/property/${id}`, `./pictures/property/${result[0].imagePath}/${result[0].serialId}`);
|
||||
fs.copySync(`./pictures_base/property/${id}`, `./pictures/property/${result.imagePath}/${result.serialId}`);
|
||||
} catch (err) {
|
||||
console.log(`----- No pictures available for ${id} ------`);
|
||||
console.log(`----- No pictures available for ${id} ------ ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
//Business Listings
|
||||
filePath = `./data/businesses.json`;
|
||||
data = readFileSync(filePath, 'utf8');
|
||||
const businessJsonData = JSON.parse(data) as BusinessListing[]; // Erwartet ein Array von Objekten
|
||||
const businessJsonData = JSON.parse(data) as BusinessImportListing[]; // Erwartet ein Array von Objekten
|
||||
for (let index = 0; index < businessJsonData.length; index++) {
|
||||
const business = businessJsonData[index];
|
||||
const business = createDefaultBusinessListing(); //businessJsonData[index];
|
||||
delete business.id;
|
||||
business.type = sso.typesOfBusiness.find(e => e.oldValue === String(business.type)).value;
|
||||
business.created = new Date(business.created);
|
||||
business.updated = new Date(business.created);
|
||||
const user = getRandomItem(generatedUserData);
|
||||
business.email = user.email;
|
||||
business.imageName = emailToDirName(user.email);
|
||||
const cityGeo = geos.states.find(s => s.state_code === business.state).cities.find(c => c.name === business.city);
|
||||
business.type = sso.typesOfBusiness.find(e => e.oldValue === String(businessJsonData[index].type)).value;
|
||||
business.title = businessJsonData[index].title;
|
||||
business.description = businessJsonData[index].description;
|
||||
try {
|
||||
business.latitude = cityGeo.latitude;
|
||||
business.longitude = cityGeo.longitude;
|
||||
const cityGeo = geos.states.find(s => s.state_code === businessJsonData[index].state).cities.find(c => c.name === businessJsonData[index].city);
|
||||
business.location = {};
|
||||
business.location.latitude = cityGeo.latitude;
|
||||
business.location.longitude = cityGeo.longitude;
|
||||
business.location.city = businessJsonData[index].city;
|
||||
business.location.state = businessJsonData[index].state;
|
||||
} catch (e) {
|
||||
console.log(`----------------> ERROR ${business.state} - ${business.city}`);
|
||||
console.log(`----------------> ERROR ${businessJsonData[index].state} - ${businessJsonData[index].city}`);
|
||||
continue;
|
||||
}
|
||||
// const embeddingText = JSON.stringify({
|
||||
// type: typesOfBusiness.find(b => b.value === String(business.type))?.name,
|
||||
// title: business.title,
|
||||
// description: business.description,
|
||||
// email: business.email,
|
||||
// city: business.city,
|
||||
// state: sso.locations.find(l => l.value === business.state)?.name,
|
||||
// price: business.price,
|
||||
// realEstateIncluded: business.realEstateIncluded,
|
||||
// leasedLocation: business.leasedLocation,
|
||||
// franchiseResale: business.franchiseResale,
|
||||
// salesRevenue: business.salesRevenue,
|
||||
// cashFlow: business.cashFlow,
|
||||
// supportAndTraining: business.supportAndTraining,
|
||||
// employees: business.employees,
|
||||
// established: business.established,
|
||||
// reasonForSale: business.reasonForSale,
|
||||
// name: `${user.firstname} ${user.lastname}`,
|
||||
// });
|
||||
// const embedding = await createEmbedding(embeddingText);
|
||||
sleep(200);
|
||||
await db.insert(schema.businesses).values(business);
|
||||
business.price = businessJsonData[index].price;
|
||||
business.title = businessJsonData[index].title;
|
||||
business.draft = businessJsonData[index].draft;
|
||||
business.listingsCategory = 'business';
|
||||
business.realEstateIncluded = businessJsonData[index].realEstateIncluded;
|
||||
business.leasedLocation = businessJsonData[index].leasedLocation;
|
||||
business.franchiseResale = businessJsonData[index].franchiseResale;
|
||||
|
||||
business.salesRevenue = businessJsonData[index].salesRevenue;
|
||||
business.cashFlow = businessJsonData[index].cashFlow;
|
||||
business.supportAndTraining = businessJsonData[index].supportAndTraining;
|
||||
business.employees = businessJsonData[index].employees;
|
||||
business.established = businessJsonData[index].established;
|
||||
business.internalListingNumber = businessJsonData[index].internalListingNumber;
|
||||
business.reasonForSale = businessJsonData[index].reasonForSale;
|
||||
business.brokerLicencing = businessJsonData[index].brokerLicencing;
|
||||
business.internals = businessJsonData[index].internals;
|
||||
business.imageName = emailToDirName(user.email);
|
||||
business.created = new Date(businessJsonData[index].created);
|
||||
business.updated = new Date(businessJsonData[index].created);
|
||||
|
||||
await businessService.createListing(business); //db.insert(schema.businesses).values(business);
|
||||
}
|
||||
|
||||
//End
|
||||
|
||||
Reference in New Issue
Block a user