-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
brought ./places response inline with expectations
- Loading branch information
1 parent
16f9ed8
commit d4bcf40
Showing
12 changed files
with
599 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,38 @@ | ||
import { PlacesModule } from './places/places.module'; | ||
import { PlacesService } from './places/places.service'; | ||
// src/app.module.ts | ||
import { Module, NestMiddleware, MiddlewareConsumer, Logger, RequestMethod } from '@nestjs/common'; | ||
import { Module, NestMiddleware, MiddlewareConsumer, Logger, RequestMethod } from '@nestjs/common'; | ||
import { PlacesController } from './places/places.controller'; | ||
import { BigQueryService } from './bigquery/bigquery.service'; | ||
import { GcsService } from './gcs/gcs.service'; | ||
import { ConfigModule } from '@nestjs/config'; | ||
import {Request, Response} from 'express' | ||
import { Request, Response } from 'express' | ||
import { AuthAPIMiddleware } from './middleware/auth-api.middleware'; | ||
import { AppController } from './app.controller'; | ||
import { AppService } from './app.service'; | ||
|
||
@Module({ | ||
imports: [ConfigModule.forRoot()], | ||
controllers: [AppController,PlacesController], | ||
providers: [BigQueryService, GcsService,AppService], | ||
imports: [ | ||
PlacesModule, ConfigModule.forRoot()], | ||
controllers: [AppController], | ||
providers: [ BigQueryService, GcsService, AppService], | ||
}) | ||
export class AppModule { | ||
configure(consumer: MiddlewareConsumer) { | ||
consumer | ||
.apply(LoggerMiddleware) | ||
.forRoutes('*'); | ||
configure(consumer: MiddlewareConsumer) { | ||
consumer | ||
.apply(LoggerMiddleware) | ||
.forRoutes('*'); | ||
|
||
consumer.apply(AuthAPIMiddleware) | ||
.forRoutes('*'); | ||
.forRoutes('*'); | ||
|
||
} | ||
} | ||
|
||
class LoggerMiddleware implements NestMiddleware { | ||
use(req:Request, res:Response, next: Function) { | ||
use(req: Request, res: Response, next: Function) { | ||
|
||
Logger.debug(`Request ${req.method} ${req.originalUrl}`) | ||
next(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createParamDecorator, ExecutionContext } from '@nestjs/common'; | ||
|
||
export const AuthedUser = createParamDecorator( | ||
(data: unknown, ctx: ExecutionContext) => { | ||
const request = ctx.switchToHttp().getRequest(); | ||
return request.res.locals['user']; // Get the user from locals | ||
}, | ||
); | ||
|
||
//interface for user object | ||
export interface User { | ||
accountId: string; | ||
userId: string; | ||
isDemoAccount?: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Injectable, BadRequestException, ForbiddenException } from '@nestjs/common'; | ||
|
||
// Method decorator | ||
export function ValidateLatLngUser(): MethodDecorator { | ||
return function (target, propertyKey, descriptor: PropertyDescriptor) { | ||
const originalMethod = descriptor.value; | ||
|
||
descriptor.value = async function (...args: any[]) { | ||
const request = args[0]; // Assuming the first argument is the request object | ||
const lat = request?.lat; | ||
const lng = request?.lng; | ||
const user = args[1] | ||
|
||
if (lat && lng && user.isDemoAccount) { | ||
throw new ForbiddenException('Demo accounts cannot access this feature'); | ||
} | ||
|
||
// Call the original method if validation passes | ||
return await originalMethod.apply(this, args); | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.