autosync_backend2 1.1.27 → 1.1.29

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
@@ -4092,6 +4092,49 @@ export declare const app: Elysia<"", {
4092
4092
  };
4093
4093
  };
4094
4094
  };
4095
+ } & {
4096
+ "cp-order": {
4097
+ ":id": {
4098
+ payment: {
4099
+ get: {
4100
+ body: unknown;
4101
+ params: {
4102
+ id: string;
4103
+ };
4104
+ query: unknown;
4105
+ headers: unknown;
4106
+ response: {
4107
+ 200: {
4108
+ payments: {
4109
+ cpOrderId: string;
4110
+ paymentPackageId: string | null;
4111
+ paymentMethod: "CASH" | "BANK_TRANSFER" | "POS_TERMINAL" | "PAYMENT_PACKAGE";
4112
+ paymentChannel: string;
4113
+ amount: number;
4114
+ state: "NOT_PAID" | "PENDING" | "FAILED" | "EXPIRED" | "PAID" | "DECLINED" | "CANCELED" | "REFUNDING" | "REFUNDED";
4115
+ invoiceNumber: string | null;
4116
+ id: string;
4117
+ createdAt: string;
4118
+ updatedAt: string;
4119
+ deletedAt: string | null;
4120
+ }[];
4121
+ totalAmount: number;
4122
+ paidAmount: number;
4123
+ };
4124
+ 422: {
4125
+ type: "validation";
4126
+ on: string;
4127
+ summary?: string;
4128
+ message?: string;
4129
+ found?: unknown;
4130
+ property?: string;
4131
+ expected?: string;
4132
+ };
4133
+ };
4134
+ };
4135
+ };
4136
+ };
4137
+ };
4095
4138
  };
4096
4139
  } & {
4097
4140
  crm: {
package/dist/index.js CHANGED
@@ -143968,6 +143968,10 @@ var CrmCpOrderPaymentLogic;
143968
143968
  CrmCpOrderPaymentLogic.removePaymentInfo = async (id) => {
143969
143969
  await db_default.delete(crmPaymentTable).where(eq(crmPaymentTable.id, id));
143970
143970
  };
143971
+ CrmCpOrderPaymentLogic.create = async (body) => {
143972
+ const [payment] = await db_default.insert(crmCpOrderPaymentTable).values(body).returning();
143973
+ return payment;
143974
+ };
143971
143975
  CrmCpOrderPaymentLogic.createQpay = async (body, user2) => {
143972
143976
  let paymentInfo = await getPaymentInfo("Qpay", user2);
143973
143977
  if ("code" in paymentInfo) {
@@ -144303,20 +144307,22 @@ var CrmCpOrderItemLogic;
144303
144307
  if (!product && !sk) {
144304
144308
  return status("Bad Request", "\u04AE\u0439\u043B\u0447\u0438\u043B\u0433\u044D\u044D\u043D\u0438\u0439 \u0442\u04E9\u0440\u04E9\u043B \u044D\u0441\u0432\u044D\u043B \u0431\u0430\u0440\u0430\u0430 \u0441\u043E\u043D\u0433\u043E\u043D\u043E \u0443\u0443.");
144305
144309
  }
144310
+ const curr = await db_default.select({
144311
+ id: crmCpOrderItemTable.id
144312
+ }).from(crmCpOrderItemTable).where(and(eq(crmCpOrderItemTable.cpOrderId, body.cpOrderId), eq(crmCpOrderItemTable.companyServiceKindId, body.companyServiceKindId ?? "").if(body.companyServiceKindId), eq(crmCpOrderItemTable.companyProductId, body.companyProductId ?? "").if(body.companyProductId)));
144313
+ if (curr.length > 0) {
144314
+ const [updated] = await db_default.update(crmCpOrderItemTable).set({
144315
+ ...body,
144316
+ priceUnit: sk?.price ?? product?.product.priceSell ?? 0,
144317
+ priceTotal: body.quantity * (sk?.price ?? product?.product.priceSell ?? 0)
144318
+ }).where(eq(crmCpOrderItemTable.id, curr[0].id)).returning();
144319
+ return updated;
144320
+ }
144306
144321
  const [result] = await db_default.insert(crmCpOrderItemTable).values({
144307
144322
  ...body,
144308
144323
  priceUnit: sk?.price ?? product?.product.priceSell ?? 0,
144309
144324
  priceTotal: body.quantity * (sk?.price ?? product?.product.priceSell ?? 0)
144310
- }).returning().onConflictDoUpdate({
144311
- set: {
144312
- quantity: sql3`excluded.quantity + ${crmCpOrderItemTable.quantity}`,
144313
- priceTotal: sql3`(excluded.quantity + ${crmCpOrderItemTable.quantity}) * excluded.price_unit`
144314
- },
144315
- target: [
144316
- crmCpOrderItemTable.cpOrderId,
144317
- crmCpOrderItemTable.companyServiceKindId
144318
- ]
144319
- });
144325
+ }).returning();
144320
144326
  return result;
144321
144327
  };
144322
144328
  CrmCpOrderItemLogic.createMany = async (body, user2, tdb = db_default) => {
@@ -144327,20 +144333,20 @@ var CrmCpOrderItemLogic;
144327
144333
  ids: body.map((item) => item.companyServiceKindId).filter((i2) => !!i2),
144328
144334
  pagination: {
144329
144335
  page: 1,
144330
- size: body.length
144336
+ size: body.filter((i2) => !!i2.companyServiceKindId).length
144331
144337
  }
144332
144338
  }, user2);
