feat: Add new function to clear user cache and include phone number field for official WhatsApp
parent
8ca5b4503a
commit
6c5b89fd28
|
@ -54,6 +54,7 @@ interface WhatsappData {
|
|||
isDefault?: boolean;
|
||||
isOfficial?: boolean;
|
||||
phoneNumberId?: string;
|
||||
number?: string;
|
||||
wabaId?: string;
|
||||
}
|
||||
|
||||
|
@ -322,7 +323,8 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
|||
urlApi,
|
||||
phoneNumberId,
|
||||
wabaId,
|
||||
isOfficial
|
||||
isOfficial,
|
||||
number
|
||||
}: WhatsappData = req.body;
|
||||
|
||||
if (req.user.profile !== "master") {
|
||||
|
@ -333,7 +335,8 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
|||
urlApi,
|
||||
isOfficial,
|
||||
phoneNumberId,
|
||||
wabaId
|
||||
wabaId,
|
||||
number
|
||||
});
|
||||
|
||||
if (invalid) {
|
||||
|
@ -346,6 +349,7 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
|||
} else if (!isOfficial) {
|
||||
phoneNumberId = "";
|
||||
wabaId = "";
|
||||
number = "";
|
||||
}
|
||||
|
||||
let invalidPhoneName = validatePhoneName(name);
|
||||
|
@ -365,7 +369,8 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
|||
queueIds,
|
||||
phoneNumberId,
|
||||
wabaId,
|
||||
isOfficial
|
||||
isOfficial,
|
||||
number
|
||||
});
|
||||
|
||||
console.log("whatsapp.id: ", whatsapp.id);
|
||||
|
@ -549,18 +554,22 @@ interface WhatsappDataValidate {
|
|||
isOfficial?: boolean;
|
||||
phoneNumberId?: string;
|
||||
wabaId?: string;
|
||||
number?: string;
|
||||
}
|
||||
|
||||
const checkWhatsAppData = ({
|
||||
urlApi,
|
||||
isOfficial,
|
||||
phoneNumberId,
|
||||
wabaId
|
||||
wabaId,
|
||||
number
|
||||
}: WhatsappDataValidate) => {
|
||||
if (isOfficial && (!phoneNumberId || phoneNumberId.trim() == "")) {
|
||||
return { message: "Phone number Id is required!" };
|
||||
} else if (isOfficial && (!wabaId || wabaId.trim() == "")) {
|
||||
return { message: "WABA ID is required!" };
|
||||
} else if (isOfficial && (!number || number.trim() == "")) {
|
||||
return { message: "Phone number is required!" };
|
||||
} else if (!isOfficial && (!urlApi || urlApi.trim() == "")) {
|
||||
return { message: "urlApi is required!" };
|
||||
}
|
||||
|
|
|
@ -17,6 +17,18 @@ export async function get(key: string) {
|
|||
return JSON.parse(value);
|
||||
}
|
||||
|
||||
export async function clearAllKeys() {
|
||||
// Retrieve all keys matching the pattern '*'
|
||||
const keys = await redis.keys("user:*");
|
||||
|
||||
// If there are keys, delete them
|
||||
if (keys.length > 0) {
|
||||
console.log('keys: ', keys)
|
||||
await redis.del(...keys);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function findByContain(
|
||||
key: string,
|
||||
keyName: string,
|
||||
|
|
|
@ -23,7 +23,7 @@ import fs from "fs";
|
|||
import dir from "path";
|
||||
import { getSettingValue } from "./helpers/WhaticketSettings";
|
||||
import loadSettings from "./helpers/LoadSettings";
|
||||
import { set } from "./helpers/RedisClient";
|
||||
import { clearAllKeys, set } from "./helpers/RedisClient";
|
||||
|
||||
const server = app.listen(process.env.PORT, () => {
|
||||
logger.info(`Server started on port: ${process.env.PORT}`);
|
||||
|
@ -44,6 +44,8 @@ gracefulShutdown(server);
|
|||
(async () => {
|
||||
console.log("os.tmpdir(): ", os.tmpdir());
|
||||
|
||||
await clearAllKeys();
|
||||
|
||||
const users = await User.findAll();
|
||||
|
||||
for (const user of users) {
|
||||
|
|
|
@ -16,6 +16,7 @@ interface Request {
|
|||
phoneNumberId?: string;
|
||||
wabaId?: string;
|
||||
isOfficial?: boolean;
|
||||
number?: string;
|
||||
}
|
||||
|
||||
interface Response {
|
||||
|
@ -34,7 +35,8 @@ const CreateWhatsAppService = async ({
|
|||
isDefault = false,
|
||||
isOfficial = false,
|
||||
phoneNumberId,
|
||||
wabaId
|
||||
wabaId,
|
||||
number
|
||||
}: Request): Promise<Response> => {
|
||||
try {
|
||||
const schema = Yup.object().shape({
|
||||
|
@ -98,6 +100,7 @@ const CreateWhatsAppService = async ({
|
|||
phoneNumberId,
|
||||
wabaId,
|
||||
isOfficial,
|
||||
number,
|
||||
classification
|
||||
},
|
||||
{ include: ["queues"] }
|
||||
|
|
|
@ -70,6 +70,7 @@ const WhatsAppModal = ({ open, onClose, whatsAppId, whatsAppOfficial }) => {
|
|||
farewellMessage: '',
|
||||
isDefault: false,
|
||||
isOfficial: false,
|
||||
number: '',
|
||||
phoneNumberId: '',
|
||||
wabaId: ''
|
||||
}
|
||||
|
@ -109,6 +110,7 @@ const WhatsAppModal = ({ open, onClose, whatsAppId, whatsAppOfficial }) => {
|
|||
if (!isOfficial) {
|
||||
values.phoneNumberId = ''
|
||||
values.wabaId = ''
|
||||
values.number = ''
|
||||
}
|
||||
|
||||
|
||||
|
@ -276,6 +278,18 @@ const WhatsAppModal = ({ open, onClose, whatsAppId, whatsAppOfficial }) => {
|
|||
margin="dense"
|
||||
className={classes.textField}
|
||||
/>
|
||||
|
||||
<Field
|
||||
as={TextField}
|
||||
label="Phone number"
|
||||
autoFocus
|
||||
name="number"
|
||||
error={touched.name && Boolean(errors.name)}
|
||||
helperText={touched.name && errors.name}
|
||||
variant="outlined"
|
||||
margin="dense"
|
||||
className={classes.textField}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue