Rework of major pages
This commit is contained in:
@@ -22,19 +22,19 @@ export class CommercialPropertyListingsController {
|
||||
// return this.listingsService.findByUserId(userid,commercials);
|
||||
// }
|
||||
@Post('search')
|
||||
find(@Body() criteria: ListingCriteria): any {
|
||||
return this.listingsService.findListingsByCriteria(criteria,commercials);
|
||||
async find(@Body() criteria: ListingCriteria): Promise<any> {
|
||||
return await this.listingsService.findListingsByCriteria(criteria,commercials);
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@Body() listing: any){
|
||||
async create(@Body() listing: any){
|
||||
this.logger.info(`Save Listing`);
|
||||
this.listingsService.createListing(listing,commercials)
|
||||
return await this.listingsService.createListing(listing,commercials)
|
||||
}
|
||||
@Put()
|
||||
update(@Body() listing: any){
|
||||
async update(@Body() listing: any){
|
||||
this.logger.info(`Save Listing`);
|
||||
this.listingsService.updateListing(listing.id,listing,commercials)
|
||||
return await this.listingsService.updateListing(listing.id,listing,commercials)
|
||||
}
|
||||
@Delete(':id')
|
||||
deleteById(@Param('id') id:string){
|
||||
|
||||
@@ -71,12 +71,16 @@ export class ListingsService {
|
||||
}
|
||||
|
||||
async createListing(data: BusinessListing | CommercialPropertyListing, table: typeof businesses | typeof commercials): Promise<BusinessListing | CommercialPropertyListing> {
|
||||
const newListing = { data, created: data.created, updated: data.updated, visits: 0, last_visit: null }
|
||||
const [createdListing] = await this.conn.insert(table).values(newListing).returning();
|
||||
data.created=new Date()
|
||||
data.updated=new Date()
|
||||
data.visits=0;
|
||||
data.lastVisit=null
|
||||
const [createdListing] = await this.conn.insert(table).values(data).returning();
|
||||
return createdListing as BusinessListing | CommercialPropertyListing;
|
||||
}
|
||||
|
||||
async updateListing(id: string, data: BusinessListing | CommercialPropertyListing, table: typeof businesses | typeof commercials): Promise<BusinessListing | CommercialPropertyListing> {
|
||||
data.updated=new Date();
|
||||
const [updateListing] = await this.conn.update(table).set(data).where(eq(table.id, id)).returning();
|
||||
return updateListing as BusinessListing | CommercialPropertyListing;
|
||||
}
|
||||
@@ -107,95 +111,5 @@ export class ListingsService {
|
||||
listing.imageOrder.push(imagename);
|
||||
await this.updateListing(listing.id, listing, commercials)
|
||||
}
|
||||
// async getCommercialPropertyListingById(id: string): Promise<CommercialPropertyListing>{
|
||||
// return await this.commercialPropertyListingRepository.fetch(id) as unknown as CommercialPropertyListing;
|
||||
// }
|
||||
// async getBusinessListingById(id: string) {
|
||||
// return await this.businessListingRepository.fetch(id)
|
||||
// }
|
||||
// async getBusinessListingByUserId(userid:string){
|
||||
// return await this.businessListingRepository.search().where('userId').equals(userid).return.all()
|
||||
// }
|
||||
// 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 findBusinessListings(criteria:ListingCriteria): Promise<any> {
|
||||
// // let listings = await this.getAllBusinessListings();
|
||||
// // return this.find(criteria,listings);
|
||||
// const from=criteria.start?criteria.start:0
|
||||
// const size=criteria.length?criteria.length:24
|
||||
// this.logger.info(`start findBusinessListings: ${JSON.stringify(criteria)}`);
|
||||
// const result = await this.redis.ft.search('business:index','*',{LIMIT:{from,size}});
|
||||
// this.logger.info(`start findBusinessListings: ${JSON.stringify(criteria)}`);
|
||||
// return result
|
||||
// }
|
||||
// async findCommercialPropertyListings(criteria:ListingCriteria): Promise<any> {
|
||||
// let listings = await this.getAllCommercialListings();
|
||||
// return this.find(criteria,listings);
|
||||
// }
|
||||
// async deleteAllBusinessListings(){
|
||||
// const ids = await this.getIdsForRepo(this.schemaNameBusiness.name);
|
||||
// this.businessListingRepository.remove(ids);
|
||||
// }
|
||||
// async deleteAllcommercialListings(){
|
||||
// const ids = await this.getIdsForRepo(this.schemaNameCommercial.name);
|
||||
// this.commercialPropertyListingRepository.remove(ids);
|
||||
// }
|
||||
// async getIdsForRepo(repoName:string, maxcount=100000){
|
||||
// let cursor = 0;
|
||||
// let ids = [];
|
||||
// do {
|
||||
// const reply = await this.redis.scan(cursor, {
|
||||
// MATCH: `${repoName}:*`,
|
||||
// COUNT: maxcount
|
||||
// });
|
||||
// cursor = reply.cursor;
|
||||
// // Extrahiere die ID aus jedem Schlüssel und füge sie zur Liste hinzu
|
||||
// ids = ids.concat(reply.keys.map(key => key.split(':')[1]).filter(id=>id!='index'));
|
||||
// } while (cursor !== 0);
|
||||
// return ids;
|
||||
// }
|
||||
|
||||
// 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.state)){
|
||||
// console.log(criteria.state);
|
||||
// listings=listings.filter(l=>l.state===criteria.state);
|
||||
// }
|
||||
// if (convertStringToNullUndefined(criteria.minPrice)){
|
||||
// console.log(criteria.minPrice);
|
||||
// listings=listings.filter(l=>l.price>=Number(criteria.minPrice));
|
||||
// }
|
||||
// if (convertStringToNullUndefined(criteria.maxPrice)){
|
||||
// console.log(criteria.maxPrice);
|
||||
// listings=listings.filter(l=>l.price<=Number(criteria.maxPrice));
|
||||
// }
|
||||
// if (convertStringToNullUndefined(criteria.realEstateChecked)){
|
||||
// console.log(criteria.realEstateChecked);
|
||||
// listings=listings.filter(l=>l.realEstateIncluded);
|
||||
// }
|
||||
// if (convertStringToNullUndefined(criteria.category)){
|
||||
// console.log(criteria.category);
|
||||
// listings=listings.filter(l=>l.category===criteria.category);
|
||||
// }
|
||||
// return listings
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user