Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
fix: 🚑 Ensure customer & product has currency
Browse files Browse the repository at this point in the history
  • Loading branch information
Tolfx committed Mar 13, 2022
1 parent cb6f0e7 commit 86bef8d
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/Cache/reCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import ConfigModel from "../Database/Models/Configs.model";
import { CacheConfig } from "./Configs.cache";
import InvoiceModel from "../Database/Models/Invoices.model";
import { CacheInvoice } from "./Invoices.cache";
import { Company_Currency } from "../Config";
import { TPaymentCurrency } from "../Lib/Currencies";

/**
* @deprecated
Expand Down Expand Up @@ -51,27 +53,28 @@ export async function reCache_Admin()
});
}

/**
* @deprecated
*/
export async function reCache_Customers()
{
Logger.info(`Starting caching on customers..`);
return new Promise(async (resolve) =>
{
const customer = await CustomerModel.find();
for (const c of customer)
for await(const c of customer)
{
// Check if customer has currency
if(!c.currency)
{
const companyCurrency = await Company_Currency();
c.currency = companyCurrency.toLocaleUpperCase() as TPaymentCurrency;
await c.save();
}
Logger.cache(`Caching customer ${c.uid}`);
CacheCustomer.set(c.uid, c);
}
return resolve(true);
});
}

/**
* @deprecated
*/
export async function reCache_Product()
{
Logger.info(`Starting caching on products..`);
Expand All @@ -80,6 +83,13 @@ export async function reCache_Product()
const product = await ProductModel.find();
for (const c of product)
{
// Check if product has currency
if(!c.currency)
{
const companyCurrency = await Company_Currency();
c.currency = companyCurrency.toLocaleUpperCase() as TPaymentCurrency;
await c.save();
}
Logger.cache(`Caching product ${c.uid}`);
CacheProduct.set(c.uid, c);
}
Expand Down Expand Up @@ -201,8 +211,8 @@ export async function reCache()
await reCache_Configs();
// await reCache_Categories();
await reCache_Admin();
// await reCache_Customers();
// await reCache_Product();
await reCache_Customers();
await reCache_Product();
// await reCache_Transactions();
// await reCache_Orders();
await reCache_Images();
Expand Down

0 comments on commit 86bef8d

Please sign in to comment.