(instanceName: string)
| 5 | import { NextFunction, Request, Response } from 'express'; |
| 6 | |
| 7 | async function getInstance(instanceName: string) { |
| 8 | try { |
| 9 | const cacheConf = configService.get<CacheConf>('CACHE'); |
| 10 | |
| 11 | const exists = !!waMonitor.waInstances[instanceName]; |
| 12 | |
| 13 | if (cacheConf.REDIS.ENABLED && cacheConf.REDIS.SAVE_INSTANCES) { |
| 14 | const keyExists = await cache.has(instanceName); |
| 15 | |
| 16 | return exists || keyExists; |
| 17 | } |
| 18 | |
| 19 | return exists || (await prismaRepository.instance.findMany({ where: { name: instanceName } })).length > 0; |
| 20 | } catch (error) { |
| 21 | throw new InternalServerErrorException(error?.toString()); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | export async function instanceExistsGuard(req: Request, _: Response, next: NextFunction) { |
| 26 | if (req.originalUrl.includes('/instance/create') || req.originalUrl.includes('/instance/fetchInstances')) { |
no test coverage detected