mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-23 04:22:02 -06:00
Merge pull request #224 from jaison-x/pr
fix: workaround to manage param data as an array in mongodb
This commit is contained in:
commit
a99e173168
@ -25,7 +25,14 @@ export async function useMultiFileAuthStateDb(
|
|||||||
const writeData = async (data: any, key: string): Promise<any> => {
|
const writeData = async (data: any, key: string): Promise<any> => {
|
||||||
try {
|
try {
|
||||||
await client.connect();
|
await client.connect();
|
||||||
return await collection.replaceOne({ _id: key }, JSON.parse(JSON.stringify(data, BufferJSON.replacer)), {
|
let msgParsed = JSON.parse(JSON.stringify(data, BufferJSON.replacer));
|
||||||
|
if (Array.isArray(msgParsed)) {
|
||||||
|
msgParsed = {
|
||||||
|
_id: key,
|
||||||
|
content_array: msgParsed,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return await collection.replaceOne({ _id: key }, msgParsed, {
|
||||||
upsert: true,
|
upsert: true,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -36,7 +43,10 @@ export async function useMultiFileAuthStateDb(
|
|||||||
const readData = async (key: string): Promise<any> => {
|
const readData = async (key: string): Promise<any> => {
|
||||||
try {
|
try {
|
||||||
await client.connect();
|
await client.connect();
|
||||||
const data = await collection.findOne({ _id: key });
|
let data = (await collection.findOne({ _id: key })) as any;
|
||||||
|
if (data?.content_array) {
|
||||||
|
data = data.content_array;
|
||||||
|
}
|
||||||
const creds = JSON.stringify(data);
|
const creds = JSON.stringify(data);
|
||||||
return JSON.parse(creds, BufferJSON.reviver);
|
return JSON.parse(creds, BufferJSON.reviver);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user