Auth Token Übersendung eingebaut
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { Body, Controller, Delete, Get, Inject, Param, Post, Put } from '@nestjs/common';
|
||||
import { Body, Controller, Delete, Get, Inject, Param, Post, Put, Request, UseGuards } from '@nestjs/common';
|
||||
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
|
||||
import { Logger } from 'winston';
|
||||
import { businesses } from '../drizzle/schema.js';
|
||||
import { OptionalJwtAuthGuard } from '../jwt-auth/optional-jwt-auth.guard.js';
|
||||
import { ListingCriteria } from '../models/main.model.js';
|
||||
import { ListingsService } from './listings.service.js';
|
||||
|
||||
@@ -16,9 +17,11 @@ export class BusinessListingsController {
|
||||
findById(@Param('id') id: string): any {
|
||||
return this.listingsService.findById(id, businesses);
|
||||
}
|
||||
|
||||
@UseGuards(OptionalJwtAuthGuard)
|
||||
@Get('user/:userid')
|
||||
findByUserId(@Param('userid') userid: string): any {
|
||||
return this.listingsService.findByUserId(userid, businesses);
|
||||
findByUserId(@Request() req, @Param('userid') userid: string): any {
|
||||
return this.listingsService.findByUserId(userid, businesses, req.user?.username);
|
||||
}
|
||||
|
||||
@Post('search')
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { Body, Controller, Delete, Get, Inject, Param, Post, Put } from '@nestjs/common';
|
||||
import { Body, Controller, Delete, Get, Inject, Param, Post, Put, Request, UseGuards } from '@nestjs/common';
|
||||
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
|
||||
import { Logger } from 'winston';
|
||||
import { commercials } from '../drizzle/schema.js';
|
||||
import { FileService } from '../file/file.service.js';
|
||||
import { OptionalJwtAuthGuard } from '../jwt-auth/optional-jwt-auth.guard.js';
|
||||
import { ListingCriteria } from '../models/main.model.js';
|
||||
import { ListingsService } from './listings.service.js';
|
||||
|
||||
@@ -18,9 +19,12 @@ export class CommercialPropertyListingsController {
|
||||
findById(@Param('id') id: string): any {
|
||||
return this.listingsService.findById(id, commercials);
|
||||
}
|
||||
|
||||
@UseGuards(OptionalJwtAuthGuard)
|
||||
@Get('user/:userid')
|
||||
findByUserId(@Param('userid') userid: string): any {
|
||||
return this.listingsService.findByUserId(userid, commercials);
|
||||
findByUserId(@Request() req, @Param('userid') userid: string): any {
|
||||
console.log(req.user?.username);
|
||||
return this.listingsService.findByUserId(userid, commercials, req.user?.username);
|
||||
}
|
||||
@Post('search')
|
||||
async find(@Body() criteria: ListingCriteria): Promise<any> {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AuthModule } from '../auth/auth.module.js';
|
||||
import { DrizzleModule } from '../drizzle/drizzle.module.js';
|
||||
import { FileService } from '../file/file.service.js';
|
||||
import { UserService } from '../user/user.service.js';
|
||||
@@ -9,7 +10,7 @@ import { ListingsService } from './listings.service.js';
|
||||
import { UnknownListingsController } from './unknown-listings.controller.js';
|
||||
|
||||
@Module({
|
||||
imports: [DrizzleModule],
|
||||
imports: [DrizzleModule, AuthModule],
|
||||
controllers: [BusinessListingsController, CommercialPropertyListingsController, UnknownListingsController, BrokerListingsController],
|
||||
providers: [ListingsService, FileService, UserService],
|
||||
exports: [ListingsService],
|
||||
|
||||
@@ -68,17 +68,17 @@ export class ListingsService {
|
||||
const result = await this.conn
|
||||
.select()
|
||||
.from(table)
|
||||
.where(sql`${table.id} = ${id}`);
|
||||
.where(and(sql`${table.id} = ${id}`, ne(table.draft, true)));
|
||||
return result[0] as BusinessListing | CommercialPropertyListing;
|
||||
}
|
||||
async findByImagePath(imagePath: string, serial: string): Promise<CommercialPropertyListing> {
|
||||
const result = await this.conn
|
||||
.select()
|
||||
.from(commercials)
|
||||
.where(and(sql`${commercials.imagePath} = ${imagePath}`, sql`${commercials.serialId} = ${serial}`));
|
||||
.where(and(sql`${commercials.imagePath} = ${imagePath}`, sql`${commercials.serialId} = ${serial}`, ne(commercials.draft, true)));
|
||||
return result[0] as CommercialPropertyListing;
|
||||
}
|
||||
async findByUserId(userId: string, table: typeof businesses | typeof commercials): Promise<BusinessListing[] | CommercialPropertyListing[]> {
|
||||
async findByUserId(userId: string, table: typeof businesses | typeof commercials, email: string): Promise<BusinessListing[] | CommercialPropertyListing[]> {
|
||||
return (await this.conn.select().from(table).where(eq(table.userId, userId))) as BusinessListing[] | CommercialPropertyListing[];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user