diff --git a/apps/api/src/proxy/proxy.controller.ts b/apps/api/src/proxy/proxy.controller.ts index 96ee57f..41f902e 100644 --- a/apps/api/src/proxy/proxy.controller.ts +++ b/apps/api/src/proxy/proxy.controller.ts @@ -63,8 +63,15 @@ export class ProxyController { @Get('/queries') public async getQueriesList(@Res() reply: FastifyReply) { + const res = await this.getAllQueries(); + + return reply.send(res); + } + + private async getAllQueries() { const list = await this.cacheManager.store.keys('*'); - const res = (Object.keys(queryTTL) as Array).reduce( + + return (Object.keys(queryTTL) as Array).reduce( (acc, queryName) => { const queries = list.filter((x) => x.split(' ').at(0) === queryName); const ttl = queryTTL[queryName]; @@ -74,8 +81,6 @@ export class ProxyController { }, {} as Record, ); - - return reply.send(res); } @Delete('/delete-query') @@ -102,4 +107,37 @@ export class ProxyController { throw new HttpException(error, HttpStatus.INTERNAL_SERVER_ERROR); } } + + @Delete('/delete-queries-by-key') + public async deleteQueriesByKey( + @Query('queriesGroup') queriesGroup: string, + @Res() reply: FastifyReply, + ) { + try { + const allQueries = await this.getAllQueries(); + const { queries } = allQueries[queriesGroup]; + + queries.forEach(async (query) => { + await this.cacheManager.del(query); + }); + + return reply.send('ok'); + } catch (error) { + throw new HttpException(error, HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + @Get('/get-query-value') + public async getQueryValue( + @Query('queryKey') queryKey: string, + @Res() reply: FastifyReply, + ) { + try { + const value = this.cacheManager.get(queryKey); + + return reply.send(value); + } catch (error) { + throw new HttpException(error, HttpStatus.INTERNAL_SERVER_ERROR); + } + } } diff --git a/apps/web/api/cache/query.ts b/apps/web/api/cache/query.ts index e4d77b9..1526f39 100644 --- a/apps/web/api/cache/query.ts +++ b/apps/web/api/cache/query.ts @@ -1,13 +1,12 @@ import type { ResponseQueries } from './types'; import getUrls from '@/config/urls'; import { withHandleError } from '@/utils/axios'; -import type { QueryFunctionContext } from '@tanstack/react-query'; import axios from 'axios'; const { URL_CACHE_GET_QUERIES, URL_CACHE_DELETE_QUERY, URL_CACHE_RESET_QUERIES } = getUrls(); -export function getQueries({ signal }: QueryFunctionContext) { - return withHandleError(axios.get(URL_CACHE_GET_QUERIES, { signal })).then( +export function getQueries() { + return withHandleError(axios.get(URL_CACHE_GET_QUERIES)).then( ({ data }) => data ); }