autosync_backend2 1.2.21 → 1.2.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.
Files changed (3) hide show
  1. package/dist/index.d.ts +180 -111
  2. package/dist/index.js +120 -53
  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": {
@@ -7124,26 +7045,40 @@ export declare const app: Elysia<"", {
7124
7045
  body: unknown;
7125
7046
  params: {};
7126
7047
  query: {
7127
- type: "Service" | "Product";
7048
+ type?: "Service" | "Product" | undefined;
7049
+ employeeId?: string | undefined;
7050
+ phoneNumber?: string | undefined;
7051
+ licensePlate?: string | undefined;
7052
+ startDate?: string | undefined;
7053
+ endDate?: string | undefined;
7054
+ pagination: {
7055
+ size: number;
7056
+ page: number;
7057
+ };
7128
7058
  };
7129
7059
  headers: unknown;
7130
7060
  response: {
7131
7061
  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
- }[];
7062
+ totalCount: number;
7063
+ totalPage: number;
7064
+ result: Omit<{
7065
+ createdAt: string | null;
7066
+ orderId: string | null;
7067
+ phone: string | null;
7068
+ licensePlate: string | null;
7069
+ name: string | null;
7070
+ partNumber: string | null;
7071
+ employeeName: unknown;
7072
+ quantity: number;
7073
+ priceBuy: number | null;
7074
+ price: number;
7075
+ discount: unknown;
7076
+ priceAfterDiscount: number | null;
7077
+ totalPrice: unknown;
7078
+ totalPriceNoat: unknown;
7079
+ totalCount: number;
7080
+ }, "totalCount">[];
7081
+ };
7147
7082
  401: "Session not found";
7148
7083
  422: {
7149
7084
  type: "validation";
@@ -7969,6 +7904,140 @@ export declare const app: Elysia<"", {
7969
7904
  };
7970
7905
  };
7971
7906
  };
7907
+ } & {
7908
+ inspection: {
7909
+ schedule: {};
7910
+ } & {
7911
+ schedule: {
7912
+ get: {
7913
+ body: unknown;
7914
+ params: {};
7915
+ query: {
7916
+ pagination: {
7917
+ size: number;
7918
+ page: number;
7919
+ };
7920
+ };
7921
+ headers: unknown;
7922
+ response: {
7923
+ 200: {
7924
+ totalCount: number;
7925
+ totalPage: number;
7926
+ result: Omit<{
7927
+ totalCount: number;
7928
+ companyId: string;
7929
+ machineId: string;
7930
+ templateId: string;
7931
+ daysInterval: number | null;
7932
+ timeNextDue: Date | null;
7933
+ isActive: boolean;
7934
+ id: string;
7935
+ createdAt: string;
7936
+ updatedAt: string;
7937
+ deletedAt: string | null;
7938
+ oldId: number | null;
7939
+ }, "totalCount">[];
7940
+ };
7941
+ 401: "Session not found";
7942
+ 422: {
7943
+ type: "validation";
7944
+ on: string;
7945
+ summary?: string;
7946
+ message?: string;
7947
+ found?: unknown;
7948
+ property?: string;
7949
+ expected?: string;
7950
+ };
7951
+ };
7952
+ };
7953
+ };
7954
+ } & {
7955
+ schedule: {
7956
+ post: {
7957
+ body: {
7958
+ oldId?: number | null | undefined;
7959
+ isActive?: boolean | undefined;
7960
+ daysInterval?: number | null | undefined;
7961
+ timeNextDue?: Date | null | undefined;
7962
+ templateId: string;
7963
+ machineId: string;
7964
+ };
7965
+ params: {};
7966
+ query: unknown;
7967
+ headers: unknown;
7968
+ response: {
7969
+ 401: "Session not found";
7970
+ 422: {
7971
+ type: "validation";
7972
+ on: string;
7973
+ summary?: string;
7974
+ message?: string;
7975
+ found?: unknown;
7976
+ property?: string;
7977
+ expected?: string;
7978
+ };
7979
+ };
7980
+ };
7981
+ };
7982
+ } & {
7983
+ schedule: {
7984
+ ":id": {
7985
+ put: {
7986
+ body: {
7987
+ companyId?: string | undefined;
7988
+ oldId?: number | null | undefined;
7989
+ isActive?: boolean | undefined;
7990
+ templateId?: string | undefined;
7991
+ machineId?: string | undefined;
7992
+ daysInterval?: number | null | undefined;
7993
+ timeNextDue?: Date | null | undefined;
7994
+ };
7995
+ params: {
7996
+ id: string;
7997
+ };
7998
+ query: unknown;
7999
+ headers: unknown;
8000
+ response: {
8001
+ 401: "Session not found";
8002
+ 422: {
8003
+ type: "validation";
8004
+ on: string;
8005
+ summary?: string;
8006
+ message?: string;
8007
+ found?: unknown;
8008
+ property?: string;
8009
+ expected?: string;
8010
+ };
8011
+ };
8012
+ };
8013
+ };
8014
+ };
8015
+ } & {
8016
+ schedule: {
8017
+ ":id": {
8018
+ delete: {
8019
+ body: unknown;
8020
+ params: {
8021
+ id: string;
8022
+ };
8023
+ query: unknown;
8024
+ headers: unknown;
8025
+ response: {
8026
+ 401: "Session not found";
8027
+ 422: {
8028
+ type: "validation";
8029
+ on: string;
8030
+ summary?: string;
8031
+ message?: string;
8032
+ found?: unknown;
8033
+ property?: string;
8034
+ expected?: string;
8035
+ };
8036
+ };
8037
+ };
8038
+ };
8039
+ };
8040
+ };
7972
8041
  };
