Skip to content

Commit

Permalink
feat: ✨ Fix to issue #34
Browse files Browse the repository at this point in the history
  • Loading branch information
Tolfx committed May 19, 2022
1 parent 9359177 commit 670d96e
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 89 deletions.
6 changes: 1 addition & 5 deletions apps/admin/src/components/customers/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ import { currencyCodes } from "lib/Currencies";
import { Edit, FormTab, PasswordInput, AutocompleteInput, TabbedForm, TextInput, SelectInput, ArrayInput, SimpleFormIterator, NumberInput, ReferenceInput, useEditController } from "react-admin";
//@ts-ignore
import MarkdownInput from 'ra-input-markdown';
import React from "react";
import { IInvoice } from "interfaces/Invoice.interface";

export const EditCustomer = (props: any) =>
{
const controllerProps = useEditController(props);
const { resource, record, save } = controllerProps;

// get id
const id = props.id;

Expand Down Expand Up @@ -53,7 +49,7 @@ export const EditCustomer = (props: any) =>
<ReferenceInput filterToQuery={(searchText: any) => ({
"id": searchText,
customer_uid: id,
})} perPage={100} label="Invoice id" source="invoice_id" reference="invoices">
})} perPage={100} allowEmpty label="Invoice id" source="invoice_id" reference="invoices">
<AutocompleteInput
isRequired={false}
optionText="id"
Expand Down
2 changes: 1 addition & 1 deletion apps/admin/src/components/images/Create.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import
{
Create, FileField, FileInput, FormTab,
Create, FormTab,
TabbedForm,
} from "react-admin";

Expand Down
9 changes: 1 addition & 8 deletions apps/admin/src/components/invoices/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,16 @@ import
ReferenceArrayInput, ReferenceInput, AutocompleteInput,
SimpleFormIterator,
TabbedForm,
useGetOne,
SelectInput,
useEditController,
} from "react-admin";
//@ts-ignore
import MarkdownInput from 'ra-input-markdown';
import { currencyCodes } from "lib/Currencies";
import RenderFullName from "../../lib/RenderFullName";
import React from "react";
import { ICustomer } from "interfaces/Customer.interface";

export const EditInvoices = (props: any) =>
{
const controllerProps = useEditController(props);
const { resource, record, save } = controllerProps;
console.log(record)
return (
<Edit value={controllerProps} mutationMode="pessimistic" {...props}>
<TabbedForm>
Expand Down Expand Up @@ -100,8 +94,7 @@ export const EditInvoices = (props: any) =>
</SimpleFormIterator>
</ArrayInput>

{/* @ts-ignore */}
<ReferenceArrayInput filterToQuery={searchText => ({
<ReferenceArrayInput filterToQuery={(searchText: any) => ({
"id": searchText,
})} perPage={100} source="transactions" reference="transactions">
<AutocompleteArrayInput
Expand Down
9 changes: 0 additions & 9 deletions apps/admin/src/components/orders/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,6 @@ export const CreateOrders = (props: any) =>
return { id: e, name: e };
})} />
</FormTab>
<FormTab label="Invoices">
{/* @ts-ignore */}
<ReferenceArrayInput filterToQuery={searchText => ({
"id": searchText,
})} perPage={100} source="invoices" reference="invoices">
<AutocompleteInput optionText={(record) => record?.id?.toString() ?? ""} />
</ReferenceArrayInput>

</FormTab>
</TabbedForm>
</Create>
);
3 changes: 2 additions & 1 deletion apps/admin/src/components/orders/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import
TabbedForm,
TextInput,
FormDataConsumer,
AutocompleteArrayInput,
} from "react-admin";
import RenderFullName from "../../lib/RenderFullName";

Expand Down Expand Up @@ -98,7 +99,7 @@ export const EditOrders = (props: any) =>
<FormTab label="Invoices">

<ReferenceArrayInput source="invoices" reference="invoices">
<AutocompleteInput optionText={(record) => record?.id?.toString() ?? ""} />
<AutocompleteArrayInput optionText={(record) => record?.id?.toString() ?? ""} />
</ReferenceArrayInput>

</FormTab>
Expand Down
1 change: 0 additions & 1 deletion apps/admin/src/components/orders/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const OrderList = (props: any) => (
<TextField label="Id" source="id" />
<ReferenceField label="Customer" source="customer_uid" reference="customers">
<FunctionField
// @ts-ignore
render={RenderFullName}
source="personal.first_name"
/>
Expand Down
57 changes: 36 additions & 21 deletions apps/api/src/Cache/reCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export async function reCache_Customers()
c.currency = companyCurrency.toLocaleUpperCase() as TPaymentCurrency;
await c.save();
}
Logger.cache(`Caching customer ${c.uid}`);
// Logger.cache(`Caching customer ${c.uid}`);
CacheCustomer.set(c.uid, c);
}
return resolve(true);
Expand All @@ -81,7 +81,7 @@ export async function reCache_Product()
return new Promise(async (resolve) =>
{
const product = await ProductModel.find();
for (const c of product)
for await (const c of product)
{
// Check if product has currency
if (!c.currency)
Expand All @@ -90,44 +90,55 @@ export async function reCache_Product()
c.currency = companyCurrency.toLocaleUpperCase() as TPaymentCurrency;
await c.save();
}
Logger.cache(`Caching product ${c.uid}`);
CacheProduct.set(c.uid, c);
if (typeof c.category_uid === "string")
{
c.category_uid = parseInt(c.category_uid);
await c.save();
}
// CacheProduct.set(c.uid, c);
}
return resolve(true);
});
}

