autosync_backend2 1.1.21 → 1.1.23

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 CHANGED
@@ -389,6 +389,12 @@ declare const app: Elysia<"", {
389
389
  clientSecret: import("@sinclair/typebox").TString;
390
390
  }>;
391
391
  }>]>]>;
392
+ readonly "CrmCpOrderPaymentModel.wsQuery": import("@sinclair/typebox").TObject<{
393
+ paymentId: import("@sinclair/typebox").TString;
394
+ }>;
395
+ readonly "CrmCpOrderPaymentModel.wsBody": import("@sinclair/typebox").TObject<{
396
+ state: import("elysia/dist/type-system/types").TUnionEnum<["PENDING", "PAID", "CANCELED"]>;
397
+ }>;
392
398
  readonly "CrmCpOrderModel.create": import("@sinclair/typebox").TObject<{
393
399
  phone: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
394
400
  vin: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
@@ -3499,6 +3505,22 @@ declare const app: Elysia<"", {
3499
3505
  } & {
3500
3506
  "cp-order": {
3501
3507
  payment: {};
3508
+ } & {
3509
+ payment: {
3510
+ ws: {
3511
+ subscribe: {
3512
+ body: {
3513
+ state: "PENDING" | "PAID" | "CANCELED";
3514
+ };
3515
+ params: {};
3516
+ query: {
3517
+ paymentId: string;
3518
+ };
3519
+ headers: unknown;
3520
+ response: unknown;
3521
+ };
3522
+ };
3523
+ };
3502
3524
  } & {
3503
3525
  payment: {
3504
3526
  storepay: {
@@ -3533,7 +3555,7 @@ declare const app: Elysia<"", {
3533
3555
  payment: {
3534
3556
  ubpay: {
3535
3557
  ":id": {
3536
- get: {
3558
+ post: {
3537
3559
  body: unknown;
3538
3560
  params: {
3539
3561
  id: string;
@@ -3541,10 +3563,7 @@ declare const app: Elysia<"", {
3541
3563
  query: unknown;
3542
3564
  headers: unknown;
3543
3565
  response: {
3544
- 200: undefined;
3545
- 404: "Төлбөрийн тохиргоо олдсонгүй." | "Төлбөрийн мэдээлэл олдсонгүй.";
3546
- 400: string;
3547
- 500: "Сервер алдаа гарлаа";
3566
+ 200: void;
3548
3567
  422: {
3549
3568
  type: "validation";
3550
3569
  on: string;
@@ -4050,18 +4069,6 @@ declare const app: Elysia<"", {
4050
4069
  };
4051
4070
  };
4052
4071
  };
4053
- } & {
4054
- "cp-order": {
4055
- ws: {
4056
- subscribe: {
4057
- body: unknown;
4058
- params: {};
4059
- query: unknown;
4060
- headers: unknown;
4061
- response: unknown;
4062
- };
4063
- };
4064
- };
4065
4072
  } & {
4066
4073
  "cp-order": {
4067
4074
  ":id": {
package/dist/index.js CHANGED
@@ -144022,8 +144022,8 @@ var UbPay = class {
144022
144022
  return {
144023
144023
  access_token: res.data.accessToken,
144024
144024
  refresh_token: res.data.refreshToken,
144025
- refresh_expires_in: parseInt(res.data.refreshTokenExpriresIn, 10),
144026
- expires_in: parseInt(res.data.accessTokenExpriresIn, 10)
144025
+ refresh_expires_in: res.data.refreshTokenExpiresIn,
144026
+ expires_in: res.data.accessTokenExpiresIn
144027
144027
  };
144028
144028
  });
144029
144029
  }
@@ -144076,7 +144076,7 @@ var UbPay = class {
144076
144076
  checkInvoice(invoiceId, token) {
144077
144077
  return __async(this, null, function* () {
144078
144078
  token = yield this.checkToken(token);
144079
- const req = yield fetch(`${this.baseUrl}/api/invoices/${invoiceId}`, {
144079
+ const req = yield fetch(`${this.baseUrl}/api/v1/invoices/${invoiceId}`, {
144080
144080
  headers: {
144081
144081
  Authorization: `Bearer ${token.access_token}`
144082
144082
  }
@@ -144144,6 +144144,11 @@ class PaymentGateway {
144144
144144
  invoiceNumber
144145
144145
  }).where(eq(crmCpOrderPaymentTable.id, id));
144146
144146
  }
144147
+ async updateState(id, state) {
144148
+ await db_default.update(crmCpOrderPaymentTable).set({
144149
+ state
144150
+ }).where(eq(crmCpOrderPaymentTable.id, id));
144151
+ }
144147
144152
  }
144148
144153
 
144149
144154
  // src/routes/crm/cpOrder/payment/gateways/storepay.ts
@@ -144197,10 +144202,13 @@ class UbPayGateway extends PaymentGateway {
144197
144202
  });
144198
144203
  const invoice = await this.ubPay.createInvoice({
144199
144204
  amount: payment.amount,
144200
- description: "",
144205
+ description: "Autosync",
144201
144206
  customData: undefined,
144202
- callbackUrl: "http://202.70.40.82:3000/crm/cp-order/payment/ubpay/" + payment.id
144207
+ callbackUrl: "http://202.70.40.82:3000/api/crm/cp-order/payment/ubpay/" + payment.id
144203
144208
  }, this.token);
144209
+ if (invoice.data.success === false) {
144210
+ 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.");
144211
+ }
144204
144212
  await this.updatePaymentInfo(invoice.token);
144205
144213
  await this.updateInvoiceNumber(payment.id, invoice.data.data.invoiceNumber);
144206
144214
  return {
@@ -144211,10 +144219,14 @@ class UbPayGateway extends PaymentGateway {
144211
144219
  async checkInvoice(invoiceId) {
144212
144220
  const payment = await this.getPaymentById(invoiceId);
144213
144221
  const check2 = await this.ubPay.checkInvoice(payment.invoiceNumber ?? "", this.token);
144222
+ console.log(check2.data);
144214
144223
  await this.updatePaymentInfo(check2.token);
144215
- if (check2.data.data.amount !== payment.amount) {
144224
+ if (check2.data.data.status === "open") {
144216
144225
  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.");
144217
144226
  }
144227
+ if (check2.data.data.status === "void") {
144228
+ this.updateState(invoiceId, "CANCELED");
144229
+ }
144218
144230
  await this.setPaid(invoiceId);
144219
144231
  }
144220
144232
  }
@@ -144385,6 +144397,14 @@ var CrmCpOrderPaymentModel;
144385
144397
  })
144386
144398
  ])
144387
144399
  ]);
144400
+ CrmCpOrderPaymentModel.wsQuery = t.Object({
144401
+ paymentId: t.String({
144402
+ format: "uuid"
144403
+ })
144404
+ });
144405
+ CrmCpOrderPaymentModel.wsBody = t.Object({
144406
+ state: t.UnionEnum(["PENDING", "PAID", "CANCELED"])
144407
+ });
144388
144408
  })(CrmCpOrderPaymentModel ||= {});
144389
144409
  var model_default6 = CrmCpOrderPaymentModel;
144390
144410
 
@@ -144392,7 +144412,21 @@ var model_default6 = CrmCpOrderPaymentModel;
144392
144412
  var paymentRoutes = new Elysia({
144393
144413
  prefix: "/payment",
144394
144414
  tags: ["CrmCpOrderPayment"]
144395
- }).use(better_auth_default).model(prefix_model_default("CrmCpOrderPaymentModel", model_default6)).get("/storepay/:id", async ({ params: { id } }) => logic_default11.checkStorePay(id)).get("/ubpay/:id", async ({ params: { id } }) => logic_default11.checkUbPay(id)).guard({ auth: true }).post("/storepay", async ({ body, user: user2 }) => logic_default11.createStorepay(body, user2), { body: "CrmCpOrderPaymentModel.storepay" }).post("/ubpay", async ({ body, user: user2 }) => logic_default11.createUbPay(body, user2), {
144415
+ }).use(better_auth_default).model(prefix_model_default("CrmCpOrderPaymentModel", model_default6)).ws("/ws", {
144416
+ open: (ws) => {
144417
+ ws.subscribe(`cp_order_payment:${ws.data.query.paymentId}`);
144418
+ },
144419
+ close: (ws) => {
144420
+ ws.unsubscribe(`cp_order_payment:${ws.data.query.paymentId}`);
144421
+ },
144422
+ query: "CrmCpOrderPaymentModel.wsQuery",
144423
+ body: "CrmCpOrderPaymentModel.wsBody"
144424
+ }).get("/storepay/:id", async ({ params: { id } }) => logic_default11.checkStorePay(id)).post("/ubpay/:id", async ({ params: { id } }) => {
144425
+ logic_default11.checkUbPay(id);
144426
+ paymentRoutes.server?.publish(`cp_order_payment:${id}`, JSON.stringify({
144427
+ state: "PAID"
144428
+ }));
144429
+ }).guard({ auth: true }).post("/storepay", async ({ body, user: user2 }) => logic_default11.createStorepay(body, user2), { body: "CrmCpOrderPaymentModel.storepay" }).post("/ubpay", async ({ body, user: user2 }) => logic_default11.createUbPay(body, user2), {
144396
144430
  body: "CrmCpOrderPaymentModel.create"
144397
144431
  }).guard({
144398
144432
  userKind: "ADMIN"
@@ -144500,8 +144534,7 @@ var cpOrderRoutes = new Elysia({
144500
144534
  prefix: "/cp-order",
144501
144535
  tags: ["CrmCpOrder"]
144502
144536
  }).use(better_auth_default).use(service_default).use(product_default).use(payment_default).guard({ auth: true }).model(prefix_model_default("CrmCpOrderModel", model_default5)).get("/", async ({ query, user: user2 }) => logic_default10.select(query, user2), {
144503
- query: "CrmCpOrderModel.select",
144504
- transform: ({ query }) => {}
144537
+ query: "CrmCpOrderModel.select"
144505
144538
  }).post("/", async ({ body, user: user2 }) => {
144506
144539
  const created = await logic_default10.create(body, user2);
144507
144540
  if ("code" in created) {
@@ -144514,23 +144547,11 @@ var cpOrderRoutes = new Elysia({
144514
144547
  size: 1
144515
144548
  }
144516
144549
  }, user2);
144517
- const message2 = {
144518
- type: "Create",
144519
- body: result.result[0]
144520
- };
144521
- cpOrderRoutes.server?.publish(`cp_order:${user2.branchId}`, JSON.stringify(message2));
144522
144550
  return result;
144523
144551
  }, {
144524
144552
  body: "CrmCpOrderModel.create"
144525
144553
  }).post("/package", async ({ body, user: user2 }) => logic_default10.addPackage(body, user2), {
144526
144554
  body: "CrmCpOrderModel.addPackage"
144527
- }).ws("/ws", {
144528
- open(ws) {
144529
- ws.subscribe(`cp_order:${ws.data.user.branchId}`);
144530
- },
144531
- close(ws) {
144532
- ws.unsubscribe(`cp_order:${ws.data.user.branchId}`);
144533
- }
144534
144555
  }).guard({
144535
144556
  params: IdSchema
144536
144557
  }).post("/:id/complete", async ({ user: user2, params: { id } }) => logic_default10.complete(id, user2)).delete("/:id", async ({ user: user2, params: { id } }) => logic_default10.remove(id, user2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autosync_backend2",
3
- "version": "1.1.21",
3
+ "version": "1.1.23",
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.12",
34
+ "mn-payment": "^0.0.15",
35
35
  "nodemailer": "^7.0.3",
36
36
  "pg": "^8.16.1",
37
37
  "pino": "^9.7.0",