7973
8042
  };
7974
8043
  }, {
package/dist/index.js CHANGED
@@ -142977,7 +142977,7 @@ var inspectionTemplateFieldTable = inspectionSchema.table("template_field", {
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"), eq(crmCpOrderItemEmployeeTable.employeeId, query.employeeId).if(query.employeeId), gte(crmCpOrderTable.createdAt, query.startDate).if(query.startDate), lte(crmCpOrderTable.createdAt, query.endDate).if(query.endDate), eq(crmCustomerTable.phoneNumber, query.phoneNumber).if(query.phoneNumber), eq(crmVehicleTable.licensePlate, query.licensePlate).if(query.licensePlate))).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,12 +152670,17 @@ var CrmReportsModel;
152661
152670
  totalPages: t.Number()
152662
152671
  })
152663
152672
  });
152664
- CrmReportsModel.cpOrderReport = t.Object({
152665
- type: t.UnionEnum(["Product", "Service"])
152666
- });
152667
- CrmReportsModel.cpOrderEmployeeReport = t.Object({
152668
- employeeId: t.String({ format: "uuid" })
152669
- });
152673
+ CrmReportsModel.cpOrderReport = t.Composite([
152674
+ t.Partial(t.Object({
152675
+ type: t.UnionEnum(["Product", "Service"]),
152676
+ employeeId: t.String({ format: "uuid" }),
152677
+ startDate: t.String({ format: "date" }),
152678
+ endDate: t.String({ format: "date" }),
152679
+ phoneNumber: t.String(),
152680
+ licensePlate: t.String()
152681
+ })),
152682
+ PaginationSchema
152683
+ ]);
152670
152684
  })(CrmReportsModel ||= {});
152671
152685
  var model_default14 = CrmReportsModel;
152672
152686
 
@@ -154002,6 +154016,59 @@ var fieldGroupRoutes = new Elysia({
154002
154016
  }).delete("/:id", async ({ params: { id } }) => logic_default26.remove(id)).get("/:id/field", async ({ params: { id } }) => logic_default25.select(id));
154003
154017
  var fieldGroup_default = fieldGroupRoutes;
154004
154018
 