144333
- if (serviceKinds.results.length !== body.length) {
144339
+ if (serviceKinds.results.length !== body.map((i2) => i2.companyServiceKindId).filter(Boolean).length) {
144334
144340
  return status("Not Found", "\u04AE\u0439\u043B\u0447\u0438\u043B\u0433\u044D\u044D\u043D\u0438\u0439 \u0442\u04E9\u0440\u04E9\u043B \u0437\u0430\u0440\u0438\u043C \u043D\u044C \u043E\u043B\u0434\u0441\u043E\u043D\u0433\u04AF\u0439.");
144335
144341
  }
144336
144342
  const products = await logic_default8.select({
144337
144343
  ids: body.map((item) => item.companyProductId).filter((i2) => !!i2),
144338
144344
  pagination: {
144339
144345
  page: 1,
144340
- size: body.length
144346
+ size: body.filter((i2) => !!i2.companyProductId).length
144341
144347
  }
144342
144348
  }, user2);
144343
- if (products.result.length !== body.length) {
144349
+ if (products.result.length !== body.map((i2) => i2.companyProductId).filter(Boolean).length) {
144344
144350
  return status("Not Found", "\u0411\u0430\u0440\u0430\u0430\u043D\u044B \u0442\u04E9\u0440\u04E9\u043B \u0437\u0430\u0440\u0438\u043C \u043D\u044C \u043E\u043B\u0434\u0441\u043E\u043D\u0433\u04AF\u0439.");
144345
144351
  }
144346
144352
  const insertValues = [];
@@ -144352,10 +144358,16 @@ var CrmCpOrderItemLogic;
144352
144358
  }
144353
144359
  insertValues.push({
144354
144360
  ...item,
144361
+ companyServiceKindId: item.companyServiceKindId ?? null,
144362
+ companyProductId: item.companyProductId ?? null,
144355
144363
  priceUnit: item.priceUnit ?? serviceKind?.price ?? product?.product.priceSell ?? 0,
144356
144364
  priceTotal: item.quantity * (item.priceUnit ?? serviceKind?.price ?? product?.product.priceSell ?? 0)
144357
144365
  });
144358
144366
  }
144367
+ const currentValues = await db_default.select().from(crmCpOrderItemTable).where(and(eq(crmCpOrderItemTable.cpOrderId, insertValues[0].cpOrderId), or(inArray(crmCpOrderItemTable.companyProductId, insertValues.map((i2) => i2.companyProductId).filter((i2) => !!i2)), inArray(crmCpOrderItemTable.companyServiceKindId, insertValues.map((i2) => i2.companyServiceKindId).filter((i2) => !!i2)))));
144368
+ if (currentValues.length > 0) {
144369
+ return status("Bad Request", "\u0417\u0430\u0445\u0438\u0430\u043B\u0433\u044B\u043D \u04AF\u0439\u043B\u0447\u0438\u043B\u0433\u044D\u044D \u044D\u0441\u0432\u044D\u043B \u0431\u0430\u0440\u0430\u0430 \u0430\u043B\u044C \u0445\u044D\u0434\u0438\u0439\u043D \u043E\u0440\u0441\u043E\u043D \u0431\u0430\u0439\u043D\u0430.");
144370
+ }
144359
144371
  await tdb.insert(crmCpOrderItemTable).values(insertValues);
144360
144372
  };
