geo coding, user service, listing for business

This commit is contained in:
2024-03-10 20:59:23 +01:00
parent 06f349d1c3
commit 6ad40b6dca
59 changed files with 120466 additions and 687 deletions

View File

@@ -5,55 +5,51 @@ import {
ListingCriteria,
ProfessionalsBrokersListing,
} from '../models/main.model.js';
import { LISTINGS, RedisService } from '../redis/redis.service.js';
import { convertStringToNullUndefined } from '../utils.js';
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
import { Logger } from 'winston';
@Injectable()
export class ListingsService {
// private readonly logger = new Logger(ListingsService.name);
constructor(private redisService: RedisService,@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger) {}
constructor(@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger) {}
async setListing(
value: BusinessListing | ProfessionalsBrokersListing | InvestmentsListing,
id?: string,
) {
if (!id) {
id = await this.redisService.getId(LISTINGS);
value.id = id;
this.logger.info(`No ID - creating new one:${id}`)
} else {
this.logger.info(`ID available:${id}`)
}
this.redisService.setJson(id, value);
// if (!id) {
// id = await this.redisService.getId(LISTINGS);
// value.id = id;
// this.logger.info(`No ID - creating new one:${id}`)
// } else {
// this.logger.info(`ID available:${id}`)
// }
//this.redisService.setJson(id, value);
}
async getListingById(id: string) {
return await this.redisService.getJson(id, LISTINGS);
//return await this.redisService.getJson(id, LISTINGS);
}
deleteListing(id: string){
this.redisService.delete(id);
//this.redisService.delete(id);
this.logger.info(`delete listing with ID:${id}`)
}
async getAllListings(start?: number, end?: number) {
const searchResult = await this.redisService.search(LISTINGS, '*');
const listings = searchResult.slice(1).reduce((acc, item, index, array) => {
// Jedes zweite Element (beginnend mit dem ersten) ist ein JSON-String des Listings
if (index % 2 === 1) {
try {
const listing = JSON.parse(item[1]); // Parsen des JSON-Strings
acc.push(listing);
} catch (error) {
console.error('Fehler beim Parsen des JSON-Strings: ', error);
}
}
return acc;
}, []);
return listings;
// const searchResult = await this.redisService.search(LISTINGS, '*');
// const listings = searchResult.slice(1).reduce((acc, item, index, array) => {
// if (index % 2 === 1) {
// try {
// const listing = JSON.parse(item[1]);
// acc.push(listing);
// } catch (error) {
// console.error('Fehler beim Parsen des JSON-Strings: ', error);
// }
// }
// return acc;
// }, []);
// return listings;
return [];
}
//criteria.type,criteria.location,criteria.minPrice,criteria.maxPrice,criteria.realEstateChecked,criteria.listingsCategory
//async find(type:string,location:string,minPrice:string,maxPrice:string,realEstateChecked:boolean,listingsCategory:string): Promise<any> {
async find(criteria:ListingCriteria): Promise<any> {
let listings = await this.getAllListings();
listings=listings.filter(l=>l.listingsCategory===criteria.listingsCategory);