fix inputnumber, Umbau auf redis-om, Neubenamung
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller.js';
|
||||
import { AppService } from './app.service.js';
|
||||
import { ListingsController } from './listings/listings.controller.js';
|
||||
import { FileService } from './file/file.service.js';
|
||||
import { AuthService } from './auth/auth.service.js';
|
||||
import { AuthController } from './auth/auth.controller.js';
|
||||
@@ -25,6 +24,7 @@ import { UserModule } from './user/user.module.js';
|
||||
import { ListingsModule } from './listings/listings.module.js';
|
||||
import { AccountModule } from './account/account.module.js';
|
||||
import { SelectOptionsModule } from './select-options/select-options.module.js';
|
||||
import { CommercialPropertyListingsController } from './listings/commercial-property-listings.controller.js';
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
|
||||
@@ -1,25 +1,23 @@
|
||||
import { Body, Controller, Delete, Get, Inject, Param, Post, Put } from '@nestjs/common';
|
||||
import { FileService } from '../file/file.service.js';
|
||||
import { convertStringToNullUndefined } from '../utils.js';
|
||||
import { RedisService } from '../redis/redis.service.js';
|
||||
import { ListingsService } from './listings.service.js';
|
||||
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
|
||||
import { Logger } from 'winston';
|
||||
|
||||
@Controller('listings')
|
||||
export class ListingsController {
|
||||
// private readonly logger = new Logger(ListingsController.name);
|
||||
|
||||
@Controller('business-listings')
|
||||
export class BusinessListingsController {
|
||||
|
||||
constructor(private readonly listingsService:ListingsService,@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger) {
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll(): any {
|
||||
return this.listingsService.getAllListings();
|
||||
return this.listingsService.getAllBusinessListings();
|
||||
}
|
||||
@Get(':id')
|
||||
findById(@Param('id') id:string): any {
|
||||
return this.listingsService.getListingById(id);
|
||||
return this.listingsService.getBusinessListingById(id);
|
||||
}
|
||||
// @Get(':type/:location/:minPrice/:maxPrice/:realEstateChecked')
|
||||
// find(@Param('type') type:string,@Param('location') location:string,@Param('minPrice') minPrice:string,@Param('maxPrice') maxPrice:string,@Param('realEstateChecked') realEstateChecked:boolean): any {
|
||||
@@ -27,24 +25,16 @@ export class ListingsController {
|
||||
// }
|
||||
@Post('search')
|
||||
find(@Body() criteria: any): any {
|
||||
return this.listingsService.find(criteria);
|
||||
}
|
||||
/**
|
||||
* @param listing updates a new listing
|
||||
*/
|
||||
@Put(':id')
|
||||
updateById(@Param('id') id:string, @Body() listing: any){
|
||||
this.logger.info(`Update by ID: ${id}`);
|
||||
this.listingsService.setListing(listing,id)
|
||||
return this.listingsService.findBusinessListings(criteria);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param listing creates a new listing
|
||||
*/
|
||||
@Post()
|
||||
create(@Body() listing: any){
|
||||
this.logger.info(`Create Listing`);
|
||||
this.listingsService.setListing(listing)
|
||||
save(@Body() listing: any){
|
||||
this.logger.info(`Save Listing`);
|
||||
this.listingsService.saveListing(listing)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,7 +42,7 @@ export class ListingsController {
|
||||
*/
|
||||
@Delete(':id')
|
||||
deleteById(@Param('id') id:string){
|
||||
this.listingsService.deleteListing(id)
|
||||
this.listingsService.deleteBusinessListing(id)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { Body, Controller, Delete, Get, Inject, Param, Post } from '@nestjs/common';
|
||||
import { ListingsService } from './listings.service.js';
|
||||
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
|
||||
import { Logger } from 'winston';
|
||||
|
||||
@Controller('commercial-property-listings')
|
||||
export class CommercialPropertyListingsController {
|
||||
|
||||
constructor(private readonly listingsService:ListingsService,@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger) {
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll(): any {
|
||||
return this.listingsService.getAllCommercialListings();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findById(@Param('id') id:string): any {
|
||||
return this.listingsService.getCommercialPropertyListingById(id);
|
||||
}
|
||||
|
||||
@Post('search')
|
||||
find(@Body() criteria: any): any {
|
||||
return this.listingsService.findCommercialPropertyListings(criteria);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param listing creates a new listing
|
||||
*/
|
||||
@Post()
|
||||
save(@Body() listing: any){
|
||||
this.logger.info(`Save Listing`);
|
||||
this.listingsService.saveListing(listing)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id deletes a listing
|
||||
*/
|
||||
@Delete(':id')
|
||||
deleteById(@Param('id') id:string){
|
||||
this.listingsService.deleteCommercialPropertyListing(id)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ListingsController } from './listings.controller.js';
|
||||
import { BusinessListingsController } from './business-listings.controller.js';
|
||||
import { ListingsService } from './listings.service.js';
|
||||
import { CommercialPropertyListingsController } from './commercial-property-listings.controller.js';
|
||||
import { RedisModule } from '../redis/redis.module.js';
|
||||
|
||||
@Module({
|
||||
controllers: [ListingsController],
|
||||
imports: [RedisModule],
|
||||
controllers: [BusinessListingsController, CommercialPropertyListingsController],
|
||||
providers: [ListingsService]
|
||||
})
|
||||
export class ListingsModule {}
|
||||
|
||||
@@ -1,65 +1,118 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import {
|
||||
BusinessListing,
|
||||
InvestmentsListing,
|
||||
CommercialPropertyListing,
|
||||
ListingCriteria,
|
||||
ProfessionalsBrokersListing,
|
||||
ListingType
|
||||
} from '../models/main.model.js';
|
||||
import { convertStringToNullUndefined } from '../utils.js';
|
||||
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
|
||||
import { Logger } from 'winston';
|
||||
import { EntityData, EntityId, Repository, Schema, SchemaDefinition } from 'redis-om';
|
||||
import { REDIS_CLIENT } from '../redis/redis.module.js';
|
||||
|
||||
@Injectable()
|
||||
export class ListingsService {
|
||||
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);
|
||||
businessListingRepository:Repository;
|
||||
commercialPropertyListingRepository:Repository;
|
||||
baseListingSchemaDef : SchemaDefinition = {
|
||||
id: { type: 'string' },
|
||||
userId: { type: 'string' },
|
||||
listingsCategory: { type: 'string' },
|
||||
title: { type: 'string' },
|
||||
description: { type: 'string' },
|
||||
country: { type: 'string' },
|
||||
state:{ type: 'string' },
|
||||
city:{ type: 'string' },
|
||||
zipCode: { type: 'number' },
|
||||
type: { type: 'string' },
|
||||
price: { type: 'number' },
|
||||
favoritesForUser:{ type: 'string[]' },
|
||||
hideImage:{ type: 'boolean' },
|
||||
draft:{ type: 'boolean' },
|
||||
created:{ type: 'date' },
|
||||
updated:{ type: 'date' }
|
||||
}
|
||||
businessListingSchemaDef : SchemaDefinition = {
|
||||
...this.baseListingSchemaDef,
|
||||
salesRevenue: { type: 'number' },
|
||||
cashFlow: { type: 'number' },
|
||||
employees: { type: 'number' },
|
||||
established: { type: 'number' },
|
||||
internalListingNumber: { type: 'number' },
|
||||
realEstateIncluded:{ type: 'boolean' },
|
||||
leasedLocation:{ type: 'boolean' },
|
||||
franchiseResale:{ type: 'boolean' },
|
||||
supportAndTraining: { type: 'string' },
|
||||
reasonForSale: { type: 'string' },
|
||||
brokerLicencing: { type: 'string' },
|
||||
internals: { type: 'string' },
|
||||
}
|
||||
commercialPropertyListingSchemaDef : SchemaDefinition = {
|
||||
...this.baseListingSchemaDef,
|
||||
imageNames:{ type: 'string[]' },
|
||||
}
|
||||
businessListingSchema = new Schema('businessListing',this.businessListingSchemaDef, {
|
||||
dataStructure: 'JSON'
|
||||
})
|
||||
commercialPropertyListingSchema = new Schema('commercialPropertyListing',this.commercialPropertyListingSchemaDef, {
|
||||
dataStructure: 'JSON'
|
||||
})
|
||||
constructor(@Inject(REDIS_CLIENT) private readonly redis: any){
|
||||
this.businessListingRepository = new Repository(this.businessListingSchema, redis);
|
||||
this.commercialPropertyListingRepository = new Repository(this.commercialPropertyListingSchema, redis)
|
||||
this.businessListingRepository.createIndex();
|
||||
this.commercialPropertyListingRepository.createIndex();
|
||||
}
|
||||
async saveListing(listing: BusinessListing | CommercialPropertyListing) {
|
||||
const repo=listing.listingsCategory==='business'?this.businessListingRepository:this.commercialPropertyListingRepository;
|
||||
let result
|
||||
if (listing.id){
|
||||
result = await repo.save(listing.id,listing as any)
|
||||
} else {
|
||||
result = await repo.save(listing as any)
|
||||
listing.id=result[EntityId];
|
||||
result = await repo.save(listing.id,listing as any)
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async getCommercialPropertyListingById(id: string) {
|
||||
return await this.commercialPropertyListingRepository.fetch(id)
|
||||
}
|
||||
async getBusinessListingById(id: string) {
|
||||
return await this.businessListingRepository.fetch(id)
|
||||
}
|
||||
async deleteBusinessListing(id: string){
|
||||
return await this.businessListingRepository.remove(id);
|
||||
}
|
||||
async deleteCommercialPropertyListing(id: string){
|
||||
return await this.commercialPropertyListingRepository.remove(id);
|
||||
}
|
||||
async getAllBusinessListings(start?: number, end?: number) {
|
||||
return await this.businessListingRepository.search().return.all()
|
||||
}
|
||||
async getAllCommercialListings(start?: number, end?: number) {
|
||||
return await this.commercialPropertyListingRepository.search().return.all()
|
||||
}
|
||||
|
||||
async getListingById(id: string) {
|
||||
//return await this.redisService.getJson(id, LISTINGS);
|
||||
|
||||
async findBusinessListings(criteria:ListingCriteria): Promise<any> {
|
||||
let listings = await this.getAllBusinessListings();
|
||||
return this.find(criteria,listings);
|
||||
}
|
||||
deleteListing(id: string){
|
||||
//this.redisService.delete(id);
|
||||
this.logger.info(`delete listing with ID:${id}`)
|
||||
async findCommercialPropertyListings(criteria:ListingCriteria): Promise<any> {
|
||||
let listings = await this.getAllCommercialListings();
|
||||
return this.find(criteria,listings);
|
||||
}
|
||||
async getAllListings(start?: number, end?: number) {
|
||||
// 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 [];
|
||||
}
|
||||
async find(criteria:ListingCriteria): Promise<any> {
|
||||
let listings = await this.getAllListings();
|
||||
async find(criteria:ListingCriteria, listings: any[]): Promise<any> {
|
||||
listings=listings.filter(l=>l.listingsCategory===criteria.listingsCategory);
|
||||
if (convertStringToNullUndefined(criteria.type)){
|
||||
console.log(criteria.type);
|
||||
listings=listings.filter(l=>l.type===criteria.type);
|
||||
}
|
||||
if (convertStringToNullUndefined(criteria.location)){
|
||||
console.log(criteria.location);
|
||||
listings=listings.filter(l=>l.location===criteria.location);
|
||||
if (convertStringToNullUndefined(criteria.state)){
|
||||
console.log(criteria.state);
|
||||
listings=listings.filter(l=>l.state===criteria.state);
|
||||
}
|
||||
if (convertStringToNullUndefined(criteria.minPrice)){
|
||||
console.log(criteria.minPrice);
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import { Body, Controller, Get, HttpStatus, Param, Post, Res } from '@nestjs/common';
|
||||
import { Response } from 'express';
|
||||
import { RedisService } from './redis.service.js';
|
||||
|
||||
@Controller('redis')
|
||||
export class RedisController {
|
||||
constructor(private redisService:RedisService){}
|
||||
|
||||
}
|
||||
@@ -24,8 +24,6 @@ export class RedisModule {}
|
||||
export const REDIS_CLIENT = "REDIS_CLIENT";
|
||||
// redis.service.ts
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { RedisService } from './redis.service.js';
|
||||
import { RedisController } from './redis.controller.js';
|
||||
import { createClient } from 'redis';
|
||||
|
||||
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
// redis.service.ts
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { BusinessListing, InvestmentsListing,ProfessionalsBrokersListing } from '../models/main.model.js';
|
||||
import fs from 'fs-extra';
|
||||
import { createClient } from 'redis';
|
||||
|
||||
export const LISTINGS = 'LISTINGS';
|
||||
export const SUBSCRIPTIONS = 'SUBSCRIPTIONS';
|
||||
export const USERS = 'USERS'
|
||||
export const redis = createClient({ url: 'redis://localhost:6379' })
|
||||
@Injectable()
|
||||
export class RedisService {
|
||||
//private redis = new Redis(); // Verbindungsparameter nach Bedarf anpassen
|
||||
// private redis = new Redis({
|
||||
// port: 6379, // Der TLS-Port von Redis
|
||||
//host: '2.56.188.138',
|
||||
// host: '127.0.0.1',
|
||||
//password: 'bizmatchRedis:5600Wuppertal11', // ACL Benutzername und Passwort
|
||||
// tls: {
|
||||
// key: fs.readFileSync('/home/aknuth/ssl/private/redis.key'),
|
||||
// cert: fs.readFileSync('/home/aknuth/ssl/certs/redis.crt')
|
||||
// }
|
||||
// });
|
||||
|
||||
|
||||
|
||||
// ######################################
|
||||
// general methods
|
||||
// ######################################
|
||||
// async setJson(id: string, value: any): Promise<void> {
|
||||
// await this.redis.call("JSON.SET", `${LISTINGS}:${id}`, "$", JSON.stringify(value));
|
||||
// }
|
||||
// async delete(id: string): Promise<void> {
|
||||
// await this.redis.del(`${LISTINGS}:${id}`);
|
||||
// }
|
||||
// async getJson(id: string, prefix:string): Promise<any> {
|
||||
// const result:string = await this.redis.call("JSON.GET", `${prefix}:${id}`) as string;
|
||||
// return JSON.parse(result);
|
||||
// }
|
||||
|
||||
// async getId(prefix:'LISTINGS'|'SUBSCRIPTIONS'|'USERS'):Promise<string>{
|
||||
// const counter = await this.redis.call("INCR",`${prefix}_ID_COUNTER`) as number;
|
||||
// return counter.toString().padStart(15, '0')
|
||||
// }
|
||||
|
||||
// async search(prefix:'LISTINGS'|'SUBSCRIPTIONS'|'USERS',clause:string):Promise<any>{
|
||||
// const result = await this.redis.call(`FT.SEARCH`, `${prefix}_INDEX`, `${clause}`, 'LIMIT', 0, 200);
|
||||
// return result;
|
||||
// }
|
||||
}
|
||||
@@ -30,7 +30,7 @@ export class SelectOptionsService {
|
||||
public listingCategories: Array<KeyValue> = [
|
||||
{ name: 'Business', value: 'business' },
|
||||
// { name: 'Professionals/Brokers Directory', value: 'professionals_brokers' },
|
||||
{ name: 'Investment Property', value: 'investment' },
|
||||
{ name: 'Commercial Property', value: 'commercialProperty' },
|
||||
]
|
||||
public categories: Array<KeyValueStyle> = [
|
||||
{ name: 'Broker', value: 'broker', icon:'pi-image',bgColorClass:'bg-green-100',textColorClass:'text-green-600' },
|
||||
|
||||
@@ -4,13 +4,12 @@ import { Entity, Repository, Schema } from 'redis-om';
|
||||
import { User } from '../models/main.model.js';
|
||||
import { REDIS_CLIENT } from '../redis/redis.module.js';
|
||||
import { UserEntity } from '../models/server.model.js';
|
||||
// export const redis = createClient({ url: 'redis://localhost:6379' })
|
||||
|
||||
@Injectable()
|
||||
export class UserService {
|
||||
userRepository:Repository;
|
||||
userSchema = new Schema('user',{
|
||||
// id: string;
|
||||
id: { type: 'string' },
|
||||
firstname: { type: 'string' },
|
||||
lastname: { type: 'string' },
|
||||
email: { type: 'string' },
|
||||
@@ -25,22 +24,14 @@ export class UserService {
|
||||
}, {
|
||||
dataStructure: 'JSON'
|
||||
})
|
||||
constructor(@Inject(REDIS_CLIENT) private readonly client: any){
|
||||
// const redis = createClient({ url: 'redis://localhost:6379' })
|
||||
this.userRepository = new Repository(this.userSchema, client)
|
||||
constructor(@Inject(REDIS_CLIENT) private readonly redis: any){
|
||||
this.userRepository = new Repository(this.userSchema, redis)
|
||||
}
|
||||
|
||||
async getUserById( id:string){
|
||||
return await this.userRepository.fetch(id);
|
||||
}
|
||||
async saveUser(user:any):Promise<UserEntity>{
|
||||
return await this.userRepository.save(user.id,user) as UserEntity
|
||||
}
|
||||
// createUser(){
|
||||
|
||||
// }
|
||||
|
||||
// updateById(id:string){
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user