Skip to content

Commit 7f11e9a

Browse files
authored
Merge pull request #92 from Tolfix/develop
v1.2.0
2 parents 9719a89 + b706014 commit 7f11e9a

File tree

96 files changed

+22027
-6945
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+22027
-6945
lines changed

.deepsource.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version = 1
2+
3+
[[analyzers]]
4+
name = "shell"
5+
enabled = true
6+
7+
[[analyzers]]
8+
name = "javascript"
9+
enabled = true
10+
11+
[analyzers.meta]
12+
plugins = ["react"]
13+
dialect = "typescript"
14+

apps/admin/src/components/products/Create.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const CreateProducts = (props: any) =>
5353
{ id: "one_time", name: "one_time" },
5454
{ id: "recurring", name: "recurring" },
5555
]} />
56-
<AutocompleteInput isRequired={false} source="recurring_method" choices={[
56+
<AutocompleteInput isRequired={false} defaultValue={undefined} source="recurring_method" choices={[
5757
{ id: "monthly", name: "monthly" },
5858
{ id: "quarterly", name: "quarterly" },
5959
{ id: "semi_annually", name: "semi_annually" },

apps/admin/src/components/products/Edit.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const EditProducts = (props: any) =>
5252
{ id: "one_time", name: "one_time" },
5353
{ id: "recurring", name: "recurring" },
5454
]} />
55-
<AutocompleteInput isRequired={false} source="recurring_method" choices={[
55+
<AutocompleteInput isRequired={false} defaultValue={undefined} source="recurring_method" choices={[
5656
{ id: "monthly", name: "monthly" },
5757
{ id: "quarterly", name: "quarterly" },
5858
{ id: "semi_annually", name: "semi_annually" },

apps/api/.env.example

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# Secret JWT token for authentication, don't share this with anyone.
22
JWT_ACCESS_TOKEN=
33

4-
# If in debug mode or note
5-
# (optional)
6-
DEBUG=
4+
DEBUG=cpg*
75

86
# The mongo database uri to use, if not set it will use the default: mongodb://localhost/cpg
97
MONGO_URI=

apps/api/Dockerfile

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,57 @@ FROM node:16-alpine as BUILDER
44
# Caching
55
RUN apk add --no-cache libc6-compat
66

7-
WORKDIR /app
8-
97
RUN apk update && \
108
apk upgrade && \
119
apk add git
1210

1311
RUN npm install -g @types/node \
1412
&& npm install -g [email protected]
1513

14+
WORKDIR /app
15+
1616
RUN npm i -g turbo
1717

1818
COPY . .
1919

20-
RUN npm install -w=api --force
20+
RUN turbo prune --scope=api --docker
2121

22-
RUN npm run build -w=packages
22+
##########################
2323

24-
RUN npm run build -w=api
24+
FROM node:16-alpine as INSTALLER
25+
RUN apk add --no-cache libc6-compat
26+
RUN apk update
27+
RUN apk add git
28+
WORKDIR /app
2529

26-
##########################
30+
COPY .gitignore .gitignore
31+
COPY --from=BUILDER /app/out/json/ .
32+
COPY --from=BUILDER /app/out/package-lock.json ./package-lock.json
33+
34+
RUN npm i --force
35+
RUN npm i -w=api --force
36+
37+
COPY --from=builder /app/out/full/ .
38+
39+
COPY turbo.json turbo.json
40+
41+
RUN npm run build --filter=api...
2742

2843
# APP
2944
FROM node:16-alpine as APP
3045

46+
RUN apk add --no-cache libc6-compat
47+
RUN apk update
48+
3149
ENV NODE_ENV=production
3250

33-
COPY --from=BUILDER /app/ .
51+
WORKDIR /app
52+
53+
# Currently idk how to get this to work, so copying root ig? with some files ignored from pruning at least.
54+
COPY --from=INSTALLER /app .
3455

3556
WORKDIR /app/apps/api
3657

37-
COPY --from=BUILDER /app/apps/api/ .
38-
3958
RUN apk update && \
4059
apk upgrade && \
4160
apk add git
@@ -49,4 +68,4 @@ ENV DISABLE_JSON_ERROR "true"
4968

5069
EXPOSE 3001
5170

52-
CMD [ "node", "./build/Main.js" ]
71+
CMD ["node", "./build/Main.js"]

apps/api/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@
4444
"request": "^2.88.2",
4545
"sequelize": "^6.15.0",
4646
"lib": "*",
47-
"stripe": "^8.186.1"
47+
"stripe": "^8.186.1",
48+
"@cpg/logger": "*"
4849
},
4950
"scripts": {
5051
"start": "node ./build/Main.js",
51-
"build": "tsc -b",
52+
"build": "tsc",
5253
"dev": "nodemon ./build/Main.js",
5354
"lint": "eslint ./src --ext .ts"
5455
},

apps/api/src/Admin/AdminHandler.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { Logger } from "lib";
1+
import Logger from "@cpg/logger";
22
import chalk from "chalk";
33
import clear from "clear";
44
import figlet from "figlet";
55
import Prompt, { cacheCommands } from "./Commands/Prompt";
66
import inquirer from 'inquirer';
77

8+
const log = new Logger("cpg:api:admin:AdminHandler");
9+
810
export default class AdminHandler
911
{
1012

@@ -52,7 +54,7 @@ export default class AdminHandler
5254
}
5355
}).catch((error) =>
5456
{
55-
Logger.error(error);
57+
log.error(error);
5658
this.action();
5759
});
5860
}

apps/api/src/Admin/CreateAdmin.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@ import bcrypt from "bcryptjs";
22
import { CacheAdmin, getAdminByUsername } from "../Cache/Admin.cache";
33
import AdminModel from "../Database/Models/Administrators.model";
44
import { idAdmin } from "../Lib/Generator";
5-
import { Logger } from "lib";
5+
import Logger from "@cpg/logger";
6+
7+
const log = new Logger("cpg:api:admin:CreateAdmin");
68

79
export default function createAdmin(username: string, password: string)
810
{
911
if (CacheAdmin.get(getAdminByUsername(username) ?? 'ADM_'))
10-
return Logger.warning(`Administrator ${username} already exists`);
12+
return log.warn(`Administrator ${username} already exists`);
1113

1214
bcrypt.genSalt(10, (err, salt) =>
1315
{
1416
bcrypt.hash(password, salt, (err, hash) =>
1517
{
1618
if (err)
17-
return Logger.error(err);
19+
return log.error(err);
1820

1921
const info = {
2022
username,

apps/api/src/Cache/reCache.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import ImageModel from "../Database/Models/Images.model";
55
import OrderModel from "../Database/Models/Orders.model";
66
import ProductModel from "../Database/Models/Products.model";
77
import TransactionsModel from "../Database/Models/Transactions.model";
8-
import { Logger } from "lib";
98
import { CacheAdmin } from "./Admin.cache";
109
import { CacheCategories } from "./Categories.cache";
1110
import { CacheCustomer } from "./Customer.cache";
@@ -16,19 +15,22 @@ import InvoiceModel from "../Database/Models/Invoices.model";
1615
import { CacheInvoice } from "./Invoices.cache";
1716
import { Company_Currency } from "../Config";
1817
import { TPaymentCurrency } from "interfaces/types/Currencies";
18+
import Logger from "@cpg/logger";
19+
20+
const log = new Logger("cpg:api:cache:reCache");
1921

2022
/**
2123
* @deprecated
2224
*/
2325
export function reCache_Categories()
2426
{
25-
Logger.info(`Starting caching on categories..`);
27+
log.info(`Starting caching on categories..`);
2628
return new Promise(async (resolve) =>
2729
{
2830
const categories = await CategoryModel.find();
2931
for (const c of categories)
3032
{
31-
Logger.cache(`Caching category ${c.uid}`);
33+
log.debug(`Caching category ${c.uid}`);
3234
CacheCategories.set(c.uid, c);
3335
}
3436
return resolve(true);
@@ -37,13 +39,13 @@ export function reCache_Categories()
3739

3840
export async function reCache_Admin()
3941
{
40-
Logger.info(`Starting caching on admins..`);
42+
log.info(`Starting caching on admins..`);
4143
return new Promise(async (resolve) =>
4244
{
4345
const admin = await AdminModel.find();
4446
for (const a of admin)
4547
{
46-
Logger.cache(`Caching admin ${a.uid}`);
48+
log.debug(`Caching admin ${a.uid}`);
4749
CacheAdmin.set(a.uid, a);
4850
}
4951
return resolve(true);
@@ -52,7 +54,7 @@ export async function reCache_Admin()
5254

5355
export async function reCache_Customers()
5456
{
55-
Logger.info(`Starting caching on customers..`);
57+
log.info(`Starting caching on customers..`);
5658
return new Promise(async (resolve) =>
5759
{
5860
const customer = await CustomerModel.find();
@@ -65,7 +67,7 @@ export async function reCache_Customers()
6567
c.currency = companyCurrency.toLocaleUpperCase() as TPaymentCurrency;
6668
await c.save();
6769
}
68-
// Logger.cache(`Caching customer ${c.uid}`);
70+
// log.cache(`Caching customer ${c.uid}`);
6971
CacheCustomer.set(c.uid, c);
7072
}
7173
return resolve(true);
@@ -74,7 +76,7 @@ export async function reCache_Customers()
7476

7577
export async function reCache_Product()
7678
{
77-
Logger.info(`Starting caching on products..`);
79+
log.info(`Starting caching on products..`);
7880
return new Promise(async (resolve) =>
7981
{
8082
const product = await ProductModel.find();
@@ -100,7 +102,7 @@ export async function reCache_Product()
100102

101103
export async function reCache_Transactions()
102104
{
103-
Logger.info(`Starting caching on transactions..`);
105+
log.info(`Starting caching on transactions..`);
104106
return new Promise(async (resolve) =>
105107
{
106108
const transactions = await TransactionsModel.find();
@@ -124,7 +126,7 @@ export async function reCache_Transactions()
124126

125127
export async function reCache_Orders()
126128
{
127-
Logger.info(`Starting caching on orders..`);
129+
log.info(`Starting caching on orders..`);
128130
return new Promise(async (resolve) =>
129131
{
130132
const order = await OrderModel.find();
@@ -143,11 +145,11 @@ export async function reCache_Orders()
143145

144146
export async function reCache_Configs()
145147
{
146-
Logger.info(`Starting caching on configs..`);
148+
log.info(`Starting caching on configs..`);
147149
return new Promise(async (resolve) =>
148150
{
149151
const config = await ConfigModel.find();
150-
// Logger.debug(config);
152+
// log.debug(config);
151153
if (!config[0])
152154
{
153155
const smtpData = {
@@ -162,15 +164,15 @@ export async function reCache_Configs()
162164
}
163165
await new ConfigModel(smtpData).save();
164166

165-
Logger.cache(`Caching config`);
167+
log.debug(`Caching config`);
166168

167169
CacheConfig.set("smtp", smtpData.smtp);
168170
CacheConfig.set("smtp_emails", smtpData.smtp_emails);
169171

170172
return resolve(true);
171173
}
172174

173-
Logger.cache(`Caching config`);
175+
log.debug(`Caching config`);
174176
const c = config[0];
175177

176178
// Check if c has payment_methods
@@ -199,13 +201,13 @@ export async function reCache_Configs()
199201

200202
export async function reCache_Images()
201203
{
202-
Logger.info(`Starting caching on images..`);
204+
log.info(`Starting caching on images..`);
203205
return new Promise(async (resolve) =>
204206
{
205207
const image = await ImageModel.find();
206208
for (const o of image)
207209
{
208-
Logger.cache(`Caching image ${o.id}`);
210+
log.debug(`Caching image ${o.id}`);
209211
CacheImages.set(o.id, o);
210212
}
211213
return resolve(true);
@@ -215,7 +217,7 @@ export async function reCache_Images()
215217

216218
export async function reCache_Invoices()
217219
{
218-
Logger.info(`Starting caching on invoices..`);
220+
log.info(`Starting caching on invoices..`);
219221
return new Promise(async (resolve) =>
220222
{
221223
const invoice = await InvoiceModel.find();
@@ -243,7 +245,7 @@ export async function reCache_Invoices()
243245
await o.save();
244246
}
245247

246-
Logger.cache(`Caching invoice ${o.uid}`);
248+
log.debug(`Caching invoice ${o.uid}`);
247249
CacheInvoice.set(o.uid, o);
248250
}
249251
return resolve(true);

apps/api/src/Config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { IAllLanguages } from "interfaces/Lang/AllLang.interface";
66
* @description
77
* Used if this service is running in debug mode.
88
*/
9-
export const DebugMode = process.env.DEBUG === "true";
9+
export const DebugMode = process.env.DEBUG_MODE === "true";
1010
export const HomeDir = ((__dirname.replace("\\build", "")).replace("/build", ""));
1111
export const JWT_Access_Token = process.env.JWT_ACCESS_TOKEN ?? "";
1212
export const d_Days = parseInt(process.env.D_DAYS ?? "30");

0 commit comments

Comments
 (0)