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

fix: refactoring, renaming, adding awaits, removing redundant, and more #89

Merged
merged 5 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 57 additions & 55 deletions src/Admin/AdminHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,58 +60,60 @@ export default class AdminHandler
run_late_invoice_notify
`);

if(result.action === "create_admin")
await this.create();

if(result.action === "show_admins")
await this.show();

if(result.action === "update_smtp")
await this.update_smtp();

if(result.action === "show_smtp")
await this.show_smtp();

if(result.action === "delete_admin")
await this.delete_admin();

if(result.action === "add_email")
await this.add_email();

if(result.action === "delete_email")
await this.delete_email();

if(result.action === "show_emails")
await this.show_emails();

if(result.action === "add_webhook")
await this.add_webhook();

if(result.action === "delete_webhook")
await this.delete_webhook();

if(result.action === "show_webhooks")
await this.show_webhooks();

if(result.action === "update_company")
await this.update_company();

if(result.action === "show_plugins")
await this.show_plugins();

if(result.action === "update_plugin")
await this.update_plugin();

if(result.action === "run_invoices_notify")
await this.run_invoices_notify();

if(result.action === "run_charge_payment")
await this.run_charge_payment();

if(result.action === "run_late_invoice_notify")
await this.run_late_invoice_notify();

this.action();
switch (result.action)
{
case "create_admin":
await this.create();
break;
case "delete_admin":
await this.delete_admin();
break;
case "show_admins":
await AdminHandler.show();
break;
case "update_smtp":
await this.update_smtp();
break;
case "show_smtp":
await this.show_smtp();
break;
case "add_email":
await this.add_email();
break;
case "delete_email":
await this.delete_email();
break;
case "show_emails":
await this.show_emails();
break;
case "add_webhook":
await this.add_webhook();
break;
case "delete_webhook":
await this.delete_webhook();
break;
case "show_webhooks":
await this.show_webhooks();
break;
case "update_company":
await this.update_company();
break;
case "show_plugins":
await this.show_plugins();
break;
case "update_plugin":
await this.update_plugin();
break;
case "run_invoices_notify":
await this.run_invoices_notify()
break;
case "run_charge_payment":
await this.run_charge_payment();
break;
case "run_late_invoice_notify":
await this.run_late_invoice_notify()
}
this.action();
});
}

Expand Down Expand Up @@ -162,7 +164,7 @@ export default class AdminHandler
const secure = result.secure === "true";

Logger.info(`Updating smtp config..`);
updateSMTP({
await updateSMTP({
host,
port,
username,
Expand All @@ -174,7 +176,7 @@ export default class AdminHandler
});
}

private async show()
private static async show()
{
Logger.info(CacheAdmin.array());
}
Expand Down Expand Up @@ -270,7 +272,7 @@ export default class AdminHandler
Logger.info(`Adding email..`);
// Check if email is valid
// eslint-disable-next-line no-useless-escape
if(!email.match(/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/))
if(!email.match(/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/))
{
Logger.error(`Invalid email`);
return resolve(false);
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/updateSMTP.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ConfigModel from "../Database/Models/Configs.model";
import { IConfigs } from "../Interfaces/Admin/Configs.interface";
import { IConfigs } from "@interface/Admin/Configs.interface";

export default async function updateSMTP(smtp: IConfigs["smtp"]): Promise<void>
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/Admin.cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IAdministrator } from "../Interfaces/Admin/Administrators.interface";
import { IAdministrator } from "@interface/Admin/Administrators.interface";

// Keeping this for a while..
export const CacheAdmin = new Map<IAdministrator["uid"], IAdministrator>();
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/Categories.cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ICategory } from "../Interfaces/Categories.interface";
import { ICategory } from "@interface/Categories.interface";

/**
* @deprecated
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/Configs.cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IConfigs } from "../Interfaces/Admin/Configs.interface";
import { IConfigs } from "@interface/Admin/Configs.interface";

export type CacheCN = keyof IConfigs;
/**
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/Customer.cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ICustomer } from "../Interfaces/Customer.interface";
import { ICustomer } from "@interface/Customer.interface";

/**
* @deprecated
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/Image.cache.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { IImage } from "../Interfaces/Images.interface";
import { IImage } from "@interface/Images.interface";

export const CacheImages = new Map<IImage["id"], IImage>();
2 changes: 1 addition & 1 deletion src/Cache/Invoices.cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IInvoice } from "../Interfaces/Invoice.interface";
import { IInvoice } from "@interface/Invoice.interface";

/**
* @deprecated
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/Order.cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IOrder } from "../Interfaces/Orders.interface";
import { IOrder } from "@interface/Orders.interface";

/**
* @deprecated
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/Product.cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IProduct } from "../Interfaces/Products.interface";
import { IProduct } from "@interface/Products.interface";

/**
* @deprecated
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/Transactions.cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ITransactions } from "../Interfaces/Transactions.interface";
import { ITransactions } from "@interface/Transactions.interface";

/**
* @deprecated
Expand Down
6 changes: 3 additions & 3 deletions src/Cache/reCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ export async function reCache_Transactions()
Logger.info(`Starting caching on transactions..`);
return new Promise(async (resolve) =>
{
const transa = await TransactionsModel.find();
for (const t of transa)
const transactions = await TransactionsModel.find();
for (const t of transactions)
{
Logger.cache(`Caching transaction ${t.uid}`);
CacheTransactions.set(t.uid, t);
Expand Down Expand Up @@ -142,7 +142,7 @@ export async function reCache_Configs()
},
smtp_emails: [],
}
new ConfigModel(smtpData).save();
await new ConfigModel(smtpData).save();

Logger.cache(`Caching config`);

Expand Down
8 changes: 4 additions & 4 deletions src/Config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import ConfigModel from "./Database/Models/Configs.model";
import { IConfigs } from "./Interfaces/Admin/Configs.interface";
import { IAllLanguages } from "./Interfaces/Lang/AllLang.interface";
import { IConfigs } from "@interface/Admin/Configs.interface";
import { IAllLanguages } from "@interface/Lang/AllLang.interface";

/**
* @description
* Used if this service is running in debug mode.
*/
export const DebugMode = process.env.DEBUG === "true" ? true : false;
export const DebugMode = process.env.DEBUG === "true";
export const HomeDir = ((__dirname.replace("\\build", "")).replace("/build", ""));
export const JWT_Access_Token = process.env.JWT_ACCESS_TOKEN ?? "";
export const d_Days = parseInt(process.env.D_DAYS ?? "30");
Expand Down Expand Up @@ -110,7 +110,7 @@ export const Company_Tax_Registered = async (): Promise<IConfigs["company"]["tax
{
const configs = await ConfigModel.findOne();
if(!configs) throw new Error("No configs found");
return configs.company?.tax_registered ?? (process.env.COMPANY_TAX_REGISTERED === "true" ? true : false);
return configs.company?.tax_registered ?? (process.env.COMPANY_TAX_REGISTERED === "true");
}
export const Company_Logo_Url = async (): Promise<IConfigs["company"]["logo_url"]> =>
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cron/Methods/Invoices.cron.methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function cron_notifyInvoices()

}
if(invoices.length > 0)
InvoiceNotifiedReport(invoices);
await InvoiceNotifiedReport(invoices);
});
}

Expand Down
6 changes: 3 additions & 3 deletions src/Cron/Orders.cron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export = function Cron_Orders()
Logger.info(GetText(Default_Language).cron.txt_Orders_Checking);
// Logger.info(`Checking orders..`);

// Check if the order needs to create a new invoice if order.dates.next_recylce is withing 14 days
// Check if the order needs to create a new invoice if order.dates.next_recycle is withing 14 days
OrderModel.find({
order_status: "active",
// order_status: {
Expand All @@ -30,7 +30,7 @@ export = function Cron_Orders()
{
Logger.info(GetText(Default_Language).cron.txt_Order_Checking(order.id));
// Logger.info(`Checking order ${order.id}`);
// Check if order.order_status is not "cancelled" or "fruad"
// Check if order.order_status is not "cancelled" or "fraud"
if(order.dates.next_recycle)
if(dateFormat.parse(order.dates.next_recycle, "YYYY-MM-DD").getTime() - new Date().getTime() <= d_Days * 24 * 60 * 60 * 1000)
{
Expand All @@ -54,7 +54,7 @@ export = function Cron_Orders()
await order.save();
}
if(newInvoices.length > 0)
InvoiceCreatedReport(newInvoices);
await InvoiceCreatedReport(newInvoices);
}
});

Expand Down
3 changes: 2 additions & 1 deletion src/Database/GraphQL/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export default async (server: Application) =>
let [login, password] = (Buffer.isBuffer(b64auth[1]) ? Buffer.from(b64auth[1], 'base64') : b64auth[1]).toString().split(':');
if(login.includes("==") || password.includes("=="))
{
login = atob(login);
//login = atob(login);
login = Buffer.from(login, 'base64').toString();
password = login.split(":")[1];
login = login.split(":")[0];
}
Expand Down
4 changes: 2 additions & 2 deletions src/Database/GraphQL/ResolverAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Logger from "../../Lib/Logger";
import GetText from "../../Translation/GetText";

export function resolverAdminAccess(resolvers: {
[key: string]: Resolver<any, any, any, any>;
[key: string]: Resolver;
})
{
Object.keys(resolvers).forEach((k) =>
Expand All @@ -26,7 +26,7 @@ export function resolverAdminAccess(resolvers: {
}

export function resolverUserAccess(resolvers: {
[key: string]: Resolver<any, any, any, any>;
[key: string]: Resolver;
})
{
Object.keys(resolvers).forEach((k) =>
Expand Down
Loading