154019
+ // src/routes/fleet/inspection/schedule/logic.ts
154020
+ var InspectionScheduleLogic;
154021
+ ((InspectionScheduleLogic) => {
154022
+ InspectionScheduleLogic.select = async (query, user2) => {
154023
+ const filter = and(softDeletedFilter(inspectionScheduleTable), eq(inspectionScheduleTable.companyId, user2.companyId));
154024
+ const columns = getTableColumns(inspectionScheduleTable);
154025
+ const baseQuery = db_default.select({
154026
+ ...columns,
154027
+ totalCount: totalCountSql
154028
+ }).from(inspectionScheduleTable).where(filter).$dynamic();
154029
+ const result = await pagination_helper_default(baseQuery, query.pagination);
154030
+ return getPaginationContent(result, query.pagination.size);
154031
+ };
154032
+ InspectionScheduleLogic.create = async (body, user2) => {
154033
+ await db_default.insert(inspectionScheduleTable).values({
154034
+ ...body,
154035
+ companyId: user2.companyId
154036
+ });
154037
+ };
154038
+ InspectionScheduleLogic.update = async (id, body, user2) => {
154039
+ await db_default.update(inspectionScheduleTable).set(body).where(and(eq(inspectionScheduleTable.id, id), eq(inspectionScheduleTable.companyId, user2.companyId)));
154040
+ };
154041
+ InspectionScheduleLogic.remove = async (id, user2) => {
154042
+ await db_default.update(inspectionScheduleTable).set({
154043
+ deletedAt: sql3`now()`
154044
+ }).where(and(eq(inspectionScheduleTable.id, id), eq(inspectionScheduleTable.companyId, user2.companyId)));
154045
+ };
154046
+ })(InspectionScheduleLogic ||= {});
154047
+ var logic_default27 = InspectionScheduleLogic;
154048
+
154049
+ // src/routes/fleet/inspection/schedule/model.ts
154050
+ var InspectionScheduleModel;
154051
+ ((InspectionScheduleModel) => {
154052
+ const createSchema = createInsertSchema2(inspectionScheduleTable);
154053
+ const updateSchema = createUpdateSchema(inspectionScheduleTable);
154054
+ InspectionScheduleModel.create = t.Omit(OmitBaseSchema(createSchema), ["companyId"]);
154055
+ InspectionScheduleModel.update = OmitBaseSchema(updateSchema);
154056
+ InspectionScheduleModel.select = t.Composite([PaginationSchema]);
154057
+ })(InspectionScheduleModel ||= {});
154058
+ var model_default27 = InspectionScheduleModel;
154059
+
154060
+ // src/routes/fleet/inspection/schedule/index.ts
154061
+ var scheduleRoutes = new Elysia({
154062
+ prefix: "/schedule"
154063
+ }).use(better_auth_default).guard({ auth: true }).get("/", async ({ query, user: user2 }) => logic_default27.select(query, user2), {
154064
+ query: model_default27.select
154065
+ }).post("/", async ({ body, user: user2 }) => logic_default27.create(body, user2), {
154066
+ body: model_default27.create
154067
+ }).guard({
154068
+ params: IdSchema
154069
+ }).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));
154070
+ var schedule_default = scheduleRoutes;
154071
+
154005
154072
  // src/routes/fleet/inspection/template/logic.ts
154006
154073
  var InspectionTemplateLogic;
154007
154074
  ((InspectionTemplateLogic) => {
@@ -154058,7 +154125,7 @@ var InspectionTemplateLogic;
154058
154125
  }).where(eq(inspectionTemplateFieldTable.id, id));
154059
154126
  };
154060
154127
  })(InspectionTemplateLogic ||= {});
154061
- var logic_default27 = InspectionTemplateLogic;
154128
+ var logic_default28 = InspectionTemplateLogic;
154062
154129
 
154063
154130
  // src/routes/fleet/inspection/template/model.ts
154064
154131
  var InspectionTemplateModel;
@@ -154073,7 +154140,7 @@ var InspectionTemplateModel;
154073
154140
  "templateId"
154074
154141
  ]);
154075
154142
  })(InspectionTemplateModel ||= {});
154076
- var model_default27 = InspectionTemplateModel;
154143
+ var model_default28 = InspectionTemplateModel;
154077
154144
 
154078
154145
  // src/routes/fleet/inspection/template/index.ts
154079
154146
  var templateRoutes = new Elysia({
@@ -154081,23 +154148,23 @@ var templateRoutes = new Elysia({
154081
154148
  tags: ["InspectionTemplate"]
154082
154149
  }).use(better_auth_default).guard({
154083
154150
  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
154151
+ }).get("/", async ({ query, user: user2 }) => logic_default28.select(query, user2), {
154152
+ query: model_default28.select
154153
+ }).post("/", async ({ body, user: user2 }) => logic_default28.create(body, user2), {
154154
+ body: model_default28.create
154088
154155
  }).guard({
154089
154156
  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));
154157
+ }).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), {
154158
+ body: model_default28.update
154159
+ }).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), {
154160
+ body: model_default28.createField
154161
+ }).delete("/field/:id", async ({ params: { id } }) => logic_default28.removeField(id));
154095
154162
  var template_default = templateRoutes;
154096
154163
 
154097
154164
  // src/routes/fleet/inspection/index.ts
154098
154165
  var inspectionRoutes2 = new Elysia({
154099
154166
  prefix: "/inspection"
154100
- }).use(fieldGroup_default).use(field_default).use(template_default);
154167
+ }).use(fieldGroup_default).use(field_default).use(template_default).use(schedule_default);
154101
154168
  var inspection_default2 = inspectionRoutes2;
154102
154169
 
154103
154170
  // src/routes/fleet/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autosync_backend2",
3
- "version": "1.2.21",
3
+ "version": "1.2.23",
4
4
  "module": "src/index.ts",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",