/**
* @deprecated
*/
export async function reCache_Transactions()
{
Logger.info(`Starting caching on transactions..`);
return new Promise(async (resolve) =>
{
const transactions = await TransactionsModel.find();
for (const t of transactions)
for await (const t of transactions)
{
Logger.cache(`Caching transaction ${t.uid}`);
CacheTransactions.set(t.uid, t);
if (typeof t.customer_uid === "string")
{
t.customer_uid = parseInt(t.customer_uid);
t.save()
}
if (typeof t.invoice_uid === "string")
{
t.invoice_uid = parseInt(t.invoice_uid);
await t.save()
}
// CacheTransactions.set(t.uid, t);
}
return resolve(true);
});
}

/**
* @deprecated
*/
export async function reCache_Orders()
{
Logger.info(`Starting caching on orders..`);
return new Promise(async (resolve) =>
{
const order = await OrderModel.find();
for (const o of order)
for await (const o of order)
{
Logger.cache(`Caching order ${o.uid}`);
CacheOrder.set(o.uid, o);
if (typeof o.customer_uid === "string")
{
o.customer_uid = parseInt(o.customer_uid);
await o.save()
}
// CacheOrder.set(o.uid, o);
}
return resolve(true);
});
Expand Down Expand Up @@ -205,9 +216,6 @@ export async function reCache_Images()
}


/**
* @deprecated
*/
export async function reCache_Invoices()
{
Logger.info(`Starting caching on invoices..`);
Expand All @@ -223,6 +231,13 @@ export async function reCache_Invoices()
o.currency = companyCurrency.toLocaleUpperCase() as TPaymentCurrency;
await o.save();
}
if (typeof o.customer_uid === "string")
{
console.log(o.customer_uid, typeof o.customer_uid);
o.customer_uid = parseInt(o.customer_uid);
o.markModified("customer_uid");
await o.save();
}
Logger.cache(`Caching invoice ${o.uid}`);
CacheInvoice.set(o.uid, o);
}
Expand All @@ -237,8 +252,8 @@ export async function reCache()
await reCache_Admin();
await reCache_Customers();
await reCache_Product();
// await reCache_Transactions();
// await reCache_Orders();
await reCache_Transactions();
await reCache_Orders();
await reCache_Images();
await reCache_Invoices();
}
4 changes: 2 additions & 2 deletions apps/api/src/Database/Models/Invoices.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const InvoiceSchema = new Schema
},

customer_uid: {
type: String,
type: Number,
required: true,
},

Expand Down Expand Up @@ -87,7 +87,7 @@ const InvoiceSchema = new Schema
},

transactions: {
type: [String],
type: [Number],
default: [],
},

Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/Database/Models/Orders.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const OrderSchema = new Schema
},

customer_uid: {
type: String,
type: Number,
required: true,
},

Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/Database/Models/Products.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const ProductSchema = new Schema
},

category_uid: {
type: String,
type: Number,
required: true,
},

Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/Database/Models/Quotes.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const QuotesSchema = new Schema
},

customer_uid: {
type: String,
type: Number,
required: true,
},

Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/Database/Models/Subscriptions.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const SubscriptionSchema = new Schema
},

customer_uid: {
type: String,
type: Number,
required: true,
},

Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/Database/Models/Transactions.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const TransactionsSchema = new Schema
},

customer_uid: {
type: Number || String,
type: Number,
required: false
},

Expand Down
32 changes: 16 additions & 16 deletions apps/api/src/Payments/Stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ const cacheIntents = new Map<string, stripe.Response<stripe.PaymentIntent>>();
const cacheSetupIntents = new Map<string, stripe.Response<stripe.SetupIntent>>();


export const createCreditIntent = async ({
amount,
currency,
customer,
}: ICreateCreditIntentOptions) =>
{
const intent = await Stripe.paymentIntents.create({
amount: 0,
currency: Company_Currency,
payment_method_types: ["card"],
confirm: true,
return_url: `${Full_Domain}/v2/payments/stripe/webhook`,
});
cacheIntents.set(intent.id, intent);
return intent;
}
// export const createCreditIntent = async ({
// amount,
// currency,
// customer,
// }: ICreateCreditIntentOptions) =>
// {
// const intent = await Stripe.paymentIntents.create({
// amount: 0,
// currency: Company_Currency,
// payment_method_types: ["card"],
// confirm: true,
// return_url: `${Full_Domain}/v2/payments/stripe/webhook`,
// });
// cacheIntents.set(intent.id, intent);
// return intent;
// }

// Create a method that will create a payment intent from an order
export const CreatePaymentIntent = async (invoice: IInvoice) =>
Expand Down
Loading

0 comments on commit 670d96e

Please sign in to comment.