autosync_backend2 1.1.23 → 1.1.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +168 -52
- package/dist/index.js +263 -28
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Elysia } from "elysia";
|
|
2
|
-
declare const app: Elysia<"", {
|
|
2
|
+
export declare const app: Elysia<"", {
|
|
3
3
|
decorator: {
|
|
4
4
|
publicPermissions: {
|
|
5
5
|
readonly code: import("./lib/permissions").PermissionCode;
|
|
@@ -388,6 +388,13 @@ declare const app: Elysia<"", {
|
|
|
388
388
|
clientId: import("@sinclair/typebox").TString;
|
|
389
389
|
clientSecret: import("@sinclair/typebox").TString;
|
|
390
390
|
}>;
|
|
391
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
392
|
+
type: import("@sinclair/typebox").TLiteral<"Qpay">;
|
|
393
|
+
sub: import("@sinclair/typebox").TObject<{
|
|
394
|
+
username: import("@sinclair/typebox").TString;
|
|
395
|
+
password: import("@sinclair/typebox").TString;
|
|
396
|
+
invoiceCode: import("@sinclair/typebox").TString;
|
|
397
|
+
}>;
|
|
391
398
|
}>]>]>;
|
|
392
399
|
readonly "CrmCpOrderPaymentModel.wsQuery": import("@sinclair/typebox").TObject<{
|
|
393
400
|
paymentId: import("@sinclair/typebox").TString;
|
|
@@ -1432,22 +1439,34 @@ declare const app: Elysia<"", {
|
|
|
1432
1439
|
totalCount: number;
|
|
1433
1440
|
totalPage: number;
|
|
1434
1441
|
result: {
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1442
|
+
product: {
|
|
1443
|
+
supplierId: string;
|
|
1444
|
+
productId: string | null;
|
|
1445
|
+
name: string;
|
|
1446
|
+
description: string | null;
|
|
1447
|
+
priceSell: number;
|
|
1448
|
+
priceBuy: number;
|
|
1449
|
+
barCode: string | null;
|
|
1450
|
+
oen: string | null;
|
|
1451
|
+
partNumber: string;
|
|
1452
|
+
alias: string | null;
|
|
1453
|
+
companyId: string;
|
|
1454
|
+
type: string | null;
|
|
1455
|
+
id: string;
|
|
1456
|
+
createdAt: string;
|
|
1457
|
+
updatedAt: string;
|
|
1458
|
+
deletedAt: string | null;
|
|
1459
|
+
};
|
|
1460
|
+
supplier: {
|
|
1461
|
+
name: string;
|
|
1462
|
+
phone: string | null;
|
|
1463
|
+
address: string | null;
|
|
1464
|
+
image: string | null;
|
|
1465
|
+
id: string;
|
|
1466
|
+
createdAt: string;
|
|
1467
|
+
updatedAt: string;
|
|
1468
|
+
deletedAt: string | null;
|
|
1469
|
+
};
|
|
1451
1470
|
}[];
|
|
1452
1471
|
};
|
|
1453
1472
|
422: {
|
|
@@ -1822,6 +1841,27 @@ declare const app: Elysia<"", {
|
|
|
1822
1841
|
totalCount: number;
|
|
1823
1842
|
totalPage: number;
|
|
1824
1843
|
result: {
|
|
1844
|
+
item: {
|
|
1845
|
+
warehouseId: string;
|
|
1846
|
+
productId: string;
|
|
1847
|
+
quantity: number;
|
|
1848
|
+
safetyStock: number;
|
|
1849
|
+
shelfNumber: string | null;
|
|
1850
|
+
id: string;
|
|
1851
|
+
createdAt: string;
|
|
1852
|
+
updatedAt: string;
|
|
1853
|
+
deletedAt: string | null;
|
|
1854
|
+
};
|
|
1855
|
+
supplier: {
|
|
1856
|
+
name: string;
|
|
1857
|
+
phone: string | null;
|
|
1858
|
+
address: string | null;
|
|
1859
|
+
image: string | null;
|
|
1860
|
+
id: string;
|
|
1861
|
+
createdAt: string;
|
|
1862
|
+
updatedAt: string;
|
|
1863
|
+
deletedAt: string | null;
|
|
1864
|
+
};
|
|
1825
1865
|
product: {
|
|
1826
1866
|
supplierId: string;
|
|
1827
1867
|
productId: string | null;
|
|
@@ -1840,15 +1880,6 @@ declare const app: Elysia<"", {
|
|
|
1840
1880
|
updatedAt: string;
|
|
1841
1881
|
deletedAt: string | null;
|
|
1842
1882
|
};
|
|
1843
|
-
warehouseId: string;
|
|
1844
|
-
productId: string;
|
|
1845
|
-
quantity: number;
|
|
1846
|
-
safetyStock: number;
|
|
1847
|
-
shelfNumber: string | null;
|
|
1848
|
-
id: string;
|
|
1849
|
-
createdAt: string;
|
|
1850
|
-
updatedAt: string;
|
|
1851
|
-
deletedAt: string | null;
|
|
1852
1883
|
}[];
|
|
1853
1884
|
};
|
|
1854
1885
|
422: {
|
|
@@ -3524,28 +3555,41 @@ declare const app: Elysia<"", {
|
|
|
3524
3555
|
} & {
|
|
3525
3556
|
payment: {
|
|
3526
3557
|
storepay: {
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3558
|
+
post: {
|
|
3559
|
+
body: {
|
|
3560
|
+
paymentPackageId?: string | null | undefined;
|
|
3561
|
+
phone: number;
|
|
3562
|
+
cpOrderId: string;
|
|
3563
|
+
amount: number;
|
|
3564
|
+
};
|
|
3565
|
+
params: {};
|
|
3566
|
+
query: unknown;
|
|
3567
|
+
headers: unknown;
|
|
3568
|
+
response: {
|
|
3569
|
+
200: {
|
|
3531
3570
|
id: string;
|
|
3571
|
+
createdAt: string;
|
|
3572
|
+
updatedAt: string;
|
|
3573
|
+
deletedAt: string | null;
|
|
3574
|
+
state: "NOT_PAID" | "PENDING" | "FAILED" | "EXPIRED" | "PAID" | "DECLINED" | "CANCELED" | "REFUNDING" | "REFUNDED";
|
|
3575
|
+
cpOrderId: string;
|
|
3576
|
+
paymentPackageId: string | null;
|
|
3577
|
+
paymentMethod: "CASH" | "BANK_TRANSFER" | "POS_TERMINAL" | "PAYMENT_PACKAGE";
|
|
3578
|
+
paymentChannel: string;
|
|
3579
|
+
amount: number;
|
|
3580
|
+
invoiceNumber: string | null;
|
|
3532
3581
|
};
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
message?: string;
|
|
3545
|
-
found?: unknown;
|
|
3546
|
-
property?: string;
|
|
3547
|
-
expected?: string;
|
|
3548
|
-
};
|
|
3582
|
+
404: "Төлбөрийн тохиргоо олдсонгүй.";
|
|
3583
|
+
400: string;
|
|
3584
|
+
500: "Сервер алдаа гарлаа";
|
|
3585
|
+
422: {
|
|
3586
|
+
type: "validation";
|
|
3587
|
+
on: string;
|
|
3588
|
+
summary?: string;
|
|
3589
|
+
message?: string;
|
|
3590
|
+
found?: unknown;
|
|
3591
|
+
property?: string;
|
|
3592
|
+
expected?: string;
|
|
3549
3593
|
};
|
|
3550
3594
|
};
|
|
3551
3595
|
};
|
|
@@ -3553,9 +3597,9 @@ declare const app: Elysia<"", {
|
|
|
3553
3597
|
};
|
|
3554
3598
|
} & {
|
|
3555
3599
|
payment: {
|
|
3556
|
-
|
|
3600
|
+
storepay: {
|
|
3557
3601
|
":id": {
|
|
3558
|
-
|
|
3602
|
+
get: {
|
|
3559
3603
|
body: unknown;
|
|
3560
3604
|
params: {
|
|
3561
3605
|
id: string;
|
|
@@ -3563,7 +3607,10 @@ declare const app: Elysia<"", {
|
|
|
3563
3607
|
query: unknown;
|
|
3564
3608
|
headers: unknown;
|
|
3565
3609
|
response: {
|
|
3566
|
-
200:
|
|
3610
|
+
200: undefined;
|
|
3611
|
+
404: "Төлбөрийн тохиргоо олдсонгүй." | "Төлбөрийн мэдээлэл олдсонгүй.";
|
|
3612
|
+
400: string;
|
|
3613
|
+
500: "Сервер алдаа гарлаа";
|
|
3567
3614
|
422: {
|
|
3568
3615
|
type: "validation";
|
|
3569
3616
|
on: string;
|
|
@@ -3580,12 +3627,14 @@ declare const app: Elysia<"", {
|
|
|
3580
3627
|
};
|
|
3581
3628
|
} & {
|
|
3582
3629
|
payment: {
|
|
3583
|
-
|
|
3630
|
+
ubpay: {
|
|
3584
3631
|
post: {
|
|
3585
3632
|
body: {
|
|
3586
3633
|
paymentPackageId?: string | null | undefined;
|
|
3587
|
-
|
|
3634
|
+
state: "NOT_PAID" | "PENDING" | "FAILED" | "EXPIRED" | "PAID" | "DECLINED" | "CANCELED" | "REFUNDING" | "REFUNDED";
|
|
3588
3635
|
cpOrderId: string;
|
|
3636
|
+
paymentMethod: "CASH" | "BANK_TRANSFER" | "POS_TERMINAL" | "PAYMENT_PACKAGE";
|
|
3637
|
+
paymentChannel: string;
|
|
3589
3638
|
amount: number;
|
|
3590
3639
|
};
|
|
3591
3640
|
params: {};
|
|
@@ -3593,6 +3642,7 @@ declare const app: Elysia<"", {
|
|
|
3593
3642
|
headers: unknown;
|
|
3594
3643
|
response: {
|
|
3595
3644
|
200: {
|
|
3645
|
+
qrCode: string;
|
|
3596
3646
|
id: string;
|
|
3597
3647
|
createdAt: string;
|
|
3598
3648
|
updatedAt: string;
|
|
@@ -3624,6 +3674,66 @@ declare const app: Elysia<"", {
|
|
|
3624
3674
|
} & {
|
|
3625
3675
|
payment: {
|
|
3626
3676
|
ubpay: {
|
|
3677
|
+
":id": {
|
|
3678
|
+
post: {
|
|
3679
|
+
body: unknown;
|
|
3680
|
+
params: {
|
|
3681
|
+
id: string;
|
|
3682
|
+
};
|
|
3683
|
+
query: unknown;
|
|
3684
|
+
headers: unknown;
|
|
3685
|
+
response: {
|
|
3686
|
+
200: undefined;
|
|
3687
|
+
404: "Төлбөрийн тохиргоо олдсонгүй." | "Төлбөрийн мэдээлэл олдсонгүй.";
|
|
3688
|
+
400: string;
|
|
3689
|
+
500: "Сервер алдаа гарлаа";
|
|
3690
|
+
422: {
|
|
3691
|
+
type: "validation";
|
|
3692
|
+
on: string;
|
|
3693
|
+
summary?: string;
|
|
3694
|
+
message?: string;
|
|
3695
|
+
found?: unknown;
|
|
3696
|
+
property?: string;
|
|
3697
|
+
expected?: string;
|
|
3698
|
+
};
|
|
3699
|
+
};
|
|
3700
|
+
};
|
|
3701
|
+
};
|
|
3702
|
+
};
|
|
3703
|
+
};
|
|
3704
|
+
} & {
|
|
3705
|
+
payment: {
|
|
3706
|
+
qpay: {
|
|
3707
|
+
":id": {
|
|
3708
|
+
get: {
|
|
3709
|
+
body: unknown;
|
|
3710
|
+
params: {
|
|
3711
|
+
id: string;
|
|
3712
|
+
};
|
|
3713
|
+
query: unknown;
|
|
3714
|
+
headers: unknown;
|
|
3715
|
+
response: {
|
|
3716
|
+
200: undefined;
|
|
3717
|
+
404: "Төлбөрийн тохиргоо олдсонгүй." | "Төлбөрийн мэдээлэл олдсонгүй.";
|
|
3718
|
+
400: string;
|
|
3719
|
+
500: "Сервер алдаа гарлаа";
|
|
3720
|
+
422: {
|
|
3721
|
+
type: "validation";
|
|
3722
|
+
on: string;
|
|
3723
|
+
summary?: string;
|
|
3724
|
+
message?: string;
|
|
3725
|
+
found?: unknown;
|
|
3726
|
+
property?: string;
|
|
3727
|
+
expected?: string;
|
|
3728
|
+
};
|
|
3729
|
+
};
|
|
3730
|
+
};
|
|
3731
|
+
};
|
|
3732
|
+
};
|
|
3733
|
+
};
|
|
3734
|
+
} & {
|
|
3735
|
+
payment: {
|
|
3736
|
+
qpay: {
|
|
3627
3737
|
post: {
|
|
3628
3738
|
body: {
|
|
3629
3739
|
paymentPackageId?: string | null | undefined;
|
|
@@ -3762,6 +3872,13 @@ declare const app: Elysia<"", {
|
|
|
3762
3872
|
clientId: string;
|
|
3763
3873
|
clientSecret: string;
|
|
3764
3874
|
};
|
|
3875
|
+
} | {
|
|
3876
|
+
type: "Qpay";
|
|
3877
|
+
sub: {
|
|
3878
|
+
password: string;
|
|
3879
|
+
username: string;
|
|
3880
|
+
invoiceCode: string;
|
|
3881
|
+
};
|
|
3765
3882
|
});
|
|
3766
3883
|
params: {};
|
|
3767
3884
|
query: unknown;
|
|
@@ -4916,4 +5033,3 @@ declare const app: Elysia<"", {
|
|
|
4916
5033
|
standaloneSchema: {};
|
|
4917
5034
|
}>;
|
|
4918
5035
|
export type App = typeof app;
|
|
4919
|
-
export {};
|
package/dist/index.js
CHANGED
|
@@ -143420,11 +143420,11 @@ var WarehouseProductLogic;
|
|
|
143420
143420
|
return and(softDeletedFilter(warehouseProductTable), eq(warehouseProductTable.companyId, user2.companyId), or(ilike(warehouseProductTable.name, ilikeSearch), ilike(warehouseProductTable.barCode, ilikeSearch), ilike(warehouseProductTable.oen, ilikeSearch), ilike(warehouseProductTable.partNumber, ilikeSearch))?.if(!!query.search), eq(warehouseProductTable.priceSell, query.priceSell ?? 0).if(query.priceSell), eq(warehouseProductTable.productId, query.productId ?? "").if(query.productId), eq(warehouseProductTable.supplierId, query.supplierId ?? "").if(query.supplierId), eq(warehouseProductTable.id, query.id ?? "").if(query.id), inArray(warehouseProductTable.id, query.ids ?? []).if(query.ids?.length));
|
|
143421
143421
|
};
|
|
143422
143422
|
WarehouseProductLogic.select = async (query, user2) => {
|
|
143423
|
-
const columns = getTableColumns(warehouseProductTable);
|
|
143424
143423
|
const baseQuery = db_default.select({
|
|
143425
|
-
|
|
143424
|
+
product: warehouseProductTable,
|
|
143425
|
+
supplier: techdocSupplierTable,
|
|
143426
143426
|
totalCount: totalCountSql
|
|
143427
|
-
}).from(warehouseProductTable).where(WarehouseProductLogic.getFilter(query, user2)).$dynamic();
|
|
143427
|
+
}).from(warehouseProductTable).innerJoin(techdocSupplierTable, eq(techdocSupplierTable.id, warehouseProductTable.supplierId)).where(WarehouseProductLogic.getFilter(query, user2)).$dynamic();
|
|
143428
143428
|
const result = await pagination_helper_default(baseQuery, query.pagination);
|
|
143429
143429
|
const content = {
|
|
143430
143430
|
totalCount: result[0]?.totalCount ?? 0,
|
|
@@ -143550,8 +143550,8 @@ var CrmCpOrderProductLogic;
|
|
|
143550
143550
|
const sk = product.result[0];
|
|
143551
143551
|
const [result] = await db_default.insert(crmCpOrderProductTable).values({
|
|
143552
143552
|
...body,
|
|
143553
|
-
priceUnit: sk.priceSell,
|
|
143554
|
-
priceTotal: body.quantity * sk.priceSell
|
|
143553
|
+
priceUnit: sk.product.priceSell,
|
|
143554
|
+
priceTotal: body.quantity * sk.product.priceSell
|
|
143555
143555
|
}).returning().onConflictDoUpdate({
|
|
143556
143556
|
target: [
|
|
143557
143557
|
crmCpOrderProductTable.cpOrderId,
|
|
@@ -143580,14 +143580,14 @@ var CrmCpOrderProductLogic;
|
|
|
143580
143580
|
}
|
|
143581
143581
|
const insertValues = [];
|
|
143582
143582
|
for (const item of body) {
|
|
143583
|
-
const serviceKind = serviceKinds.result.find((s) => s.id === item.companyProductId);
|
|
143583
|
+
const serviceKind = serviceKinds.result.find((s) => s.product.id === item.companyProductId);
|
|
143584
143584
|
if (!serviceKind) {
|
|
143585
143585
|
return status("Not Found", "\u0411\u0430\u0440\u0430\u0430 \u043E\u043B\u0434\u0441\u043E\u043D\u0433\u04AF\u0439.");
|
|
143586
143586
|
}
|
|
143587
143587
|
insertValues.push({
|
|
143588
143588
|
...item,
|
|
143589
|
-
priceUnit: item.priceUnit ?? serviceKind.priceSell,
|
|
143590
|
-
priceTotal: item.quantity * (item.priceUnit ?? serviceKind.priceSell)
|
|
143589
|
+
priceUnit: item.priceUnit ?? serviceKind.product.priceSell,
|
|
143590
|
+
priceTotal: item.quantity * (item.priceUnit ?? serviceKind.product.priceSell)
|
|
143591
143591
|
});
|
|
143592
143592
|
}
|
|
143593
143593
|
await tdb.insert(crmCpOrderProductTable).values(insertValues);
|
|
@@ -143920,13 +143920,125 @@ var __async = (__this, __arguments, generator3) => {
|
|
|
143920
143920
|
step((generator3 = generator3.apply(__this, __arguments)).next());
|
|
143921
143921
|
});
|
|
143922
143922
|
};
|
|
143923
|
+
var Qpay = class {
|
|
143924
|
+
constructor(username2, password, invoiceCode, saveToken) {
|
|
143925
|
+
this.baseUrl = "https://merchant.qpay.mn";
|
|
143926
|
+
this.username = username2;
|
|
143927
|
+
this.password = password;
|
|
143928
|
+
this.invoiceCode = invoiceCode;
|
|
143929
|
+
this.saveToken = saveToken;
|
|
143930
|
+
}
|
|
143931
|
+
login() {
|
|
143932
|
+
return __async(this, null, function* () {
|
|
143933
|
+
const req = yield fetch(`${this.baseUrl}/v2/auth/token`, {
|
|
143934
|
+
method: "POST",
|
|
143935
|
+
headers: {
|
|
143936
|
+
"Content-Type": "application/json",
|
|
143937
|
+
Authorization: `Basic ${btoa(`${this.username}:${this.password}`)}`
|
|
143938
|
+
}
|
|
143939
|
+
});
|
|
143940
|
+
const res = yield req.json();
|
|
143941
|
+
if (res.error) {
|
|
143942
|
+
throw new Error(res.message);
|
|
143943
|
+
}
|
|
143944
|
+
const response = res;
|
|
143945
|
+
return {
|
|
143946
|
+
access_token: response.access_token,
|
|
143947
|
+
refresh_token: response.refresh_token,
|
|
143948
|
+
expires_in: response.expires_in,
|
|
143949
|
+
refresh_expires_in: response.refresh_expires_in
|
|
143950
|
+
};
|
|
143951
|
+
});
|
|
143952
|
+
}
|
|
143953
|
+
getRefreshToken(refreshToken2) {
|
|
143954
|
+
return __async(this, null, function* () {
|
|
143955
|
+
const req = yield fetch(`${this.baseUrl}/v2/auth/refresh`, {
|
|
143956
|
+
method: "POST",
|
|
143957
|
+
headers: {
|
|
143958
|
+
"Content-Type": "application/json",
|
|
143959
|
+
Authorization: `Bearer ${refreshToken2}`
|
|
143960
|
+
}
|
|
143961
|
+
});
|
|
143962
|
+
const res = yield req.json();
|
|
143963
|
+
if (res.error) {
|
|
143964
|
+
throw new Error(res.message);
|
|
143965
|
+
}
|
|
143966
|
+
const response = res;
|
|
143967
|
+
return {
|
|
143968
|
+
access_token: response.access_token,
|
|
143969
|
+
refresh_token: response.refresh_token,
|
|
143970
|
+
expires_in: response.expires_in,
|
|
143971
|
+
refresh_expires_in: response.refresh_expires_in
|
|
143972
|
+
};
|
|
143973
|
+
});
|
|
143974
|
+
}
|
|
143975
|
+
checkToken(inputToken) {
|
|
143976
|
+
return __async(this, null, function* () {
|
|
143977
|
+
let token = inputToken;
|
|
143978
|
+
if (!token || !token.refresh_expires_in) {
|
|
143979
|
+
token = yield this.login();
|
|
143980
|
+
}
|
|
143981
|
+
if (token.refresh_expires_in && new Date(token.refresh_expires_in * 1000) <= /* @__PURE__ */ new Date) {
|
|
143982
|
+
token = yield this.login();
|
|
143983
|
+
} else if (new Date(token.expires_in * 1000) <= /* @__PURE__ */ new Date) {
|
|
143984
|
+
token = yield this.getRefreshToken(token.refresh_token);
|
|
143985
|
+
}
|
|
143986
|
+
if (this.saveToken && JSON.stringify(inputToken) !== JSON.stringify(token)) {
|
|
143987
|
+
yield this.saveToken(token);
|
|
143988
|
+
}
|
|
143989
|
+
return token;
|
|
143990
|
+
});
|
|
143991
|
+
}
|
|
143992
|
+
createInvoice(input, token) {
|
|
143993
|
+
return __async(this, null, function* () {
|
|
143994
|
+
token = yield this.checkToken(token);
|
|
143995
|
+
const req = yield fetch(`${this.baseUrl}/v2/invoice`, {
|
|
143996
|
+
method: "POST",
|
|
143997
|
+
headers: {
|
|
143998
|
+
"Content-Type": "application/json",
|
|
143999
|
+
Authorization: `Bearer ${token.access_token}`
|
|
144000
|
+
},
|
|
144001
|
+
body: JSON.stringify(__spreadProps2(__spreadValues2({}, input), {
|
|
144002
|
+
invoice_code: this.invoiceCode
|
|
144003
|
+
}))
|
|
144004
|
+
});
|
|
144005
|
+
const res = yield req.json();
|
|
144006
|
+
return {
|
|
144007
|
+
data: res,
|
|
144008
|
+
token
|
|
144009
|
+
};
|
|
144010
|
+
});
|
|
144011
|
+
}
|
|
144012
|
+
checkInvoice(invoiceId, token) {
|
|
144013
|
+
return __async(this, null, function* () {
|
|
144014
|
+
token = yield this.checkToken(token);
|
|
144015
|
+
const req = yield fetch(`${this.baseUrl}/v2/payment/check`, {
|
|
144016
|
+
method: "POST",
|
|
144017
|
+
headers: {
|
|
144018
|
+
"Content-Type": "application/json",
|
|
144019
|
+
Authorization: `Bearer ${token.access_token}`
|
|
144020
|
+
},
|
|
144021
|
+
body: JSON.stringify({
|
|
144022
|
+
object_type: "INVOICE",
|
|
144023
|
+
object_id: invoiceId
|
|
144024
|
+
})
|
|
144025
|
+
});
|
|
144026
|
+
const res = yield req.json();
|
|
144027
|
+
return {
|
|
144028
|
+
data: res,
|
|
144029
|
+
token
|
|
144030
|
+
};
|
|
144031
|
+
});
|
|
144032
|
+
}
|
|
144033
|
+
};
|
|
143923
144034
|
var StorePay = class {
|
|
143924
|
-
constructor(username2
|
|
144035
|
+
constructor(username2, password, appUsername, appPassword, saveToken) {
|
|
143925
144036
|
this.baseUrl = "https://service.storepay.mn:8778";
|
|
143926
144037
|
this.username = username2;
|
|
143927
144038
|
this.password = password;
|
|
143928
144039
|
this.appUsername = appUsername;
|
|
143929
144040
|
this.appPassword = appPassword;
|
|
144041
|
+
this.saveToken = saveToken;
|
|
143930
144042
|
}
|
|
143931
144043
|
login() {
|
|
143932
144044
|
return __async(this, null, function* () {
|
|
@@ -143949,14 +144061,18 @@ var StorePay = class {
|
|
|
143949
144061
|
return res;
|
|
143950
144062
|
});
|
|
143951
144063
|
}
|
|
143952
|
-
checkToken(
|
|
144064
|
+
checkToken(inputToken) {
|
|
143953
144065
|
return __async(this, null, function* () {
|
|
144066
|
+
let token = inputToken;
|
|
143954
144067
|
if (!token) {
|
|
143955
144068
|
token = yield this.login();
|
|
143956
144069
|
}
|
|
143957
144070
|
if (new Date(token.expires_in * 1000) <= /* @__PURE__ */ new Date) {
|
|
143958
144071
|
token = yield this.login();
|
|
143959
144072
|
}
|
|
144073
|
+
if (this.saveToken && JSON.stringify(inputToken) !== JSON.stringify(token)) {
|
|
144074
|
+
yield this.saveToken(token);
|
|
144075
|
+
}
|
|
143960
144076
|
return token;
|
|
143961
144077
|
});
|
|
143962
144078
|
}
|
|
@@ -144000,11 +144116,12 @@ var StorePay = class {
|
|
|
144000
144116
|
}
|
|
144001
144117
|
};
|
|
144002
144118
|
var UbPay = class {
|
|
144003
|
-
constructor(clientId, clientSecret, baseUrl) {
|
|
144119
|
+
constructor(clientId, clientSecret, saveToken, baseUrl) {
|
|
144004
144120
|
this.baseUrl = "https://merchant-payment-api.dev.p.ubcabtech.com";
|
|
144005
144121
|
this.clientId = clientId;
|
|
144006
144122
|
this.clientSecret = clientSecret;
|
|
144007
144123
|
this.baseUrl = baseUrl || this.baseUrl;
|
|
144124
|
+
this.saveToken = saveToken;
|
|
144008
144125
|
}
|
|
144009
144126
|
login() {
|
|
144010
144127
|
return __async(this, null, function* () {
|
|
@@ -144042,16 +144159,20 @@ var UbPay = class {
|
|
|
144042
144159
|
});
|
|
144043
144160
|
});
|
|
144044
144161
|
}
|
|
144045
|
-
checkToken(
|
|
144162
|
+
checkToken(inputToken) {
|
|
144046
144163
|
return __async(this, null, function* () {
|
|
144164
|
+
let token = inputToken;
|
|
144047
144165
|
if (!token || !token.refresh_expires_in) {
|
|
144048
144166
|
token = yield this.login();
|
|
144049
144167
|
}
|
|
144050
144168
|
if (token.refresh_expires_in && new Date(token.refresh_expires_in * 1000) <= /* @__PURE__ */ new Date) {
|
|
144051
144169
|
token = yield this.login();
|
|
144052
|
-
} else {
|
|
144170
|
+
} else if (new Date(token.expires_in * 1000) <= /* @__PURE__ */ new Date) {
|
|
144053
144171
|
token = yield this.getRefreshToken(token);
|
|
144054
144172
|
}
|
|
144173
|
+
if (this.saveToken && JSON.stringify(inputToken) !== JSON.stringify(token)) {
|
|
144174
|
+
yield this.saveToken(token);
|
|
144175
|
+
}
|
|
144055
144176
|
return token;
|
|
144056
144177
|
});
|
|
144057
144178
|
}
|
|
@@ -144091,6 +144212,8 @@ var UbPay = class {
|
|
|
144091
144212
|
};
|
|
144092
144213
|
|
|
144093
144214
|
// src/routes/crm/cpOrder/payment/gateways/index.ts
|
|
144215
|
+
var CALLBACK_URL = "http://202.70.40.82:3000/api/crm/cp-order/payment";
|
|
144216
|
+
|
|
144094
144217
|
class PaymentGateway {
|
|
144095
144218
|
token = undefined;
|
|
144096
144219
|
paymentId = undefined;
|
|
@@ -144169,9 +144292,10 @@ class StorePayGateway extends PaymentGateway {
|
|
|
144169
144292
|
mobileNumber: input.phone,
|
|
144170
144293
|
description: "",
|
|
144171
144294
|
amount: input.amount,
|
|
144172
|
-
callbackUrl:
|
|
144295
|
+
callbackUrl: `${CALLBACK_URL}/storepay/${payment.id}`
|
|
144173
144296
|
}, this.token);
|
|
144174
144297
|
await this.updatePaymentInfo(invoice.token);
|
|
144298
|
+
await this.updateInvoiceNumber(payment.id, invoice.data.value.toString());
|
|
144175
144299
|
return payment;
|
|
144176
144300
|
}
|
|
144177
144301
|
async checkInvoice(id) {
|
|
@@ -144193,6 +144317,7 @@ class UbPayGateway extends PaymentGateway {
|
|
|
144193
144317
|
ubPay;
|
|
144194
144318
|
constructor(input) {
|
|
144195
144319
|
super();
|
|
144320
|
+
input[2] = this.updatePaymentInfo;
|
|
144196
144321
|
this.ubPay = new UbPay(...input);
|
|
144197
144322
|
}
|
|
144198
144323
|
async createInvoice(input) {
|
|
@@ -144204,7 +144329,7 @@ class UbPayGateway extends PaymentGateway {
|
|
|
144204
144329
|
amount: payment.amount,
|
|
144205
144330
|
description: "Autosync",
|
|
144206
144331
|
customData: undefined,
|
|
144207
|
-
callbackUrl:
|
|
144332
|
+
callbackUrl: `${CALLBACK_URL}/ubpay/${payment.id}`
|
|
144208
144333
|
}, this.token);
|
|
144209
144334
|
if (invoice.data.success === false) {
|
|
144210
144335
|
throw new Error("\u041D\u044D\u0445\u044D\u043C\u0436\u043B\u044D\u043B \u04AF\u04AF\u0441\u0433\u044D\u0445\u044D\u0434 \u0430\u043B\u0434\u0430\u0430 \u0433\u0430\u0440\u043B\u0430\u0430.");
|
|
@@ -144219,7 +144344,6 @@ class UbPayGateway extends PaymentGateway {
|
|
|
144219
144344
|
async checkInvoice(invoiceId) {
|
|
144220
144345
|
const payment = await this.getPaymentById(invoiceId);
|
|
144221
144346
|
const check2 = await this.ubPay.checkInvoice(payment.invoiceNumber ?? "", this.token);
|
|
144222
|
-
console.log(check2.data);
|
|
144223
144347
|
await this.updatePaymentInfo(check2.token);
|
|
144224
144348
|
if (check2.data.data.status === "open") {
|
|
144225
144349
|
throw new Error("\u0422\u04E9\u043B\u0431\u04E9\u0440 \u0442\u04E9\u043B\u04E9\u0433\u0434\u04E9\u04E9\u0433\u04AF\u0439 \u0431\u0430\u0439\u043D\u0430.");
|
|
@@ -144231,6 +144355,41 @@ class UbPayGateway extends PaymentGateway {
|
|
|
144231
144355
|
}
|
|
144232
144356
|
}
|
|
144233
144357
|
|
|
144358
|
+
// src/routes/crm/cpOrder/payment/gateways/qpay.ts
|
|
144359
|
+
class QpayGateway extends PaymentGateway {
|
|
144360
|
+
qpay;
|
|
144361
|
+
constructor(params) {
|
|
144362
|
+
super();
|
|
144363
|
+
params[3] = this.updatePaymentInfo;
|
|
144364
|
+
this.qpay = new Qpay(...params);
|
|
144365
|
+
}
|
|
144366
|
+
async createInvoice(input) {
|
|
144367
|
+
const payment = await this.savePayment(input);
|
|
144368
|
+
const invoice = await this.qpay.createInvoice({
|
|
144369
|
+
sender_invoice_no: payment.id,
|
|
144370
|
+
invoice_receiver_code: payment.cpOrderId,
|
|
144371
|
+
invoice_description: "test",
|
|
144372
|
+
amount: payment.amount,
|
|
144373
|
+
callback_url: `${CALLBACK_URL}/qpay/${payment.id}`
|
|
144374
|
+
}, this.token);
|
|
144375
|
+
await this.updatePaymentInfo(invoice.token);
|
|
144376
|
+
await this.updateInvoiceNumber(payment.id, invoice.data.invoice_id);
|
|
144377
|
+
return {
|
|
144378
|
+
...payment,
|
|
144379
|
+
qrCode: invoice.data.qr_text
|
|
144380
|
+
};
|
|
144381
|
+
}
|
|
144382
|
+
async checkInvoice(invoiceId) {
|
|
144383
|
+
const payment = await this.getPaymentById(invoiceId);
|
|
144384
|
+
const check2 = await this.qpay.checkInvoice(payment.invoiceNumber ?? "", this.token);
|
|
144385
|
+
await this.updatePaymentInfo(check2.token);
|
|
144386
|
+
if (check2.data.paid_amount !== payment.amount) {
|
|
144387
|
+
throw new Error("\u0422\u04E9\u043B\u0431\u04E9\u0440 \u0442\u04E9\u043B\u04E9\u0433\u0434\u04E9\u04E9\u0433\u04AF\u0439 \u0431\u0430\u0439\u043D\u0430.");
|
|
144388
|
+
}
|
|
144389
|
+
await this.setPaid(invoiceId);
|
|
144390
|
+
}
|
|
144391
|
+
}
|
|
144392
|
+
|
|
144234
144393
|
// src/routes/crm/cpOrder/payment/logic.ts
|
|
144235
144394
|
var CrmCpOrderPaymentLogic;
|
|
144236
144395
|
((CrmCpOrderPaymentLogic) => {
|
|
@@ -144247,6 +144406,68 @@ var CrmCpOrderPaymentLogic;
|
|
|
144247
144406
|
CrmCpOrderPaymentLogic.removePaymentInfo = async (id) => {
|
|
144248
144407
|
await db_default.delete(crmPaymentTable).where(eq(crmPaymentTable.id, id));
|
|
144249
144408
|
};
|
|
144409
|
+
CrmCpOrderPaymentLogic.createQpay = async (body, user2) => {
|
|
144410
|
+
let paymentInfo = await getPaymentInfo("Qpay", user2);
|
|
144411
|
+
if ("code" in paymentInfo) {
|
|
144412
|
+
return paymentInfo;
|
|
144413
|
+
}
|
|
144414
|
+
const auth3 = paymentInfo.sub;
|
|
144415
|
+
const gateway = new QpayGateway([
|
|
144416
|
+
auth3.username,
|
|
144417
|
+
auth3.password,
|
|
144418
|
+
auth3.invoiceCode,
|
|
144419
|
+
async (token) => {
|
|
144420
|
+
await db_default.update(crmPaymentTable).set({
|
|
144421
|
+
accessToken: token.access_token,
|
|
144422
|
+
refreshToken: token.refresh_token,
|
|
144423
|
+
expiresIn: token.expires_in,
|
|
144424
|
+
refreshExpiresIn: token.refresh_expires_in
|
|
144425
|
+
}).where(eq(crmPaymentTable.id, paymentInfo.id));
|
|
144426
|
+
paymentInfo.accessToken = token.access_token;
|
|
144427
|
+
paymentInfo.refreshToken = token.refresh_token;
|
|
144428
|
+
paymentInfo.expiresIn = token.expires_in;
|
|
144429
|
+
paymentInfo.refreshExpiresIn = token.refresh_expires_in ?? 0;
|
|
144430
|
+
}
|
|
144431
|
+
]);
|
|
144432
|
+
gateway.setToken(paymentInfo);
|
|
144433
|
+
try {
|
|
144434
|
+
const result = await gateway.createInvoice({
|
|
144435
|
+
...body,
|
|
144436
|
+
paymentMethod: "POS_TERMINAL",
|
|
144437
|
+
paymentChannel: "Qpay",
|
|
144438
|
+
state: "PENDING"
|
|
144439
|
+
});
|
|
144440
|
+
return result;
|
|
144441
|
+
} catch (err2) {
|
|
144442
|
+
if (err2 instanceof Error) {
|
|
144443
|
+
return status("Bad Request", err2.message);
|
|
144444
|
+
}
|
|
144445
|
+
return status("Internal Server Error", "\u0421\u0435\u0440\u0432\u0435\u0440 \u0430\u043B\u0434\u0430\u0430 \u0433\u0430\u0440\u043B\u0430\u0430");
|
|
144446
|
+
}
|
|
144447
|
+
};
|
|
144448
|
+
CrmCpOrderPaymentLogic.checkQpay = async (id) => {
|
|
144449
|
+
const paymentInfo = await getPaymentInfoByPaymentId(id, "Qpay");
|
|
144450
|
+
if ("code" in paymentInfo) {
|
|
144451
|
+
return paymentInfo;
|
|
144452
|
+
}
|
|
144453
|
+
const auth3 = paymentInfo.sub;
|
|
144454
|
+
const gateway = new QpayGateway([
|
|
144455
|
+
auth3.username,
|
|
144456
|
+
auth3.password,
|
|
144457
|
+
auth3.invoiceCode
|
|
144458
|
+
]);
|
|
144459
|
+
gateway.setToken(paymentInfo);
|
|
144460
|
+
try {
|
|
144461
|
+
await gateway.checkInvoice(id);
|
|
144462
|
+
app.server?.publish(`cp_order_payment:${id}`, "PAID");
|
|
144463
|
+
} catch (err2) {
|
|
144464
|
+
if (err2 instanceof Error) {
|
|
144465
|
+
app.server?.publish(`cp_order_payment:${id}`, err2.message);
|
|
144466
|
+
return status("Bad Request", err2.message);
|
|
144467
|
+
}
|
|
144468
|
+
return status("Internal Server Error", "\u0421\u0435\u0440\u0432\u0435\u0440 \u0430\u043B\u0434\u0430\u0430 \u0433\u0430\u0440\u043B\u0430\u0430");
|
|
144469
|
+
}
|
|
144470
|
+
};
|
|
144250
144471
|
CrmCpOrderPaymentLogic.createStorepay = async (body, user2) => {
|
|
144251
144472
|
const paymentInfo = await getPaymentInfo("StorePay", user2);
|
|
144252
144473
|
if ("code" in paymentInfo) {
|
|
@@ -144291,15 +144512,17 @@ var CrmCpOrderPaymentLogic;
|
|
|
144291
144512
|
gateway.setToken(paymentInfo);
|
|
144292
144513
|
try {
|
|
144293
144514
|
await gateway.checkInvoice(id);
|
|
144515
|
+
app.server?.publish(`cp_order_payment:${id}`, "PAID");
|
|
144294
144516
|
} catch (err2) {
|
|
144295
144517
|
if (err2 instanceof Error) {
|
|
144518
|
+
app.server?.publish(`cp_order_payment:${id}`, err2.message);
|
|
144296
144519
|
return status("Bad Request", err2.message);
|
|
144297
144520
|
}
|
|
144298
144521
|
return status("Internal Server Error", "\u0421\u0435\u0440\u0432\u0435\u0440 \u0430\u043B\u0434\u0430\u0430 \u0433\u0430\u0440\u043B\u0430\u0430");
|
|
144299
144522
|
}
|
|
144300
144523
|
};
|
|
144301
144524
|
CrmCpOrderPaymentLogic.createUbPay = async (body, user2) => {
|
|
144302
|
-
|
|
144525
|
+
let paymentInfo = await getPaymentInfo("UbPay", user2);
|
|
144303
144526
|
if ("code" in paymentInfo) {
|
|
144304
144527
|
return paymentInfo;
|
|
144305
144528
|
}
|
|
@@ -144331,8 +144554,10 @@ var CrmCpOrderPaymentLogic;
|
|
|
144331
144554
|
gateway.setToken(paymentInfo);
|
|
144332
144555
|
try {
|
|
144333
144556
|
await gateway.checkInvoice(id);
|
|
144557
|
+
app.server?.publish(`cp_order_payment:${id}`, "PAID");
|
|
144334
144558
|
} catch (err2) {
|
|
144335
144559
|
if (err2 instanceof Error) {
|
|
144560
|
+
app.server?.publish(`cp_order_payment:${id}`, err2.message);
|
|
144336
144561
|
return status("Bad Request", err2.message);
|
|
144337
144562
|
}
|
|
144338
144563
|
return status("Internal Server Error", "\u0421\u0435\u0440\u0432\u0435\u0440 \u0430\u043B\u0434\u0430\u0430 \u0433\u0430\u0440\u043B\u0430\u0430");
|
|
@@ -144394,6 +144619,14 @@ var CrmCpOrderPaymentModel;
|
|
|
144394
144619
|
clientId: t.String(),
|
|
144395
144620
|
clientSecret: t.String()
|
|
144396
144621
|
})
|
|
144622
|
+
}),
|
|
144623
|
+
t.Object({
|
|
144624
|
+
type: t.Literal("Qpay"),
|
|
144625
|
+
sub: t.Object({
|
|
144626
|
+
username: t.String(),
|
|
144627
|
+
password: t.String(),
|
|
144628
|
+
invoiceCode: t.String()
|
|
144629
|
+
})
|
|
144397
144630
|
})
|
|
144398
144631
|
])
|
|
144399
144632
|
]);
|
|
@@ -144421,13 +144654,12 @@ var paymentRoutes = new Elysia({
|
|
|
144421
144654
|
},
|
|
144422
144655
|
query: "CrmCpOrderPaymentModel.wsQuery",
|
|
144423
144656
|
body: "CrmCpOrderPaymentModel.wsBody"
|
|
144424
|
-
}).get("/storepay/:id", async ({ params: { id } }) => logic_default11.checkStorePay(id)).post("/ubpay
|
|
144425
|
-
|
|
144426
|
-
|
|
144427
|
-
|
|
144428
|
-
|
|
144429
|
-
|
|
144430
|
-
body: "CrmCpOrderPaymentModel.create"
|
|
144657
|
+
}).post("/storepay", async ({ body, user: user2 }) => logic_default11.createStorepay(body, user2), { body: "CrmCpOrderPaymentModel.storepay", auth: true }).get("/storepay/:id", async ({ params: { id } }) => logic_default11.checkStorePay(id)).post("/ubpay", async ({ body, user: user2 }) => logic_default11.createUbPay(body, user2), {
|
|
144658
|
+
body: "CrmCpOrderPaymentModel.create",
|
|
144659
|
+
auth: true
|
|
144660
|
+
}).post("/ubpay/:id", async ({ params: { id } }) => logic_default11.checkUbPay(id)).get("/qpay/:id", async ({ params: { id } }) => logic_default11.checkQpay(id)).post("/qpay", async ({ body, user: user2 }) => logic_default11.createQpay(body, user2), {
|
|
144661
|
+
body: "CrmCpOrderPaymentModel.create",
|
|
144662
|
+
auth: true
|
|
144431
144663
|
}).guard({
|
|
144432
144664
|
userKind: "ADMIN"
|
|
144433
144665
|
}).get("/", async () => logic_default11.selectPaymentInfo()).post("/", async ({ body }) => logic_default11.createPaymentInfo(body), {
|
|
@@ -145039,7 +145271,7 @@ var permissionRoutes = new Elysia({
|
|
|
145039
145271
|
return status2("Forbidden", "\u0417\u04E9\u0432\u0445\u04E9\u043D \u0430\u0434\u043C\u0438\u043D \u044D\u0440\u0445\u0442\u044D\u0439 \u0445\u044D\u0440\u044D\u0433\u043B\u044D\u0433\u0447\u0438\u0434 \u044D\u043D\u044D \u04AF\u0439\u043B\u0434\u043B\u0438\u0439\u0433 \u0445\u0438\u0439\u0445 \u0431\u043E\u043B\u043E\u043C\u0436\u0442\u043E\u0439.");
|
|
145040
145272
|
}
|
|
145041
145273
|
}
|
|
145042
|
-
}).group("/group", (
|
|
145274
|
+
}).group("/group", (app2) => app2.guard({
|
|
145043
145275
|
permission: "PERMISSION_GROUP_ALL"
|
|
145044
145276
|
}).get("/", async ({ query }) => await logic_default14.selectGroups(query), {
|
|
145045
145277
|
query: "PermissionModel.select"
|
|
@@ -145395,12 +145627,12 @@ var WarehouseItemLogic;
|
|
|
145395
145627
|
((WarehouseItemLogic) => {
|
|
145396
145628
|
WarehouseItemLogic.select = async (query, user2) => {
|
|
145397
145629
|
const filter = and(softDeletedFilter(warehouseItemTable), ...query.product ? [logic_default7.getFilter(query.product, user2)] : [], eq(warehouseItemTable.safetyStock, query.safetyStock ?? 0).if(query.safetyStock), ilike(warehouseItemTable.shelfNumber, sql3`%${query.shelfNumber}%`).if(query.shelfNumber));
|
|
145398
|
-
const columns = getTableColumns(warehouseItemTable);
|
|
145399
145630
|
const baseQuery = db_default.select({
|
|
145400
|
-
|
|
145631
|
+
item: warehouseItemTable,
|
|
145632
|
+
supplier: techdocSupplierTable,
|
|
145401
145633
|
product: warehouseProductTable,
|
|
145402
145634
|
totalCount: totalCountSql
|
|
145403
|
-
}).from(warehouseItemTable).where(filter).innerJoin(warehouseProductTable, and(eq(warehouseItemTable.productId, warehouseProductTable.id), isNull2(warehouseProductTable.deletedAt))).$dynamic();
|
|
145635
|
+
}).from(warehouseItemTable).where(filter).innerJoin(warehouseProductTable, and(eq(warehouseItemTable.productId, warehouseProductTable.id), isNull2(warehouseProductTable.deletedAt))).innerJoin(techdocSupplierTable, eq(warehouseProductTable.supplierId, techdocSupplierTable.id)).$dynamic();
|
|
145404
145636
|
const result = await pagination_helper_default(baseQuery, query.pagination);
|
|
145405
145637
|
const content = {
|
|
145406
145638
|
totalCount: result[0]?.totalCount ?? 0,
|
|
@@ -145671,3 +145903,6 @@ var app = new Elysia().use(index_default({
|
|
|
145671
145903
|
tags: swagger_tags_default
|
|
145672
145904
|
}
|
|
145673
145905
|
})).use(requestLogger).mount(auth2.handler).use(routes_default).listen(env_default.PORT);
|
|
145906
|
+
export {
|
|
145907
|
+
app
|
|
145908
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autosync_backend2",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.25",
|
|
4
4
|
"module": "src/index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"exceljs": "^4.4.0",
|
|
32
32
|
"fast-xml-parser": "^5.2.5",
|
|
33
33
|
"generate-password": "^1.7.1",
|
|
34
|
-
"mn-payment": "^0.0.
|
|
34
|
+
"mn-payment": "^0.0.20",
|
|
35
35
|
"nodemailer": "^7.0.3",
|
|
36
36
|
"pg": "^8.16.1",
|
|
37
37
|
"pino": "^9.7.0",
|