feat: Add function in controller to remove user and update cache in Redis

feat-scaling-ticket-remote-creation
adriano 2024-03-07 11:47:42 -03:00
parent 8e24f37219
commit 9d4b80986d
2 changed files with 10 additions and 6 deletions

View File

@ -12,7 +12,7 @@ import DeleteUserService from "../services/UserServices/DeleteUserService";
import ListUser from "../services/UserServices/ListUserParamiterService";
import User from "../models/User";
import { get, set } from "../helpers/RedisClient";
import { del, get, set } from "../helpers/RedisClient";
import {
startWhoIsOnlineMonitor,
@ -27,7 +27,7 @@ import { splitDateTime } from "../helpers/SplitDateTime";
import ListUserByWhatsappQueuesService from "../services/UserServices/ListUserByWhatsappQueuesService";
import { json } from "sequelize";
import { getSettingValue } from "../helpers/WhaticketSettings";
import { setBotInfo } from "../helpers/SetBotInfo"
import { setBotInfo } from "../helpers/SetBotInfo";
type IndexQuery = {
searchParam: string;
@ -275,7 +275,7 @@ export const update = async (
let user: any = await UpdateUserService({ userData, userId });
await setBotInfo(user)
await setBotInfo(user);
if (user) {
const { id, name } = user;
@ -305,6 +305,8 @@ export const remove = async (
await DeleteUserService(userId);
del(`user:${userId}`);
const io = getIO();
io.emit("user", {
action: "delete",
@ -324,5 +326,3 @@ export const remove = async (
return res.status(200).json({ message: "User deleted" });
};

View File

@ -23,7 +23,7 @@ export async function get(key: string, value?: string) {
if (keys.length > 0) {
for (const key of keys) {
const val = await redis.get(key);
if (value == val) return value;
if (value == val) return value;
}
}
return null;
@ -33,6 +33,10 @@ export async function get(key: string, value?: string) {
}
}
export async function del(key: string) {
await redis.del(key);
}
export async function clearAllKeys(...keys: string[]) {
for (const key of keys) {
// Retrieve all keys matching the pattern '*'