144361
144373
  CrmCpOrderItemLogic.update = async (id, body) => {
@@ -144381,6 +144393,12 @@ var CrmCpOrderItemLogic;
144381
144393
  CrmCpOrderItemLogic.remove = async (id) => {
144382
144394
  await db_default.delete(crmCpOrderItemTable).where(eq(crmCpOrderItemTable.id, id));
144383
144395
  };
144396
+ CrmCpOrderItemLogic.selectAmountTotal = async (cpOrderId) => {
144397
+ const [amount] = await db_default.select({
144398
+ amount: sum(crmCpOrderItemTable.priceTotal).mapWith((value) => value === null ? 0 : Number(value))
144399
+ }).from(crmCpOrderItemTable).where(eq(crmCpOrderItemTable.cpOrderId, cpOrderId));
144400
+ return amount.amount;
144401
+ };
144384
144402
  })(CrmCpOrderItemLogic ||= {});
144385
144403
  var logic_default9 = CrmCpOrderItemLogic;
144386
144404
 
@@ -144398,9 +144416,9 @@ var CrmCpOrderLogic;
144398
144416
  make,
144399
144417
  model,
144400
144418
  customer: crmCustomerTable,
144401
- isDeleteAble: sql3`(
144419
+ isDeleteAble: sql3`
144402
144420
  (select count(*) from ${crmCpOrderItemTable} where ${crmCpOrderItemTable.cpOrderId} = ${crmCpOrderTable.id} and ${crmCpOrderItemTable.deletedAt} is null)
144403
- ) = 0`.mapWith(Boolean).as("is_delete_able")
144421
+ = 0`.mapWith(Boolean).as("is_delete_able")
144404
144422
  }).from(crmCpOrderTable).innerJoin(crmVehicleTable, eq(crmVehicleTable.id, crmCpOrderTable.vehicleId)).leftJoin(crmCustomerTable, eq(crmCustomerTable.id, crmCpOrderTable.customerId)).leftJoin(model, eq(model.id, crmVehicleTable.vehicleKindId)).leftJoin(make, eq(make.id, model.parentId)).where(filter).orderBy(desc(crmCpOrderTable.createdAt)).$dynamic();
144405
144423
  const result = await pagination_helper_default(baseQuery, query.pagination);
144406
144424
  const content = {
@@ -144494,7 +144512,7 @@ var CrmCpOrderLogic;
144494
144512
  name: i2.name ?? undefined
144495
144513
  })), user2, db2);
144496
144514
  if (res && "code" in res) {
144497
- throw res;
144515
+ throw new Error(res.response);
144498
144516
  }
144499
144517
  }
144500
144518
  if (spPackage.products.length > 0) {
@@ -144507,7 +144525,7 @@ var CrmCpOrderLogic;
144507
144525
  name: i2.name
144508
144526
  })), user2, db2);
144509
144527
  if (res && "code" in res) {
144510
- throw res;
144528
+ throw new Error(res.response);
144511
144529
  }
144512
144530
  }
144513
144531
  });
@@ -144534,13 +144552,11 @@ var CrmCpOrderLogic;
144534
144552
  }).where(eq(crmCpOrderTable.id, id));
144535
144553
  };
144536
144554
  CrmCpOrderLogic.selectPayments = async (id) => {
144537
- const [totalAmount] = await db_default.select({
144538
- amount: sum(crmCpOrderItemTable.priceTotal)
144539
- }).from(crmCpOrderItemTable).where(eq(crmCpOrderItemTable.cpOrderId, id));
144555
+ const totalAmount = await logic_default9.selectAmountTotal(id);
144540
144556
  const payments = await logic_default7.selectByCpOrderId(id);
144541
144557
  return {
144542
144558
  payments,
144543
- totalAmount: totalAmount.amount ? +totalAmount.amount : 0,
144559
+ totalAmount,
144544
144560
  paidAmount: payments.map((p) => p.state === "PAID" ? p.amount : 0).reduce((a12, b) => a12 + b, 0)
144545
144561
  };
144546
144562
  };
@@ -144739,7 +144755,9 @@ var cpOrderRoutes = new Elysia({
144739
144755
  body: "CrmCpOrderModel.addPackage"
144740
144756
  }).guard({
144741
144757
  params: IdSchema
144742
- }).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));
144758
+ }).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)).get("/:id/payment", async ({ params: { id } }) => logic_default10.selectPayments(id), {
144759
+ tags: ["CrmCpOrderPayment", "CrmCpOrder"]
144760
+ });
144743
144761
  var cpOrder_default = cpOrderRoutes;
144744
144762
 
144745
144763
  // src/routes/crm/customer/model.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autosync_backend2",
3
- "version": "1.1.27",
3
+ "version": "1.1.29",
4
4
  "module": "src/index.ts",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",