autosync_backend2 1.2.20 → 1.2.22

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +176 -112
  2. package/dist/index.js +116 -51
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -3852,99 +3852,6 @@ export declare const app: Elysia<"", {
3852
3852
  };
3853
3853
  headers: unknown;
3854
3854
  response: {
3855
- 200: {
3856
- totalCount: number;
3857
- totalPage: number;
3858
- result: {
3859
- totalAmount: number;
3860
- paidAmount: number;
3861
- order: {
3862
- companyId: string;
3863
- companyBranchId: string;
3864
- customerId: string | null;
3865
- vehicleId: string | null;
3866
- orderId: string;
3867
- state: "CREATED" | "PROGRESSING" | "COMPLETE";
3868
- isNoat: boolean | null;
3869
- timeCompleted: string | null;
3870
- km: number;
3871
- type: "Service" | "ProductSell";
3872
- id: string;
3873
- createdAt: string;
3874
- updatedAt: string;
3875
- deletedAt: string | null;
3876
- oldId: number | null;
3877
- };
3878
- vehicle: {
3879
- customerId: string | null;
3880
- vehicleKindId: string;
3881
- vin: string | null;
3882
- licensePlate: string | null;
3883
- color: string | null;
3884
- engineCc: string | null;
3885
- cylinder: string | null;
3886
- gasType: string | null;
3887
- transmissionType: string | null;
3888
- vehicleType: string | null;
3889
- yearManufacture: number | null;
3890
- yearImport: number | null;
3891
- steering: string | null;
3892
- engineCode: string | null;
3893
- transmissionCode: string | null;
3894
- driveTrain: string | null;
3895
- km: number;
3896
- customData: unknown;
3897
- companyId: string | null;
3898
- id: string;
3899
- createdAt: string;
3900
- updatedAt: string;
3901
- deletedAt: string | null;
3902
- oldId: number | null;
3903
- } | null;
3904
- make: {
3905
- vehicleKindEnum: "MAKE" | "MODEL_GROUP" | "MODEL";
3906
- parentId: string | null;
3907
- name: string;
3908
- description: string | null;
3909
- yearStart: number | null;
3910
- yearEnd: number | null;
3911
- imagePath: string | null;
3912
- id: string;
3913
- createdAt: string;
3914
- updatedAt: string;
3915
- deletedAt: string | null;
3916
- oldId: number | null;
3917
- } | null;
3918
- model: {
3919
- vehicleKindEnum: "MAKE" | "MODEL_GROUP" | "MODEL";
3920
- parentId: string | null;
3921
- name: string;
3922
- description: string | null;
3923
- yearStart: number | null;
3924
- yearEnd: number | null;
3925
- imagePath: string | null;
3926
- id: string;
3927
- createdAt: string;
3928
- updatedAt: string;
3929
- deletedAt: string | null;
3930
- oldId: number | null;
3931
- } | null;
3932
- customer: {
3933
- companyId: string | null;
3934
- firstname: string | null;
3935
- lastname: string | null;
3936
- phoneNumber: string;
3937
- email: string | null;
3938
- regNum: string | null;
3939
- id: string;
3940
- createdAt: string;
3941
- updatedAt: string;
3942
- deletedAt: string | null;
3943
- oldId: number | null;
3944
- } | null;
3945
- isDeleteAble: unknown;
3946
- }[];
3947
- };
3948
3855
  401: "Session not found";
3949
3856
  422: {
3950
3857
  type: "validation";
@@ -3975,8 +3882,6 @@ export declare const app: Elysia<"", {
3975
3882
  totalCount: number;
3976
3883
  totalPage: number;
3977
3884
  result: {
3978
- totalAmount: number;
3979
- paidAmount: number;
3980
3885
  order: {
3981
3886
  companyId: string;
3982
3887
  companyBranchId: string;
@@ -4062,6 +3967,8 @@ export declare const app: Elysia<"", {
4062
3967
  oldId: number | null;
4063
3968
  } | null;
4064
3969
  isDeleteAble: unknown;
3970
+ totalAmount: number;
3971
+ paidAmount: number;
4065
3972
  }[];
4066
3973
  };
4067
3974
  400: "Машины дугаар болон VIN хоёроос нэгийг нь оруулна уу." | "Машины VIN оруулсан бол машины төрөл оруулна уу.";
@@ -4194,6 +4101,20 @@ export declare const app: Elysia<"", {
4194
4101
  };
4195
4102
  };
4196
4103
  };
4104
+ } & {
4105
+ "cp-order": {
4106
+ delete: {
4107
+ post: {
4108
+ body: unknown;
4109
+ params: {};
4110
+ query: unknown;
4111
+ headers: unknown;
4112
+ response: {
4113
+ 401: "Session not found";
4114
+ };
4115
+ };
4116
+ };
4117
+ };
4197
4118
  } & {
4198
4119
  "cp-order": {
4199
4120
  ":id": {
@@ -7125,25 +7046,34 @@ export declare const app: Elysia<"", {
7125
7046
  params: {};
7126
7047
  query: {
7127
7048
  type: "Service" | "Product";
7049
+ pagination: {
7050
+ size: number;
7051
+ page: number;
7052
+ };
7128
7053
  };
7129
7054
  headers: unknown;
7130
7055
  response: {
7131
7056
  200: {
7132
- createdAt: string | null;
7133
- orderId: string | null;
7134
- phone: string | null;
7135
- licensePlate: string | null;
7136
- name: string | null;
7137
- partNumber: string | null;
7138
- employeeName: unknown;
7139
- quantity: number;
7140
- priceBuy: number | null;
7141
- price: number;
7142
- discount: unknown;
7143
- priceAfterDiscount: number | null;
7144
- totalPrice: unknown;
7145
- totalPriceNoat: unknown;
7146
- }[];
7057
+ totalCount: number;
7058
+ totalPage: number;
7059
+ result: Omit<{
7060
+ createdAt: string | null;
7061
+ orderId: string | null;
7062
+ phone: string | null;
7063
+ licensePlate: string | null;
7064
+ name: string | null;
7065
+ partNumber: string | null;
7066
+ employeeName: unknown;
7067
+ quantity: number;
7068
+ priceBuy: number | null;
7069
+ price: number;
7070
+ discount: unknown;
7071
+ priceAfterDiscount: number | null;
7072
+ totalPrice: unknown;
7073
+ totalPriceNoat: unknown;
7074
+ totalCount: number;
7075
+ }, "totalCount">[];
7076
+ };
7147
7077
  401: "Session not found";
7148
7078
  422: {
7149
7079
  type: "validation";
@@ -7878,7 +7808,7 @@ export declare const app: Elysia<"", {
7878
7808
  templateId: string;
7879
7809
  fieldGroupId: string | null;
7880
7810
  fieldGroup: string | null;
7881
- fieldId: string;
7811
+ fieldId: string | null;
7882
7812
  code: string | null;
7883
7813
  description: string | null;
7884
7814
  fieldType: "BOOLEAN" | "NUMERIC" | "TEXT" | "DATE" | "RATE" | "MULTI_CHOICE";
@@ -7919,7 +7849,7 @@ export declare const app: Elysia<"", {
7919
7849
  fieldGroup?: string | null | undefined;
7920
7850
  sortIndex?: number | null | undefined;
7921
7851
  fieldGroupId?: string | null | undefined;
7922
- fieldId: string;
7852
+ fieldId?: string | null | undefined;
7923
7853
  fieldType: "BOOLEAN" | "NUMERIC" | "TEXT" | "DATE" | "RATE" | "MULTI_CHOICE";
7924
7854
  };
7925
7855
  params: {
@@ -7969,6 +7899,140 @@ export declare const app: Elysia<"", {
7969
7899
  };
7970
7900
  };
7971
7901
  };
7902
+ } & {
7903
+ inspection: {
7904
+ schedule: {};
7905
+ } & {
7906
+ schedule: {
7907
+ get: {
7908
+ body: unknown;
7909
+ params: {};
7910
+ query: {
7911
+ pagination: {
7912
+ size: number;
7913
+ page: number;
7914
+ };
7915
+ };
7916
+ headers: unknown;
7917
+ response: {
7918
+ 200: {
7919
+ totalCount: number;
7920
+ totalPage: number;
7921
+ result: Omit<{
7922
+ totalCount: number;
7923
+ companyId: string;
7924
+ machineId: string;
7925
+ templateId: string;
7926
+ daysInterval: number | null;
7927
+ timeNextDue: Date | null;
7928
+ isActive: boolean;
7929
+ id: string;
7930
+ createdAt: string;
7931
+ updatedAt: string;
7932
+ deletedAt: string | null;
7933
+ oldId: number | null;
7934
+ }, "totalCount">[];
7935
+ };
7936
+ 401: "Session not found";
7937
+ 422: {
7938
+ type: "validation";
7939
+ on: string;
7940
+ summary?: string;
7941
+ message?: string;
7942
+ found?: unknown;
7943
+ property?: string;
7944
+ expected?: string;
7945
+ };
7946
+ };
7947
+ };
7948
+ };
7949
+ } & {
7950
+ schedule: {
7951
+ post: {
7952
+ body: {
7953
+ oldId?: number | null | undefined;
7954
+ isActive?: boolean | undefined;
7955
+ daysInterval?: number | null | undefined;
7956
+ timeNextDue?: Date | null | undefined;
7957
+ templateId: string;
7958
+ machineId: string;
7959
+ };
7960
+ params: {};
7961
+ query: unknown;
7962
+ headers: unknown;
7963
+ response: {
7964
+ 401: "Session not found";
7965
+ 422: {
7966
+ type: "validation";
7967
+ on: string;
7968
+ summary?: string;
7969
+ message?: string;
7970
+ found?: unknown;
7971
+ property?: string;
7972
+ expected?: string;
7973
+ };
7974
+ };
7975
+ };
7976
+ };
7977
+ } & {
7978
+ schedule: {
7979
+ ":id": {
7980
+ put: {
7981
+ body: {
7982
+ companyId?: string | undefined;
7983
+ oldId?: number | null | undefined;
7984
+ isActive?: boolean | undefined;
7985
+ templateId?: string | undefined;
7986
+ machineId?: string | undefined;
7987
+ daysInterval?: number | null | undefined;
7988
+ timeNextDue?: Date | null | undefined;
7989
+ };
7990
+ params: {
7991
+ id: string;
7992
+ };
7993
+ query: unknown;
7994
+ headers: unknown;
7995
+ response: {
7996
+ 401: "Session not found";
7997
+ 422: {
7998
+ type: "validation";
7999
+ on: string;
8000
+ summary?: string;
8001
+ message?: string;
8002
+ found?: unknown;
8003
+ property?: string;
8004
+ expected?: string;
8005
+ };
8006
+ };
8007
+ };
8008
+ };
8009
+ };
8010
+ } & {
8011
+ schedule: {
8012
+ ":id": {
8013
+ delete: {
8014
+ body: unknown;
8015
+ params: {
8016
+ id: string;
8017
+ };
8018
+ query: unknown;
8019
+ headers: unknown;
8020
+ response: {
8021
+ 401: "Session not found";
8022
+ 422: {
8023
+ type: "validation";
8024
+ on: string;
8025
+ summary?: string;
8026
+ message?: string;
8027
+ found?: unknown;
8028
+ property?: string;
8029
+ expected?: string;
8030
+ };
8031
+ };
8032
+ };
8033
+ };
8034
+ };
8035
+ };
7972
8036
  };
7973
8037
  };
7974
8038
  }, {
package/dist/index.js CHANGED
@@ -142971,13 +142971,13 @@ var inspectionTemplateFieldTable = inspectionSchema.table("template_field", {
142971
142971
  templateId: uuid5().notNull(),
142972
142972
  fieldGroupId: uuid5(),
142973
142973
  fieldGroup: varchar(),
142974
- fieldId: uuid5().notNull(),
142974
+ fieldId: uuid5(),
142975
142975
  code: varchar(),
142976
142976
  description: text(),
142977
142977
  fieldType: inspectionFieldTypeEnum().notNull(),
142978
142978
  required: boolean4().notNull().default(false),
142979
142979
  metadata: jsonb(),
142980
- sortIndex: integer2()
142980
+ sortIndex: numeric({ mode: "number" })
142981
142981
  });
142982
142982
  var inspectionTemplateMachineKindTable = inspectionSchema.table("template_machine_kind", {
142983
142983
  templateId: uuid5().notNull(),
@@ -143024,6 +143024,7 @@ var inspectionFieldResult = inspectionSchema.table("field_result", {
143024
143024
  });
143025
143025
  var inspectionScheduleTable = inspectionSchema.table("schedule", {
143026
143026
  ...base_schema_helper_default,
143027
+ companyId: uuid5().notNull(),
143027
143028
  machineId: uuid5().notNull(),
143028
143029
  templateId: uuid5().notNull(),
143029
143030
  daysInterval: integer2(),
@@ -150940,39 +150941,35 @@ var CrmCpOrderLogic;
150940
150941
  model,
150941
150942
  customer: crmCustomerTable,
150942
150943
  isDeleteAble: sql3`(
150943
- select case when count(*) = 0 then TRUE else FALSE end from ${crmCpOrderItemTable} where ${crmCpOrderItemTable.cpOrderId} = ${crmCpOrderTable.id} and ${crmCpOrderItemTable.deletedAt} is null)`.as("is_delete_able")
150944
- }).from(crmCpOrderTable).leftJoin(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();
150944
+ select case when count(*) = 0 then TRUE else FALSE end from ${crmCpOrderItemTable} where ${crmCpOrderItemTable.cpOrderId} = ${crmCpOrderTable.id} and ${crmCpOrderItemTable.deletedAt} is null)`.as("is_delete_able"),
150945
+ totalAmount: sql3`
150946
+ (
150947
+ (
150948
+ COALESCE((select sum(${crmCpOrderItemTable.priceTotal}) from ${crmCpOrderItemTable} where ${crmCpOrderItemTable.cpOrderId} = ${crmCpOrderTable.id} and ${crmCpOrderItemTable.deletedAt} is null), 0)
150949
+ +
150950
+ COALESCE((select sum(${crmCpOrderSpPackageTable.priceTotal}) from ${crmCpOrderSpPackageTable} where ${crmCpOrderSpPackageTable.cpOrderId} = ${crmCpOrderTable.id} and ${crmCpOrderSpPackageTable.deletedAt} is null), 0)
150951
+ ) * CASE WHEN ${crmCpOrderTable.isNoat} THEN 1.1 ELSE 1 END
150952
+ -
150953
+ COALESCE((select sum(${crmDiscountApplyTable.valueApplied}) from ${crmDiscountApplyTable} where ${crmDiscountApplyTable.cpOrderId} = ${crmCpOrderTable.id} and ${crmDiscountApplyTable.deletedAt} is null), 0)
150954
+ )
150955
+ `.mapWith(Number).as("total_amount"),
150956
+ paidAmount: sql3`
150957
+ COALESCE((select sum(${crmCpOrderPaymentTable.amount}) from ${crmCpOrderPaymentTable} where ${crmCpOrderPaymentTable.cpOrderId} = ${crmCpOrderTable.id} and ${crmCpOrderPaymentTable.state} = 'PAID' and ${crmCpOrderPaymentTable.deletedAt} is null), 0)
150958
+ `.mapWith(Number).as("paid_amount")
150959
+ }).from(crmCpOrderTable).leftJoin(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)).having((t2) => query.isPaid === undefined ? undefined : query.isPaid ? sql3`${t2.totalAmount} - ${t2.paidAmount} = 0` : sql3`${t2.totalAmount} - ${t2.paidAmount} != 0`).groupBy((t2) => [
150960
+ t2.order.id,
150961
+ t2.vehicle.id,
150962
+ t2.make.id,
150963
+ t2.model.id,
150964
+ t2.customer.id
150965
+ ]).$dynamic();
150945
150966
  const result = await pagination_helper_default(baseQuery, query.pagination);
150946
- let totalAmounts = [];
150947
- let payments = [];
150948
- let appliedDiscounts = [];
150949
- let packageAmounts = [];
150950
- if (result.length > 0) {
150951
- const ids = result.map((i2) => i2.order.id);
150952
- [totalAmounts, payments, appliedDiscounts, packageAmounts] = await Promise.all([
150953
- logic_default7.selectAmountTotal(ids),
150954
- logic_default12.selectByCpOrderId(ids, true),
150955
- logic_default13.selectAppliesByCpOrderId(ids),
150956
- logic_default9.selectAmountTotal(ids)
150957
- ]);
150958
- }
150959
150967
  const content = {
150960
150968
  totalCount: result[0]?.totalCount ?? 0,
150961
150969
  totalPage: result.length === 0 ? 0 : Math.ceil(result[0].totalCount / query.pagination.size)
150962
150970
  };
150963
150971
  return {
150964
- result: result.map(({ totalCount, ...item }) => {
150965
- const totalAmount = totalAmounts.find((i2) => i2.cpOrderId === item.order.id);
150966
- const ad = appliedDiscounts.filter((i2) => i2.apply.cpOrderId === item.order.id);
150967
- const totalDiscount = ad.map((i2) => i2.apply.valueApplied).reduce((a, b) => a + b, 0);
150968
- const packageAmount = packageAmounts.find((p) => p.cpOrderId === item.order.id);
150969
- const ta = ((totalAmount?.amount ?? 0) + (packageAmount?.amount ?? 0)) * (totalAmount?.isNoat ? 1.1 : 1) - totalDiscount;
150970
- return {
150971
- ...item,
150972
- totalAmount: ta,
150973
- paidAmount: payments.filter((i2) => i2.cpOrderId === item.order.id).map((i2) => i2.amount).reduce((a, b) => a + b, 0)
150974
- };
150975
- }),
150972
+ result: result.map(({ totalCount, ...item }) => item),
150976
150973
  ...content
150977
150974
  };
150978
150975
  };
@@ -151730,7 +151727,7 @@ var payment_default = paymentRoutes;
151730
151727
  var cpOrderRoutes = new Elysia({
151731
151728
  prefix: "/cp-order",
151732
151729
  tags: ["CrmCpOrder"]
151733
- }).use(better_auth_default).use(item_default).use(payment_default).guard({ auth: true }).get("/", async ({ query, user: user2 }) => logic_default14.select(query, user2), {
151730
+ }).use(better_auth_default).use(item_default).use(payment_default).guard({ auth: true }).get("/", async ({ query, user: user2 }) => logic_default14.select(query, user2).catch((err2) => console.log(err2)), {
151734
151731
  query: model_default9.select
151735
151732
  }).post("/", async ({ body, user: user2 }) => {
151736
151733
  const created = await logic_default14.create(body, user2);
@@ -151753,6 +151750,16 @@ var cpOrderRoutes = new Elysia({
151753
151750
  body: model_default9.addPackage
151754
151751
  }).post("/complete", async ({ user: user2, body }) => logic_default14.complete(body, user2), {
151755
151752
  body: model_default9.complete
151753
+ }).post("/delete", async ({ user: user2 }) => {
151754
+ const results = await logic_default14.select({
151755
+ pagination: {
151756
+ page: 1,
151757
+ size: 1e4
151758
+ }
151759
+ }, user2);
151760
+ await db_default.update(crmCpOrderTable).set({
151761
+ deletedAt: sql3`now()`
151762
+ }).where(inArray(crmCpOrderTable.id, results.result.filter((i2) => !!i2.isDeleteAble).map((i2) => i2.order.id)));
151756
151763
  }).guard({
151757
151764
  params: IdSchema
151758
151765
  }).put("/:id", async ({ body, user: user2, params: { id } }) => logic_default14.update(id, body, user2), {
@@ -152107,7 +152114,7 @@ var CrmInspectionLogic;
152107
152114
  status: crmInspectionTable.status
152108
152115
  }
152109
152116
  }).from(crmInspectionTable).where(eq(crmInspectionTable.id, inspection.id)).leftJoin(companyCompanyTable, eq(companyCompanyTable.id, crmInspectionTable.companyId)).leftJoin(crmVehicleTable, eq(crmVehicleTable.id, crmInspectionTable.vehicleId)).leftJoin(techdocVehicleKindTable, eq(techdocVehicleKindTable.id, crmVehicleTable.vehicleKindId)).leftJoin(companyEmployeeTable, eq(companyEmployeeTable.id, crmInspectionTable.employeeId));
152110
- distribution_default.post(env_default.NODE_ENV === "development" ? "https://driver-partner-api.dev.ubcabtech.com/v1/webhook/autosync/inspection" : "https://driver-partner-api.ubcabtech.com/v1/webhook/autosync/inspection", {
152117
+ await distribution_default.post(env_default.NODE_ENV === "development" ? "https://driver-partner-api.dev.ubcabtech.com/v1/webhook/autosync/inspection" : "https://driver-partner-api.ubcabtech.com/v1/webhook/autosync/inspection", {
152111
152118
  json: result[0],
152112
152119
  retry: 3
152113
152120
  });
@@ -152545,7 +152552,7 @@ var CrmReportsLogic;
152545
152552
  return formatCSV(headers, rows);
152546
152553
  };
152547
152554
  CrmReportsLogic.cpOrderReport = async (query, user2) => {
152548
- const result = await db_default.select({
152555
+ const baseQuery = db_default.select({
152549
152556
  createdAt: crmCpOrderTable.createdAt,
152550
152557
  orderId: crmCpOrderTable.orderId,
152551
152558
  phone: crmCustomerTable.phoneNumber,
@@ -152559,8 +152566,9 @@ var CrmReportsLogic;
152559
152566
  discount: sql3`${crmDiscountApplyTable.priceAfterDiscount} - ${crmDiscountApplyTable.priceBeforeDiscount}`.as("discount"),
152560
152567
  priceAfterDiscount: crmDiscountApplyTable.priceAfterDiscount,
152561
152568
  totalPrice: sql3`CASE WHEN ${crmCpOrderTable.isNoat} = FALSE THEN ${crmCpOrderItemTable.priceTotal} ELSE 0 END`.as("total_price"),
152562
- totalPriceNoat: sql3`CASE WHEN ${crmCpOrderTable.isNoat} = TRUE THEN ${crmCpOrderItemTable.priceTotal} * 1.1 ELSE 0 END`.as("total_price_noat")
152563
- }).from(crmCpOrderItemTable).leftJoin(crmCpOrderTable, eq(crmCpOrderTable.id, crmCpOrderItemTable.cpOrderId)).leftJoin(crmCustomerTable, eq(crmCustomerTable.id, crmCpOrderTable.customerId)).leftJoin(crmVehicleTable, eq(crmVehicleTable.id, crmCpOrderTable.vehicleId)).leftJoin(warehouseProductTable, eq(warehouseProductTable.productId, crmCpOrderItemTable.companyProductId)).leftJoin(companyServiceKindTable, eq(companyServiceKindTable.id, crmCpOrderItemTable.companyServiceKindId)).leftJoin(crmCpOrderItemEmployeeTable, eq(crmCpOrderItemEmployeeTable.cpOrderItemId, crmCpOrderItemTable.id)).leftJoin(companyEmployeeTable, eq(companyEmployeeTable.id, crmCpOrderItemEmployeeTable.employeeId)).leftJoin(crmDiscountApplyTable, eq(crmDiscountApplyTable.cpOrderItemId, crmCpOrderItemTable.id)).where(and(eq(crmCpOrderTable.companyId, user2.companyId), eq(crmCpOrderTable.companyBranchId, user2.branchId).if(user2.kind === "CUSTOMER"), isNotNull(crmCpOrderItemTable.companyProductId).if(query.type === "Product"), isNotNull(crmCpOrderItemTable.companyServiceKindId).if(query.type === "Service"))).groupBy((t2) => [
152569
+ totalPriceNoat: sql3`CASE WHEN ${crmCpOrderTable.isNoat} = TRUE THEN ${crmCpOrderItemTable.priceTotal} * 1.1 ELSE 0 END`.as("total_price_noat"),
152570
+ totalCount: totalCountSql
152571
+ }).from(crmCpOrderItemTable).leftJoin(crmCpOrderTable, eq(crmCpOrderTable.id, crmCpOrderItemTable.cpOrderId)).leftJoin(crmCustomerTable, eq(crmCustomerTable.id, crmCpOrderTable.customerId)).leftJoin(crmVehicleTable, eq(crmVehicleTable.id, crmCpOrderTable.vehicleId)).leftJoin(warehouseProductTable, eq(warehouseProductTable.id, crmCpOrderItemTable.companyProductId)).leftJoin(companyServiceKindTable, eq(companyServiceKindTable.id, crmCpOrderItemTable.companyServiceKindId)).leftJoin(crmCpOrderItemEmployeeTable, eq(crmCpOrderItemEmployeeTable.cpOrderItemId, crmCpOrderItemTable.id)).leftJoin(companyEmployeeTable, eq(companyEmployeeTable.id, crmCpOrderItemEmployeeTable.employeeId)).leftJoin(crmDiscountApplyTable, eq(crmDiscountApplyTable.cpOrderItemId, crmCpOrderItemTable.id)).where(and(eq(crmCpOrderTable.companyId, user2.companyId), eq(crmCpOrderTable.companyBranchId, user2.branchId).if(user2.kind === "CUSTOMER"), isNotNull(crmCpOrderItemTable.companyProductId).if(query.type === "Product"), isNotNull(crmCpOrderItemTable.companyServiceKindId).if(query.type === "Service"))).groupBy((t2) => [
152564
152572
  t2.createdAt,
152565
152573
  t2.orderId,
152566
152574
  t2.phone,
@@ -152574,8 +152582,9 @@ var CrmReportsLogic;
152574
152582
  t2.discount,
152575
152583
  t2.totalPrice,
152576
152584
  t2.totalPriceNoat
152577
- ]);
152578
- return result;
152585
+ ]).$dynamic();
152586
+ const result = await pagination_helper_default(baseQuery, query.pagination);
152587
+ return getPaginationContent(result, query.pagination.size);
152579
152588
  };
152580
152589
  })(CrmReportsLogic ||= {});
152581
152590
  var logic_default18 = CrmReportsLogic;
@@ -152661,9 +152670,12 @@ var CrmReportsModel;
152661
152670
  totalPages: t.Number()
152662
152671
  })
152663
152672
  });
152664
- CrmReportsModel.cpOrderReport = t.Object({
152665
- type: t.UnionEnum(["Product", "Service"])
152666
- });
152673
+ CrmReportsModel.cpOrderReport = t.Composite([
152674
+ t.Object({
152675
+ type: t.UnionEnum(["Product", "Service"])
152676
+ }),
152677
+ PaginationSchema
152678
+ ]);
152667
152679
  CrmReportsModel.cpOrderEmployeeReport = t.Object({
152668
152680
  employeeId: t.String({ format: "uuid" })
152669
152681
  });
@@ -154002,6 +154014,59 @@ var fieldGroupRoutes = new Elysia({
154002
154014
  }).delete("/:id", async ({ params: { id } }) => logic_default26.remove(id)).get("/:id/field", async ({ params: { id } }) => logic_default25.select(id));
154003
154015
  var fieldGroup_default = fieldGroupRoutes;
154004
154016
 
154017
+ // src/routes/fleet/inspection/schedule/logic.ts
154018
+ var InspectionScheduleLogic;
154019
+ ((InspectionScheduleLogic) => {
154020
+ InspectionScheduleLogic.select = async (query, user2) => {
154021
+ const filter = and(softDeletedFilter(inspectionScheduleTable), eq(inspectionScheduleTable.companyId, user2.companyId));
154022
+ const columns = getTableColumns(inspectionScheduleTable);
154023
+ const baseQuery = db_default.select({
154024
+ ...columns,
154025
+ totalCount: totalCountSql
154026
+ }).from(inspectionScheduleTable).where(filter).$dynamic();
154027
+ const result = await pagination_helper_default(baseQuery, query.pagination);
154028
+ return getPaginationContent(result, query.pagination.size);
154029
+ };
154030
+ InspectionScheduleLogic.create = async (body, user2) => {
154031
+ await db_default.insert(inspectionScheduleTable).values({
154032
+ ...body,
154033
+ companyId: user2.companyId
154034
+ });
154035
+ };
154036
+ InspectionScheduleLogic.update = async (id, body, user2) => {
154037
+ await db_default.update(inspectionScheduleTable).set(body).where(and(eq(inspectionScheduleTable.id, id), eq(inspectionScheduleTable.companyId, user2.companyId)));
154038
+ };
154039
+ InspectionScheduleLogic.remove = async (id, user2) => {
154040
+ await db_default.update(inspectionScheduleTable).set({
154041
+ deletedAt: sql3`now()`
154042
+ }).where(and(eq(inspectionScheduleTable.id, id), eq(inspectionScheduleTable.companyId, user2.companyId)));
154043
+ };
154044
+ })(InspectionScheduleLogic ||= {});
154045
+ var logic_default27 = InspectionScheduleLogic;
154046
+
154047
+ // src/routes/fleet/inspection/schedule/model.ts
154048
+ var InspectionScheduleModel;
154049
+ ((InspectionScheduleModel) => {
154050
+ const createSchema = createInsertSchema2(inspectionScheduleTable);
154051
+ const updateSchema = createUpdateSchema(inspectionScheduleTable);
154052
+ InspectionScheduleModel.create = t.Omit(OmitBaseSchema(createSchema), ["companyId"]);
154053
+ InspectionScheduleModel.update = OmitBaseSchema(updateSchema);
154054
+ InspectionScheduleModel.select = t.Composite([PaginationSchema]);
154055
+ })(InspectionScheduleModel ||= {});
154056
+ var model_default27 = InspectionScheduleModel;
154057
+
154058
+ // src/routes/fleet/inspection/schedule/index.ts
154059
+ var scheduleRoutes = new Elysia({
154060
+ prefix: "/schedule"
154061
+ }).use(better_auth_default).guard({ auth: true }).get("/", async ({ query, user: user2 }) => logic_default27.select(query, user2), {
154062
+ query: model_default27.select
154063
+ }).post("/", async ({ body, user: user2 }) => logic_default27.create(body, user2), {
154064
+ body: model_default27.create
154065
+ }).guard({
154066
+ params: IdSchema
154067
+ }).put("/:id", async ({ body, params: { id }, user: user2 }) => logic_default27.update(id, body, user2), { body: model_default27.update }).delete("/:id", async ({ params: { id }, user: user2 }) => logic_default27.remove(id, user2));
154068
+ var schedule_default = scheduleRoutes;
154069
+
154005
154070
  // src/routes/fleet/inspection/template/logic.ts
154006
154071
  var InspectionTemplateLogic;
154007
154072
  ((InspectionTemplateLogic) => {
@@ -154058,7 +154123,7 @@ var InspectionTemplateLogic;
154058
154123
  }).where(eq(inspectionTemplateFieldTable.id, id));
154059
154124
  };
154060
154125
  })(InspectionTemplateLogic ||= {});
154061
- var logic_default27 = InspectionTemplateLogic;
154126
+ var logic_default28 = InspectionTemplateLogic;
154062
154127
 
154063
154128
  // src/routes/fleet/inspection/template/model.ts
154064
154129
  var InspectionTemplateModel;
@@ -154073,7 +154138,7 @@ var InspectionTemplateModel;
154073
154138
  "templateId"
154074
154139
  ]);
154075
154140
  })(InspectionTemplateModel ||= {});
154076
- var model_default27 = InspectionTemplateModel;
154141
+ var model_default28 = InspectionTemplateModel;
154077
154142
 
154078
154143
  // src/routes/fleet/inspection/template/index.ts
154079
154144
  var templateRoutes = new Elysia({
@@ -154081,23 +154146,23 @@ var templateRoutes = new Elysia({
154081
154146
  tags: ["InspectionTemplate"]
154082
154147
  }).use(better_auth_default).guard({
154083
154148
  userKind: "COMPANY_ADMIN"
154084
- }).get("/", async ({ query, user: user2 }) => logic_default27.select(query, user2), {
154085
- query: model_default27.select
154086
- }).post("/", async ({ body, user: user2 }) => logic_default27.create(body, user2), {
154087
- body: model_default27.create
154149
+ }).get("/", async ({ query, user: user2 }) => logic_default28.select(query, user2), {
154150
+ query: model_default28.select
154151
+ }).post("/", async ({ body, user: user2 }) => logic_default28.create(body, user2), {
154152
+ body: model_default28.create
154088
154153
  }).guard({
154089
154154
  params: IdSchema
154090
- }).get("/:id", async ({ params: { id }, user: user2 }) => logic_default27.selectById(id, user2)).put("/:id", async ({ body, params: { id }, user: user2 }) => logic_default27.update(id, body, user2), {
154091
- body: model_default27.update
154092
- }).delete("/:id", async ({ params: { id }, user: user2 }) => logic_default27.remove(id, user2)).get("/:id/field", async ({ params: { id } }) => logic_default27.selectField(id)).post("/:id/field", async ({ body, params: { id } }) => logic_default27.addField(id, body), {
154093
- body: model_default27.createField
154094
- }).delete("/field/:id", async ({ params: { id } }) => logic_default27.removeField(id));
154155
+ }).get("/:id", async ({ params: { id }, user: user2 }) => logic_default28.selectById(id, user2)).put("/:id", async ({ body, params: { id }, user: user2 }) => logic_default28.update(id, body, user2), {
154156
+ body: model_default28.update
154157
+ }).delete("/:id", async ({ params: { id }, user: user2 }) => logic_default28.remove(id, user2)).get("/:id/field", async ({ params: { id } }) => logic_default28.selectField(id)).post("/:id/field", async ({ body, params: { id } }) => logic_default28.addField(id, body), {
154158
+ body: model_default28.createField
154159
+ }).delete("/field/:id", async ({ params: { id } }) => logic_default28.removeField(id));
154095
154160
  var template_default = templateRoutes;
154096
154161
 
154097
154162
  // src/routes/fleet/inspection/index.ts
154098
154163
  var inspectionRoutes2 = new Elysia({
154099
154164
  prefix: "/inspection"
154100
- }).use(fieldGroup_default).use(field_default).use(template_default);
154165
+ }).use(fieldGroup_default).use(field_default).use(template_default).use(schedule_default);
154101
154166
  var inspection_default2 = inspectionRoutes2;
154102
154167
 
154103
154168
  // src/routes/fleet/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autosync_backend2",
3
- "version": "1.2.20",
3
+ "version": "1.2.22",
4
4
  "module": "src/index.ts",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",