MCPcopy Create free account
hub / github.com/evolution-foundation/evolution-api / getInstance

Function getInstance

src/api/guards/instance.guard.ts:7–23  ·  view source on GitHub ↗
(instanceName: string)

Source from the content-addressed store, hash-verified

5import { NextFunction, Request, Response } from 'express';
6
7async 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
25export async function instanceExistsGuard(req: Request, _: Response, next: NextFunction) {
26 if (req.originalUrl.includes('/instance/create') || req.originalUrl.includes('/instance/fetchInstances')) {

Callers 2

instanceExistsGuardFunction · 0.85
instanceLoggedGuardFunction · 0.85

Calls 3

toStringMethod · 0.80
getMethod · 0.65
hasMethod · 0.65

Tested by

no test coverage detected