autosync_backend2 1.1.69 → 1.1.70

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
@@ -3860,7 +3860,7 @@ export declare const app: Elysia<"", {
3860
3860
  isNoat: boolean | null;
3861
3861
  timeCompleted: string | null;
3862
3862
  km: number;
3863
- type: "Service" | "ProductSale";
3863
+ type: "Service" | "ProductSell";
3864
3864
  id: string;
3865
3865
  createdAt: string;
3866
3866
  updatedAt: string;
@@ -3972,7 +3972,7 @@ export declare const app: Elysia<"", {
3972
3972
  isNoat: boolean | null;
3973
3973
  timeCompleted: string | null;
3974
3974
  km: number;
3975
- type: "Service" | "ProductSale";
3975
+ type: "Service" | "ProductSell";
3976
3976
  id: string;
3977
3977
  createdAt: string;
3978
3978
  updatedAt: string;
@@ -4057,6 +4057,35 @@ export declare const app: Elysia<"", {
4057
4057
  };
4058
4058
  };
4059
4059
  };
4060
+ } & {
4061
+ "cp-order": {
4062
+ sell: {
4063
+ post: {
4064
+ body: unknown;
4065
+ params: {};
4066
+ query: unknown;
4067
+ headers: unknown;
4068
+ response: {
4069
+ 200: {
4070
+ type: "Service" | "ProductSell";
4071
+ id: string;
4072
+ createdAt: string;
4073
+ updatedAt: string;
4074
+ companyId: string;
4075
+ deletedAt: string | null;
4076
+ isNoat: boolean | null;
4077
+ companyBranchId: string;
4078
+ customerId: string | null;
4079
+ vehicleId: string | null;
4080
+ km: number;
4081
+ orderId: string;
4082
+ state: "CREATED" | "PROGRESSING" | "COMPLETE";
4083
+ timeCompleted: string | null;
4084
+ };
4085
+ };
4086
+ };
4087
+ };
4088
+ };
4060
4089
  } & {
4061
4090
  "cp-order": {
4062
4091
  package: {
@@ -4108,7 +4137,7 @@ export declare const app: Elysia<"", {
4108
4137
  isNoat: boolean | null;
4109
4138
  timeCompleted: string | null;
4110
4139
  km: number;
4111
- type: "Service" | "ProductSale";
4140
+ type: "Service" | "ProductSell";
4112
4141
  id: string;
4113
4142
  createdAt: string;
4114
4143
  updatedAt: string;
@@ -4133,7 +4162,7 @@ export declare const app: Elysia<"", {
4133
4162
  ":id": {
4134
4163
  put: {
4135
4164
  body: {
4136
- type?: "Service" | "ProductSale" | undefined;
4165
+ type?: "Service" | "ProductSell" | undefined;
4137
4166
  companyId?: string | undefined;
4138
4167
  isNoat?: boolean | null | undefined;
4139
4168
  companyBranchId?: string | undefined;
@@ -4160,7 +4189,7 @@ export declare const app: Elysia<"", {
4160
4189
  isNoat: boolean | null;
4161
4190
  timeCompleted: string | null;
4162
4191
  km: number;
4163
- type: "Service" | "ProductSale";
4192
+ type: "Service" | "ProductSell";
4164
4193
  id: string;
4165
4194
  createdAt: string;
4166
4195
  updatedAt: string;
@@ -6217,7 +6246,7 @@ export declare const app: Elysia<"", {
6217
6246
  isNoat: boolean | null;
6218
6247
  timeCompleted: string | null;
6219
6248
  km: number;
6220
- type: "Service" | "ProductSale";
6249
+ type: "Service" | "ProductSell";
6221
6250
  id: string;
6222
6251
  createdAt: string;
6223
6252
  updatedAt: string;
@@ -6445,7 +6474,7 @@ export declare const app: Elysia<"", {
6445
6474
  isNoat: boolean | null;
6446
6475
  timeCompleted: string | null;
6447
6476
  km: number;
6448
- type: "Service" | "ProductSale";
6477
+ type: "Service" | "ProductSell";
6449
6478
  id: string;
6450
6479
  createdAt: string;
6451
6480
  updatedAt: string;
package/dist/index.js CHANGED
@@ -147393,7 +147393,7 @@ var crmCpOrderStateEnum = pgEnum("cp_order_state", [
147393
147393
  ]);
147394
147394
  var crmCpOrderTypeEnum = pgEnum("cp_order_type", [
147395
147395
  "Service",
147396
- "ProductSale"
147396
+ "ProductSell"
147397
147397
  ]);
147398
147398
  var crmCpOrderTable = crmSchema.table("cp_order", {
147399
147399
  ...base_schema_helper_default,
@@ -155085,21 +155085,32 @@ var CrmCpOrderLogic;
155085
155085
  if (vehicle.customerId && !customerId) {
155086
155086
  customerId = vehicle.customerId;
155087
155087
  }
155088
- const orderId = await getOrderId(user2);
155088
+ const orderId = await getOrderId("Service", user2);
155089
155089
  const [result] = await db2.insert(crmCpOrderTable).values({
155090
155090
  companyId: user2.companyId,
155091
155091
  companyBranchId: user2.branchId,
155092
155092
  customerId,
155093
155093
  vehicleId: vehicle.id,
155094
- orderId
155094
+ orderId,
155095
+ type: "Service"
155095
155096
  }).returning();
155096
155097
  return result;
155097
155098
  });
155098
155099
  };
155099
- const getOrderId = async (user2) => {
155100
+ CrmCpOrderLogic.createSell = async (user2) => {
155101
+ const orderId = await getOrderId("ProductSell", user2);
155102
+ const [result] = await db_default.insert(crmCpOrderTable).values({
155103
+ companyBranchId: user2.branchId,
155104
+ companyId: user2.companyId,
155105
+ orderId,
155106
+ type: "Service"
155107
+ }).returning();
155108
+ return result;
155109
+ };
155110
+ const getOrderId = async (type, user2) => {
155100
155111
  const today = new Date;
155101
155112
  const formatted = `${today.getFullYear()}${(today.getMonth() + 1).toString().padStart(2, "0")}${today.getDate().toString().padStart(2, "0")}`;
155102
- const cacheKey = `cp_order_id:${user2.companyId}:${user2.branchId}:${formatted}`;
155113
+ const cacheKey = `cp_order${type === "ProductSell" ? "_sell_" : ""}_id:${user2.companyId}:${user2.branchId}:${formatted}`;
155103
155114
  const cached3 = await redis_client_default.get(cacheKey);
155104
155115
  if (cached3) {
155105
155116
  const count2 = cached3 + 1;
@@ -155109,7 +155120,7 @@ var CrmCpOrderLogic;
155109
155120
  }
155110
155121
  const [latest] = await db_default.select({
155111
155122
  orderId: crmCpOrderTable.orderId
155112
- }).from(crmCpOrderTable).where(and(ilike(crmCpOrderTable.orderId, `${formatted}%`), eq(crmCpOrderTable.companyId, user2.companyId), eq(crmCpOrderTable.companyBranchId, user2.branchId))).orderBy(desc(crmCpOrderTable.orderId)).limit(1);
155123
+ }).from(crmCpOrderTable).where(and(ilike(crmCpOrderTable.orderId, `${formatted}%`), eq(crmCpOrderTable.companyId, user2.companyId), eq(crmCpOrderTable.companyBranchId, user2.branchId), eq(crmCpOrderTable.type, type))).orderBy(desc(crmCpOrderTable.orderId)).limit(1);
155113
155124
  if (latest) {
155114
155125
  const count2 = +latest.orderId.split("-")[1] + 1;
155115
155126
  await redis_client_default.set(cacheKey, count2);
@@ -155812,7 +155823,7 @@ var cpOrderRoutes = new Elysia({
155812
155823
  return result;
155813
155824
  }, {
155814
155825
  body: model_default8.create
155815
- }).post("/package", async ({ body, user: user2 }) => logic_default12.addPackage(body, user2), {
155826
+ }).post("/sell", async ({ user: user2 }) => logic_default12.createSell(user2)).post("/package", async ({ body, user: user2 }) => logic_default12.addPackage(body, user2), {
155816
155827
  body: model_default8.addPackage
155817
155828
  }).post("/complete", async ({ user: user2, body }) => logic_default12.complete(body, user2), {
155818
155829
  body: model_default8.complete
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autosync_backend2",
3
- "version": "1.1.69",
3
+ "version": "1.1.70",
4
4
  "module": "src/index.ts",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",