diff --git a/src/lib/prisma.ts b/src/lib/prisma.ts index 4da9ef0..15a33bf 100644 --- a/src/lib/prisma.ts +++ b/src/lib/prisma.ts @@ -9,9 +9,13 @@ const adapter = new PrismaMariaDb({ user: env('DATABASE_USER'), password: env('DATABASE_PASSWORD'), database: env('DATABASE_NAME'), - ssl: false, connectionLimit: 5, port: Number(env('DATABASE_PORT')) || 3306, + allowPublicKeyRetrieval: true, + ssl: { + rejectUnauthorized: false, + }, + connectTimeout: 10000, }) const prisma = new PrismaClient({ adapter }) diff --git a/src/main.ts b/src/main.ts index 0889a26..0b312fc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -33,6 +33,7 @@ async function bootstrap() { in: 'header', }) .build() + const documentFactory = () => SwaggerModule.createDocument(app, config) SwaggerModule.setup('swagger', app, documentFactory, { swaggerOptions: { @@ -47,14 +48,12 @@ async function bootstrap() { }, }, }) - // Set API prefix and enable URI versioning so alls routes live under /api/v1/* app.setGlobalPrefix('api') app.enableVersioning({ type: VersioningType.URI, defaultVersion: '1', }) - // Enable CORS. You can set `CORS_ORIGINS` to a comma-separated list of allowed origins. // Defaults include common localhost origins used by front-end dev servers. const defaultOrigins: string[] = [] @@ -83,25 +82,25 @@ async function bootstrap() { } } - // app.enableCors({ - // origin: (origin, callback) => { - // if (!origin) { - // callback(null, true) - // return - // } + app.enableCors({ + origin: (origin, callback) => { + if (!origin) { + callback(null, true) + return + } - // if (isOriginAllowed(origin)) { - // callback(null, true) - // return - // } + if (isOriginAllowed(origin)) { + callback(null, true) + return + } - // callback(new Error('Not allowed by CORS'), false) - // }, - // credentials: true, - // methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS', - // allowedHeaders: - // 'Content-Type, Accept, Authorization, X-Requested-With, X-CSRF-Token, pos_id', - // }) + callback(new Error('Not allowed by CORS'), false) + }, + credentials: true, + methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS', + allowedHeaders: + 'Content-Type, Accept, Authorization, X-Requested-With, X-CSRF-Token, pos_id', + }) // Register global logging and response mapping interceptors app.useGlobalInterceptors(new LoggingInterceptor(), new ResponseMappingInterceptor()) diff --git a/src/modules/partners/cache/partners-cache-invalidation.service.ts b/src/modules/partners/cache/partners-cache-invalidation.service.ts index 9b1cd3d..45e8a1e 100644 --- a/src/modules/partners/cache/partners-cache-invalidation.service.ts +++ b/src/modules/partners/cache/partners-cache-invalidation.service.ts @@ -1,10 +1,14 @@ import { RedisKeyMaker } from '@/common/utils' +import { PosCacheInvalidationService } from '@/modules/pos/cache/pos-cache-invalidation.service' import { RedisService } from '@/redis/redis.service' import { Injectable } from '@nestjs/common' @Injectable() export class PartnersCacheInvalidationService { - constructor(private readonly redisService: RedisService) {} + constructor( + private readonly redisService: RedisService, + private readonly PosCacheInvalidationService: PosCacheInvalidationService, + ) {} async invalidatePartnerSummary(partnerId: string): Promise { await this.invalidatePartnersList() diff --git a/src/modules/pos/cache/pos-cache-invalidation.service.ts b/src/modules/pos/cache/pos-cache-invalidation.service.ts index d68aa0a..b6670e4 100644 --- a/src/modules/pos/cache/pos-cache-invalidation.service.ts +++ b/src/modules/pos/cache/pos-cache-invalidation.service.ts @@ -6,6 +6,10 @@ import { Injectable } from '@nestjs/common' export class PosCacheInvalidationService { constructor(private readonly redisService: RedisService) {} + async invalidatePosInfo(posId: string): Promise { + this.redisService.delete(PosKeyMaker.info(posId)) + } + async invalidatePosMiddleware(token: string): Promise { this.redisService.delete(PosKeyMaker.middleware(token)) }