75 lines
3.2 KiB
TypeScript
75 lines
3.2 KiB
TypeScript
import { Body, Controller, Delete, Get, Inject, Param, Post, UploadedFile, UseInterceptors } from '@nestjs/common';
|
|
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
|
|
import { Logger } from 'winston';
|
|
import { FileInterceptor } from '@nestjs/platform-express';
|
|
import { FileService } from '../file/file.service.js';
|
|
import { SelectOptionsService } from '../select-options/select-options.service.js';
|
|
import { ListingsService } from '../listings/listings.service.js';
|
|
import { CommercialPropertyListing } from 'src/models/main.model.js';
|
|
import { Entity, EntityData } from 'redis-om';
|
|
|
|
@Controller('image')
|
|
export class ImageController {
|
|
|
|
constructor(private fileService:FileService,
|
|
private listingService:ListingsService,
|
|
@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger,
|
|
private selectOptions:SelectOptionsService) {
|
|
}
|
|
|
|
@Post('uploadPropertyPicture/:id')
|
|
@UseInterceptors(FileInterceptor('file'),)
|
|
async uploadPropertyPicture(@UploadedFile() file: Express.Multer.File,@Param('id') id:string) {
|
|
const imagename = await this.fileService.storePropertyPicture(file,id);
|
|
await this.listingService.addImage(id,imagename);
|
|
}
|
|
|
|
@Post('uploadProfile/:id')
|
|
@UseInterceptors(FileInterceptor('file'),)
|
|
async uploadProfile(@UploadedFile() file: Express.Multer.File,@Param('id') id:string) {
|
|
await this.fileService.storeProfilePicture(file,id);
|
|
}
|
|
|
|
@Post('uploadCompanyLogo/:id')
|
|
@UseInterceptors(FileInterceptor('file'),)
|
|
async uploadCompanyLogo(@UploadedFile() file: Express.Multer.File,@Param('id') id:string) {
|
|
await this.fileService.storeCompanyLogo(file,id);
|
|
}
|
|
|
|
@Get(':id')
|
|
async getPropertyImagesById(@Param('id') id:string): Promise<any> {
|
|
const result = await this.listingService.getCommercialPropertyListingById(id);
|
|
const listing = result as CommercialPropertyListing;
|
|
if (listing.imageOrder){
|
|
return listing.imageOrder
|
|
} else {
|
|
const imageOrder = await this.fileService.getPropertyImages(id);
|
|
listing.imageOrder=imageOrder;
|
|
this.listingService.saveListing(listing);
|
|
return imageOrder;
|
|
}
|
|
}
|
|
@Get('profileImages/:userids')
|
|
async getProfileImagesForUsers(@Param('userids') userids:string): Promise<any> {
|
|
return await this.fileService.getProfileImagesForUsers(userids);
|
|
}
|
|
@Get('companyLogos/:userids')
|
|
async getCompanyLogosForUsers(@Param('userids') userids:string): Promise<any> {
|
|
return await this.fileService.getCompanyLogosForUsers(userids);
|
|
}
|
|
|
|
@Delete('propertyPicture/:listingid/:imagename')
|
|
async deletePropertyImagesById(@Param('listingid') listingid:string,@Param('imagename') imagename:string): Promise<any> {
|
|
this.fileService.deleteImage(`pictures/property/${listingid}/${imagename}`);
|
|
await this.listingService.deleteImage(listingid,imagename);
|
|
}
|
|
@Delete('logo/:userid/')
|
|
async deleteLogoImagesById(@Param('id') id:string): Promise<any> {
|
|
this.fileService.deleteImage(`pictures/property//${id}`)
|
|
}
|
|
@Delete('profile/:userid/')
|
|
async deleteProfileImagesById(@Param('id') id:string): Promise<any> {
|
|
this.fileService.deleteImage(`pictures/property//${id}`)
|
|
}
|
|
}
|