autosync_backend2 1.1.52 → 1.1.54

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 +178 -12
  2. package/dist/index.js +222 -167
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -52,11 +52,11 @@ export declare const app: Elysia<"", {
52
52
  alias: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>>;
53
53
  }>;
54
54
  readonly "WarehouseProductModel.select": import("@sinclair/typebox").TObject<{
55
+ search: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
55
56
  id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
56
57
  branchId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
57
58
  ids: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
58
59
  type: import("@sinclair/typebox").TOptional<import("elysia/dist/type-system/types").TUnionEnum<["Сэлбэг", "Тос", "Дугуй", "Будаг", "Аккумлятор"]>>;
59
- search: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
60
60
  supplierId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
61
61
  productId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
62
62
  priceSell: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
@@ -108,11 +108,11 @@ export declare const app: Elysia<"", {
108
108
  size: import("@sinclair/typebox").TInteger;
109
109
  }>;
110
110
  product: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
111
+ search: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
111
112
  id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
112
113
  branchId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
113
114
  ids: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
114
115
  type: import("@sinclair/typebox").TOptional<import("elysia/dist/type-system/types").TUnionEnum<["Сэлбэг", "Тос", "Дугуй", "Будаг", "Аккумлятор"]>>;
115
- search: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
116
116
  supplierId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
117
117
  productId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
118
118
  priceSell: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
@@ -482,11 +482,11 @@ export declare const app: Elysia<"", {
482
482
  page: import("@sinclair/typebox").TInteger;
483
483
  size: import("@sinclair/typebox").TInteger;
484
484
  }>;
485
+ licensePlate: import("@sinclair/typebox").TOptional<import("elysia/dist/type-system/types").TTransform<import("@sinclair/typebox").TString, string>>;
485
486
  id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
486
487
  createdAt: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
487
488
  phone: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
488
489
  orderId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
489
- licensePlate: import("@sinclair/typebox").TOptional<import("elysia/dist/type-system/types").TTransform<import("@sinclair/typebox").TString, string>>;
490
490
  vin: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
491
491
  state: import("@sinclair/typebox").TOptional<import("elysia/dist/type-system/types").TUnionEnum<["CREATED", "PROGRESSING", "COMPLETE"]>>;
492
492
  timeCompleted: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
@@ -708,13 +708,24 @@ export declare const app: Elysia<"", {
708
708
  answer: import("@sinclair/typebox").TString;
709
709
  description: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
710
710
  }>;
711
- employeeId: import("@sinclair/typebox").TString;
712
- description: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
713
- isApproved: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
714
711
  }>>;
715
712
  experience: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>>;
716
713
  rank: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>>;
717
714
  licensePlate: import("@sinclair/typebox").TString;
715
+ status: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TEnum<{
716
+ CREATED: "CREATED";
717
+ APPROVED: "APPROVED";
718
+ CANCELLED: "CANCELLED";
719
+ }>>;
720
+ }>;
721
+ readonly "CrmInspectionModel.select": import("@sinclair/typebox").TObject<{
722
+ search: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
723
+ licensePlate: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
724
+ status: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
725
+ pagination: import("@sinclair/typebox").TObject<{
726
+ page: import("@sinclair/typebox").TInteger;
727
+ size: import("@sinclair/typebox").TInteger;
728
+ }>;
718
729
  }>;
719
730
  readonly "TechdocSupplierModel.select": import("@sinclair/typebox").TObject<{
720
731
  pagination: import("@sinclair/typebox").TObject<{
@@ -3598,6 +3609,33 @@ export declare const app: Elysia<"", {
3598
3609
  headers: unknown;
3599
3610
  response: {
3600
3611
  200: {
3612
+ company: Omit<{
3613
+ name: string;
3614
+ id: string;
3615
+ email: string;
3616
+ createdAt: string;
3617
+ updatedAt: string;
3618
+ deletedAt: string | null;
3619
+ regNumber: string;
3620
+ phone: string;
3621
+ serviceName: string;
3622
+ logoUrl: string;
3623
+ province: string | null;
3624
+ district: string | null;
3625
+ khoroo: string | null;
3626
+ street: string | null;
3627
+ socialUrls: string[] | null;
3628
+ ceoName: string | null;
3629
+ webUrl: string | null;
3630
+ googleMapUrl: string | null;
3631
+ isContract: boolean;
3632
+ isNoat: boolean;
3633
+ isNexus: boolean;
3634
+ isActive: boolean;
3635
+ branchCount: number;
3636
+ } & {
3637
+ totalCount: number;
3638
+ }, "totalCount">;
3601
3639
  id: string;
3602
3640
  name: string;
3603
3641
  emailVerified: boolean;
@@ -6348,6 +6386,64 @@ export declare const app: Elysia<"", {
6348
6386
  } & {
6349
6387
  crm: {
6350
6388
  inspection: {};
6389
+ } & {
6390
+ inspection: {
6391
+ get: {
6392
+ body: unknown;
6393
+ params: {};
6394
+ query: {
6395
+ search?: string | undefined;
6396
+ licensePlate?: string | undefined;
6397
+ status?: string | undefined;
6398
+ pagination: {
6399
+ size: number;
6400
+ page: number;
6401
+ };
6402
+ };
6403
+ headers: unknown;
6404
+ response: {
6405
+ 200: {
6406
+ totalCount: number;
6407
+ totalPage: number;
6408
+ result: {
6409
+ inspection: {
6410
+ companyId: string;
6411
+ branchId: string;
6412
+ vehicleId: string;
6413
+ inspection: {
6414
+ type: string;
6415
+ values: {
6416
+ description?: string | undefined;
6417
+ question: string;
6418
+ answer: string;
6419
+ };
6420
+ }[] | null;
6421
+ employeeId: string | null;
6422
+ expireAt: Date;
6423
+ experience: string | null;
6424
+ rank: string | null;
6425
+ licensePlate: string;
6426
+ description: string | null;
6427
+ status: "CREATED" | "APPROVED" | "CANCELLED";
6428
+ id: string;
6429
+ createdAt: string;
6430
+ updatedAt: string;
6431
+ deletedAt: string | null;
6432
+ };
6433
+ }[];
6434
+ };
6435
+ 422: {
6436
+ type: "validation";
6437
+ on: string;
6438
+ summary?: string;
6439
+ message?: string;
6440
+ found?: unknown;
6441
+ property?: string;
6442
+ expected?: string;
6443
+ };
6444
+ };
6445
+ };
6446
+ };
6351
6447
  } & {
6352
6448
  inspection: {
6353
6449
  post: {
@@ -6356,11 +6452,9 @@ export declare const app: Elysia<"", {
6356
6452
  description?: string | null | undefined;
6357
6453
  experience?: string | null | undefined;
6358
6454
  rank?: string | null | undefined;
6455
+ status?: "CREATED" | "APPROVED" | "CANCELLED" | undefined;
6359
6456
  inspection: {
6360
- description?: string | undefined;
6361
- isApproved?: boolean | undefined;
6362
6457
  type: string;
6363
- employeeId: string;
6364
6458
  values: {
6365
6459
  description?: string | undefined;
6366
6460
  question: string;
@@ -6384,10 +6478,7 @@ export declare const app: Elysia<"", {
6384
6478
  description: string | null;
6385
6479
  vehicleId: string;
6386
6480
  inspection: {
6387
- description?: string | undefined;
6388
- isApproved?: boolean | undefined;
6389
6481
  type: string;
6390
- employeeId: string;
6391
6482
  values: {
6392
6483
  description?: string | undefined;
6393
6484
  question: string;
@@ -6398,6 +6489,7 @@ export declare const app: Elysia<"", {
6398
6489
  experience: string | null;
6399
6490
  rank: string | null;
6400
6491
  licensePlate: string;
6492
+ status: "CREATED" | "APPROVED" | "CANCELLED";
6401
6493
  };
6402
6494
  502: string;
6403
6495
  400: "Машины дугаар болон VIN хоёроос нэгийг нь оруулна уу." | "Машины VIN оруулсан бол машины төрөл оруулна уу.";
@@ -6413,6 +6505,80 @@ export declare const app: Elysia<"", {
6413
6505
  };
6414
6506
  };
6415
6507
  };
6508
+ } & {
6509
+ inspection: {
6510
+ ":id": {
6511
+ get: {
6512
+ body: unknown;
6513
+ params: {
6514
+ id: string;
6515
+ };
6516
+ query: unknown;
6517
+ headers: unknown;
6518
+ response: {
6519
+ 200: {
6520
+ companyId: string;
6521
+ branchId: string;
6522
+ vehicleId: string;
6523
+ inspection: {
6524
+ type: string;
6525
+ values: {
6526
+ description?: string | undefined;
6527
+ question: string;
6528
+ answer: string;
6529
+ };
6530
+ }[] | null;
6531
+ employeeId: string | null;
6532
+ expireAt: Date;
6533
+ experience: string | null;
6534
+ rank: string | null;
6535
+ licensePlate: string;
6536
+ description: string | null;
6537
+ status: "CREATED" | "APPROVED" | "CANCELLED";
6538
+ id: string;
6539
+ createdAt: string;
6540
+ updatedAt: string;
6541
+ deletedAt: string | null;
6542
+ };
6543
+ 404: "Үзлэг олдсонгүй.";
6544
+ 422: {
6545
+ type: "validation";
6546
+ on: string;
6547
+ summary?: string;
6548
+ message?: string;
6549
+ found?: unknown;
6550
+ property?: string;
6551
+ expected?: string;
6552
+ };
6553
+ };
6554
+ };
6555
+ };
6556
+ };
6557
+ } & {
6558
+ inspection: {
6559
+ ":id": {
6560
+ post: {
6561
+ body: unknown;
6562
+ params: {
6563
+ id: string;
6564
+ };
6565
+ query: unknown;
6566
+ headers: unknown;
6567
+ response: {
6568
+ 200: void;
6569
+ 422: {
6570
+ type: "validation";
6571
+ on: string;
6572
+ summary?: string;
6573
+ message?: string;
6574
+ found?: unknown;
6575
+ property?: string;
6576
+ expected?: string;
6577
+ };
6578
+ };
6579
+ };
6580
+ };
6581
+ };
6416
6582
  } & {
6417
6583
  inspection: {
6418
6584
  ":id": {
package/dist/index.js CHANGED
@@ -137478,6 +137478,7 @@ __export(exports_schema, {
137478
137478
  crmPaymentTypeEnum: () => crmPaymentTypeEnum,
137479
137479
  crmPaymentTable: () => crmPaymentTable,
137480
137480
  crmInspectionTable: () => crmInspectionTable,
137481
+ crmInspectionStatusEnum: () => crmInspectionStatusEnum,
137481
137482
  crmDiscountTypeEnum: () => crmDiscountTypeEnum,
137482
137483
  crmDiscountTable: () => crmDiscountTable,
137483
137484
  crmDiscountStateEnum: () => crmDiscountStateEnum,
@@ -137886,6 +137887,11 @@ var crmDiscountApplyTable = crmSchema.table("discount_apply", {
137886
137887
  authUserId: text().notNull(),
137887
137888
  employeeId: uuid().notNull()
137888
137889
  });
137890
+ var crmInspectionStatusEnum = crmSchema.enum("inspection_status", [
137891
+ "CREATED",
137892
+ "APPROVED",
137893
+ "CANCELLED"
137894
+ ]);
137889
137895
  var crmInspectionTable = crmSchema.table("inspections", {
137890
137896
  ...base_schema_helper_default,
137891
137897
  companyId: uuid().notNull(),
@@ -137897,7 +137903,8 @@ var crmInspectionTable = crmSchema.table("inspections", {
137897
137903
  experience: varchar(),
137898
137904
  rank: varchar(),
137899
137905
  licensePlate: varchar().notNull(),
137900
- description: text()
137906
+ description: text(),
137907
+ status: crmInspectionStatusEnum("status").notNull().default("CREATED")
137901
137908
  });
137902
137909
  // src/lib/db/schema/techdoc.schema.ts
137903
137910
  var techdocSchema = pgSchema("techdoc");
@@ -141815,6 +141822,20 @@ var companySchemaRoutes = new Elysia({
141815
141822
  }).use(company_default).use(branch_default).use(_package_default).use(serviceKind_default).use(employee_default);
141816
141823
  var company_default2 = companySchemaRoutes;
141817
141824
 
141825
+ // src/lib/utils/dataStore.logic.ts
141826
+ var DataStoreLogic;
141827
+ ((DataStoreLogic) => {
141828
+ DataStoreLogic.create = async (body) => {
141829
+ const [result] = await db_default.insert(dataStoreTable).values(body).returning();
141830
+ return result;
141831
+ };
141832
+ DataStoreLogic.selectById = async (id) => {
141833
+ const [result] = await db_default.select().from(dataStoreTable).where(eq(dataStoreTable.id, id)).limit(1);
141834
+ return result;
141835
+ };
141836
+ })(DataStoreLogic ||= {});
141837
+ var dataStore_logic_default = DataStoreLogic;
141838
+
141818
141839
  // src/routes/warehouse/product/logic.ts
141819
141840
  var import_exceljs = __toESM(require_excel(), 1);
141820
141841
  var WarehouseProductLogic;
@@ -141935,20 +141956,6 @@ var WarehouseProductLogic;
141935
141956
  })(WarehouseProductLogic ||= {});
141936
141957
  var logic_default3 = WarehouseProductLogic;
141937
141958
 
141938
- // src/lib/utils/dataStore.logic.ts
141939
- var DataStoreLogic;
141940
- ((DataStoreLogic) => {
141941
- DataStoreLogic.create = async (body) => {
141942
- const [result] = await db_default.insert(dataStoreTable).values(body).returning();
141943
- return result;
141944
- };
141945
- DataStoreLogic.selectById = async (id) => {
141946
- const [result] = await db_default.select().from(dataStoreTable).where(eq(dataStoreTable.id, id)).limit(1);
141947
- return result;
141948
- };
141949
- })(DataStoreLogic ||= {});
141950
- var dataStore_logic_default = DataStoreLogic;
141951
-
141952
141959
  // src/routes/warehouse/item/logic.ts
141953
141960
  var WarehouseItemLogic;
141954
141961
  ((WarehouseItemLogic) => {
@@ -142321,36 +142328,6 @@ var CrmCpOrderItemLogic;
142321
142328
  })(CrmCpOrderItemLogic ||= {});
142322
142329
  var logic_default5 = CrmCpOrderItemLogic;
142323
142330
 
142324
- // src/routes/crm/cpOrder/item/model.ts
142325
- var CrmCpOrderItemModel;
142326
- ((CrmCpOrderItemModel) => {
142327
- const createSchema = createInsertSchema2(crmCpOrderItemTable);
142328
- const updateSchema = createUpdateSchema(crmCpOrderItemTable);
142329
- CrmCpOrderItemModel.create = t.Composite([
142330
- t.Pick(OmitBaseSchema(createSchema), [
142331
- "quantity",
142332
- "cpOrderId",
142333
- "companyServiceKindId",
142334
- "cpOrderSpPackageId",
142335
- "companyProductId",
142336
- "name"
142337
- ]),
142338
- t.Partial(t.Object({
142339
- priceUnit: t.Number()
142340
- }))
142341
- ]);
142342
- CrmCpOrderItemModel.update = t.Pick(OmitBaseSchema(updateSchema), [
142343
- "quantity",
142344
- "priceUnit",
142345
- "timeCompleted",
142346
- "state"
142347
- ]);
142348
- CrmCpOrderItemModel.select = t.Object({
142349
- cpOrderId: t.String({ format: "uuid" })
142350
- });
142351
- })(CrmCpOrderItemModel ||= {});
142352
- var model_default6 = CrmCpOrderItemModel;
142353
-
142354
142331
  // src/routes/crm/customer/logic.ts
142355
142332
  var CrmCustomerLogic;
142356
142333
  ((CrmCustomerLogic) => {
@@ -145855,6 +145832,36 @@ var DiscountLogic;
145855
145832
  })(DiscountLogic ||= {});
145856
145833
  var logic_default11 = DiscountLogic;
145857
145834
 
145835
+ // src/routes/crm/cpOrder/item/model.ts
145836
+ var CrmCpOrderItemModel;
145837
+ ((CrmCpOrderItemModel) => {
145838
+ const createSchema = createInsertSchema2(crmCpOrderItemTable);
145839
+ const updateSchema = createUpdateSchema(crmCpOrderItemTable);
145840
+ CrmCpOrderItemModel.create = t.Composite([
145841
+ t.Pick(OmitBaseSchema(createSchema), [
145842
+ "quantity",
145843
+ "cpOrderId",
145844
+ "companyServiceKindId",
145845
+ "cpOrderSpPackageId",
145846
+ "companyProductId",
145847
+ "name"
145848
+ ]),
145849
+ t.Partial(t.Object({
145850
+ priceUnit: t.Number()
145851
+ }))
145852
+ ]);
145853
+ CrmCpOrderItemModel.update = t.Pick(OmitBaseSchema(updateSchema), [
145854
+ "quantity",
145855
+ "priceUnit",
145856
+ "timeCompleted",
145857
+ "state"
145858
+ ]);
145859
+ CrmCpOrderItemModel.select = t.Object({
145860
+ cpOrderId: t.String({ format: "uuid" })
145861
+ });
145862
+ })(CrmCpOrderItemModel ||= {});
145863
+ var model_default6 = CrmCpOrderItemModel;
145864
+
145858
145865
  // src/routes/crm/cpOrder/item/index.ts
145859
145866
  var itemRoutes = new Elysia({
145860
145867
  prefix: "/item",
@@ -146205,6 +146212,140 @@ var discountRoutes = new Elysia({
146205
146212
  });
146206
146213
  var discount_default = discountRoutes;
146207
146214
 
146215
+ // src/routes/crm/inspection/logic.ts
146216
+ var CrmInspectionLogic;
146217
+ ((CrmInspectionLogic) => {
146218
+ CrmInspectionLogic.getFilter = (query, user2) => {
146219
+ const ilikeSearch = `%${query.search}%`;
146220
+ return and(softDeletedFilter(crmInspectionTable), eq(crmInspectionTable.companyId, user2.companyId), eq(crmInspectionTable.branchId, user2.branchId).if(user2.kind === "CUSTOMER"), or(ilike(crmInspectionTable.licensePlate, ilikeSearch), ilike(crmInspectionTable.description, ilikeSearch))?.if(!!query.search), eq(crmInspectionTable.status, query.status).if(query.status), ilike(crmInspectionTable.licensePlate, `%${query.licensePlate}%`).if(query.licensePlate));
146221
+ };
146222
+ CrmInspectionLogic.select = async (query, user2) => {
146223
+ const baseQuery = db_default.select({
146224
+ inspection: crmInspectionTable,
146225
+ totalCount: totalCountSql
146226
+ }).from(crmInspectionTable).where(CrmInspectionLogic.getFilter(query, user2)).orderBy(desc(crmInspectionTable.createdAt)).$dynamic();
146227
+ const result = await pagination_helper_default(baseQuery, query.pagination);
146228
+ const content = {
146229
+ totalCount: result[0]?.totalCount ?? 0,
146230
+ totalPage: result.length === 0 ? 0 : Math.ceil((result[0]?.totalCount ?? 0) / query.pagination.size)
146231
+ };
146232
+ return {
146233
+ result: result.map(({ totalCount, ...item }) => item),
146234
+ ...content
146235
+ };
146236
+ };
146237
+ CrmInspectionLogic.getById = async (id, user2) => {
146238
+ const [inspection] = await db_default.select().from(crmInspectionTable).where(and(eq(crmInspectionTable.id, id), eq(crmInspectionTable.companyId, user2.companyId), eq(crmInspectionTable.branchId, user2.branchId).if(user2.kind === "CUSTOMER"), softDeletedFilter(crmInspectionTable)));
146239
+ if (!inspection) {
146240
+ return status("Not Found", "\u04AE\u0437\u043B\u044D\u0433 \u043E\u043B\u0434\u0441\u043E\u043D\u0433\u04AF\u0439.");
146241
+ }
146242
+ return inspection;
146243
+ };
146244
+ CrmInspectionLogic.create = async (body, user2) => {
146245
+ const vehicle = await logic_default9.findOrCreate({
146246
+ licensePlate: body.licensePlate
146247
+ });
146248
+ if ("code" in vehicle) {
146249
+ return vehicle;
146250
+ }
146251
+ const [res] = await db_default.insert(crmInspectionTable).values({
146252
+ companyId: user2.companyId,
146253
+ branchId: user2.branchId,
146254
+ vehicleId: vehicle.id,
146255
+ employeeId: user2.employeeId,
146256
+ ...body
146257
+ }).returning();
146258
+ return res;
146259
+ };
146260
+ CrmInspectionLogic.createCpOrder = async (id, user2) => {
146261
+ const [inspection] = await db_default.select().from(crmInspectionTable).where(eq(crmInspectionTable.id, id));
146262
+ if (!inspection) {
146263
+ return status("Not Found", "\u04AE\u0437\u043B\u044D\u0433 \u043E\u043B\u0434\u0441\u043E\u043D\u0433\u04AF\u0439.");
146264
+ }
146265
+ const cpOrder = await logic_default12.create({
146266
+ licensePlate: inspection.licensePlate
146267
+ }, user2, db_default);
146268
+ if ("code" in cpOrder) {
146269
+ return cpOrder;
146270
+ }
146271
+ try {
146272
+ await db_default.transaction(async (db2) => {
146273
+ const serviceKind = await logic_default2.getInspection(user2, db2);
146274
+ await logic_default5.create({
146275
+ quantity: 1,
146276
+ cpOrderId: cpOrder.id,
146277
+ companyServiceKindId: serviceKind.id
146278
+ }, user2);
146279
+ });
146280
+ } catch (err2) {
146281
+ await logic_default12.hardRemove(cpOrder.id, user2);
146282
+ if (err2 instanceof Error) {
146283
+ return status("Bad Request", err2.message);
146284
+ }
146285
+ return status("Internal Server Error", "\u0410\u043B\u0434\u0430\u0430 \u0433\u0430\u0440\u043B\u0430\u0430. \u0414\u0430\u0445\u0438\u043D \u043E\u0440\u043E\u043B\u0434\u043E\u043D\u043E \u0443\u0443.");
146286
+ }
146287
+ return {
146288
+ cpOrderId: cpOrder.id
146289
+ };
146290
+ };
146291
+ CrmInspectionLogic.approve = async (id, user2) => {
146292
+ const [inspection] = await db_default.update(crmInspectionTable).set({
146293
+ status: "APPROVED"
146294
+ }).where(and(eq(crmInspectionTable.id, id), eq(crmInspectionTable.companyId, user2.companyId), eq(crmInspectionTable.branchId, user2.branchId).if(user2.kind === "CUSTOMER"))).returning();
146295
+ await distribution_default.post("https://driver-partner-api.dev.ubcabtech.com/v1/webhook/autosync/inspection", {
146296
+ json: inspection,
146297
+ retry: 3
146298
+ });
146299
+ };
146300
+ })(CrmInspectionLogic ||= {});
146301
+ var logic_default13 = CrmInspectionLogic;
146302
+
146303
+ // src/routes/crm/inspection/model.ts
146304
+ var CrmInspectionModel;
146305
+ ((CrmInspectionModel) => {
146306
+ const inspectionSchema = t.Object({
146307
+ type: t.String(),
146308
+ values: t.Object({
146309
+ question: t.String(),
146310
+ answer: t.String(),
146311
+ description: t.Optional(t.String())
146312
+ })
146313
+ });
146314
+ const createSchema = createInsertSchema(crmInspectionTable, {
146315
+ inspection: t.Array(inspectionSchema, {
146316
+ minItems: 1
146317
+ })
146318
+ });
146319
+ CrmInspectionModel.create = t.Omit(OmitBaseSchema(createSchema), [
146320
+ "expireAt",
146321
+ "companyId",
146322
+ "branchId",
146323
+ "vehicleId"
146324
+ ]);
146325
+ CrmInspectionModel.select = t.Composite([
146326
+ t.Partial(t.Object({
146327
+ search: t.String(),
146328
+ status: t.String(),
146329
+ licensePlate: t.String()
146330
+ })),
146331
+ PaginationSchema
146332
+ ]);
146333
+ })(CrmInspectionModel ||= {});
146334
+ var model_default11 = CrmInspectionModel;
146335
+
146336
+ // src/routes/crm/inspection/index.ts
146337
+ var inspectionRoutes = new Elysia({
146338
+ prefix: "/inspection",
146339
+ tags: ["CrmInspection"]
146340
+ }).use(better_auth_default).guard({ auth: true }).model(prefix_model_default("CrmInspectionModel", model_default11)).get("/", async ({ query, user: user2 }) => logic_default13.select(query, user2), {
146341
+ query: "CrmInspectionModel.select"
146342
+ }).post("/", async ({ body, user: user2 }) => logic_default13.create(body, user2), {
146343
+ body: "CrmInspectionModel.create"
146344
+ }).guard({
146345
+ params: IdSchema
146346
+ }).get("/:id", async ({ params: { id }, user: user2 }) => logic_default13.getById(id, user2)).post("/:id", async ({ params: { id }, user: user2 }) => logic_default13.approve(id, user2)).post("/:id/service-order", async ({ params: { id }, user: user2 }) => logic_default13.createCpOrder(id, user2));
146347
+ var inspection_default = inspectionRoutes;
146348
+
146208
146349
  // src/routes/crm/spPackage/model.ts
146209
146350
  var CrmSpPackageModel;
146210
146351
  ((CrmSpPackageModel) => {
@@ -146218,7 +146359,7 @@ var CrmSpPackageModel;
146218
146359
  t.Partial(t.Pick(selectSchema, ["name", "priceTotal", "companyBranchId"]))
146219
146360
  ]);
146220
146361
  })(CrmSpPackageModel ||= {});
146221
- var model_default11 = CrmSpPackageModel;
146362
+ var model_default12 = CrmSpPackageModel;
146222
146363
 
146223
146364
  // src/routes/crm/spPackage/product/logic.ts
146224
146365
  var CrmSpPackageProductLogic;
@@ -146264,7 +146405,7 @@ var CrmSpPackageProductLogic;
146264
146405
  }).where(eq(crmSpPackageProductTable.id, id));
146265
146406
  };
146266
146407
  })(CrmSpPackageProductLogic ||= {});
146267
- var logic_default13 = CrmSpPackageProductLogic;
146408
+ var logic_default14 = CrmSpPackageProductLogic;
146268
146409
 
146269
146410
  // src/routes/crm/spPackage/product/model.ts
146270
146411
  var CrmSpPackageProductModel;
@@ -146276,7 +146417,7 @@ var CrmSpPackageProductModel;
146276
146417
  CrmSpPackageProductModel.update = OmitBaseSchema(updateSchema);
146277
146418
  CrmSpPackageProductModel.select = t.Pick(selectSchema, ["spPackageId"]);
146278
146419
  })(CrmSpPackageProductModel ||= {});
146279
- var model_default12 = CrmSpPackageProductModel;
146420
+ var model_default13 = CrmSpPackageProductModel;
146280
146421
 
146281
146422
  // src/routes/crm/spPackage/product/index.ts
146282
146423
  var productRoutes = new Elysia({
@@ -146284,17 +146425,17 @@ var productRoutes = new Elysia({
146284
146425
  tags: ["CrmSpPackageProduct"]
146285
146426
  }).use(better_auth_default).guard({
146286
146427
  auth: true
146287
- }).model(prefix_model_default("CrmSpPackageProductModel", model_default12)).get("/", async ({ query }) => logic_default13.select(query), {
146428
+ }).model(prefix_model_default("CrmSpPackageProductModel", model_default13)).get("/", async ({ query }) => logic_default14.select(query), {
146288
146429
  query: "CrmSpPackageProductModel.select"
146289
- }).post("/", async ({ body }) => logic_default13.create(body), {
146430
+ }).post("/", async ({ body }) => logic_default14.create(body), {
146290
146431
  body: "CrmSpPackageProductModel.create"
146291
- }).post("/many", async ({ body }) => logic_default13.createMany(body), {
146432
+ }).post("/many", async ({ body }) => logic_default14.createMany(body), {
146292
146433
  body: "CrmSpPackageProductModel.create[]"
146293
146434
  }).guard({
146294
146435
  params: IdSchema
146295
- }).put("/:id", async ({ params, body }) => logic_default13.update(params.id, body), {
146436
+ }).put("/:id", async ({ params, body }) => logic_default14.update(params.id, body), {
146296
146437
  body: "CrmSpPackageProductModel.update"
146297
- }).delete("/:id", async ({ params }) => logic_default13.remove(params.id));
146438
+ }).delete("/:id", async ({ params }) => logic_default14.remove(params.id));
146298
146439
  var product_default = productRoutes;
146299
146440
 
146300
146441
  // src/routes/crm/spPackage/service/logic.ts
@@ -146337,7 +146478,7 @@ var CrmSpPackageServiceLogic;
146337
146478
  }).where(and(eq(crmSpPackageServiceTable.id, id)));
146338
146479
  };
146339
146480
  })(CrmSpPackageServiceLogic ||= {});
146340
- var logic_default14 = CrmSpPackageServiceLogic;
146481
+ var logic_default15 = CrmSpPackageServiceLogic;
146341
146482
 
146342
146483
  // src/routes/crm/spPackage/service/model.ts
146343
146484
  var CrmSpPackageServiceModel;
@@ -146349,7 +146490,7 @@ var CrmSpPackageServiceModel;
146349
146490
  CrmSpPackageServiceModel.update = OmitBaseSchema(updateSchema);
146350
146491
  CrmSpPackageServiceModel.select = t.Pick(selectSchema, ["spPackageId"]);
146351
146492
  })(CrmSpPackageServiceModel ||= {});
146352
- var model_default13 = CrmSpPackageServiceModel;
146493
+ var model_default14 = CrmSpPackageServiceModel;
146353
146494
 
146354
146495
  // src/routes/crm/spPackage/service/index.ts
146355
146496
  var serviceRoutes = new Elysia({
@@ -146357,17 +146498,17 @@ var serviceRoutes = new Elysia({
146357
146498
  tags: ["CrmSpPackageService"]
146358
146499
  }).use(better_auth_default).guard({
146359
146500
  auth: true
146360
- }).model(prefix_model_default("CrmSpPackageServiceModel", model_default13)).get("/", async ({ query }) => logic_default14.select(query), {
146501
+ }).model(prefix_model_default("CrmSpPackageServiceModel", model_default14)).get("/", async ({ query }) => logic_default15.select(query), {
146361
146502
  query: "CrmSpPackageServiceModel.select"
146362
- }).post("/", async ({ body }) => logic_default14.create(body), {
146503
+ }).post("/", async ({ body }) => logic_default15.create(body), {
146363
146504
  body: "CrmSpPackageServiceModel.create"
146364
- }).post("/many", async ({ body }) => logic_default14.createMany(body), {
146505
+ }).post("/many", async ({ body }) => logic_default15.createMany(body), {
146365
146506
  body: "CrmSpPackageServiceModel.create[]"
146366
146507
  }).guard({
146367
146508
  params: IdSchema
146368
- }).put("/:id", async ({ params, body }) => logic_default14.update(params.id, body), {
146509
+ }).put("/:id", async ({ params, body }) => logic_default15.update(params.id, body), {
146369
146510
  body: "CrmSpPackageServiceModel.update"
146370
- }).delete("/:id", async ({ params }) => logic_default14.remove(params.id));
146511
+ }).delete("/:id", async ({ params }) => logic_default15.remove(params.id));
146371
146512
  var service_default = serviceRoutes;
146372
146513
 
146373
146514
  // src/routes/crm/spPackage/index.ts
@@ -146376,7 +146517,7 @@ var spPackageRoutes = new Elysia({
146376
146517
  tags: ["CrmSpPackage"]
146377
146518
  }).use(better_auth_default).use(service_default).use(product_default).guard({
146378
146519
  auth: true
146379
- }).model(prefix_model_default("CrmSpPackageModel", model_default11)).get("/", async ({ query, user: user2 }) => logic_default7.select(query, user2), {
146520
+ }).model(prefix_model_default("CrmSpPackageModel", model_default12)).get("/", async ({ query, user: user2 }) => logic_default7.select(query, user2), {
146380
146521
  query: "CrmSpPackageModel.select"
146381
146522
  }).post("/", async ({ body, user: user2 }) => logic_default7.create(body, user2), {
146382
146523
  body: "CrmSpPackageModel.create"
@@ -146401,7 +146542,7 @@ var CrmVehicleModel;
146401
146542
  }))
146402
146543
  ]);
146403
146544
  })(CrmVehicleModel ||= {});
146404
- var model_default14 = CrmVehicleModel;
146545
+ var model_default15 = CrmVehicleModel;
146405
146546
 
146406
146547
  // src/routes/crm/vehicle/index.ts
146407
146548
  var vehicleRoutes = new Elysia({
@@ -146414,108 +146555,16 @@ var vehicleRoutes = new Elysia({
146414
146555
  auth: true,
146415
146556
  tags: ["Vehicle"]
146416
146557
  }).get("/", async ({ query, user: user2 }) => logic_default9.select(query, user2), {
146417
- query: model_default14.select
146558
+ query: model_default15.select
146418
146559
  }).post("/", async ({ body, user: user2 }) => logic_default9.create(body, user2), {
146419
- body: model_default14.create
146560
+ body: model_default15.create
146420
146561
  }).guard({
146421
146562
  params: IdSchema
146422
146563
  }).get("/:id", async ({ params, user: user2 }) => logic_default9.selectById(params.id, user2)).put("/:id", async ({ params, body, user: user2 }) => logic_default9.update(params.id, body, user2), {
146423
- body: model_default14.update
146564
+ body: model_default15.update
146424
146565
  }).delete("/:id", async ({ params, user: user2 }) => logic_default9.remove(params.id, user2)));
146425
146566
  var vehicle_default = vehicleRoutes;
146426
146567
 
146427
- // src/routes/crm/inspection/logic.ts
146428
- var CrmInspectionLogic;
146429
- ((CrmInspectionLogic) => {
146430
- CrmInspectionLogic.create = async (body, user2) => {
146431
- const vehicle = await logic_default9.findOrCreate({
146432
- licensePlate: body.licensePlate
146433
- });
146434
- if ("code" in vehicle) {
146435
- return vehicle;
146436
- }
146437
- const [res] = await db_default.insert(crmInspectionTable).values({
146438
- companyId: user2.companyId,
146439
- branchId: user2.branchId,
146440
- vehicleId: vehicle.id,
146441
- employeeId: user2.employeeId,
146442
- ...body
146443
- }).returning();
146444
- return res;
146445
- };
146446
- CrmInspectionLogic.createCpOrder = async (id, user2) => {
146447
- const [inspection] = await db_default.select().from(crmInspectionTable).where(eq(crmInspectionTable.id, id));
146448
- if (!inspection) {
146449
- return status("Not Found", "\u04AE\u0437\u043B\u044D\u0433 \u043E\u043B\u0434\u0441\u043E\u043D\u0433\u04AF\u0439.");
146450
- }
146451
- const cpOrder = await logic_default12.create({
146452
- licensePlate: inspection.licensePlate
146453
- }, user2, db_default);
146454
- if ("code" in cpOrder) {
146455
- return cpOrder;
146456
- }
146457
- try {
146458
- await db_default.transaction(async (db2) => {
146459
- const serviceKind = await logic_default2.getInspection(user2, db2);
146460
- await logic_default5.create({
146461
- quantity: 1,
146462
- cpOrderId: cpOrder.id,
146463
- companyServiceKindId: serviceKind.id
146464
- }, user2);
146465
- });
146466
- } catch (err2) {
146467
- await logic_default12.hardRemove(cpOrder.id, user2);
146468
- if (err2 instanceof Error) {
146469
- return status("Bad Request", err2.message);
146470
- }
146471
- return status("Internal Server Error", "\u0410\u043B\u0434\u0430\u0430 \u0433\u0430\u0440\u043B\u0430\u0430. \u0414\u0430\u0445\u0438\u043D \u043E\u0440\u043E\u043B\u0434\u043E\u043D\u043E \u0443\u0443.");
146472
- }
146473
- return {
146474
- cpOrderId: cpOrder.id
146475
- };
146476
- };
146477
- })(CrmInspectionLogic ||= {});
146478
- var logic_default15 = CrmInspectionLogic;
146479
-
146480
- // src/routes/crm/inspection/model.ts
146481
- var CrmInspectionModel;
146482
- ((CrmInspectionModel) => {
146483
- const inspectionSchema = t.Object({
146484
- type: t.String(),
146485
- values: t.Object({
146486
- question: t.String(),
146487
- answer: t.String(),
146488
- description: t.Optional(t.String())
146489
- }),
146490
- employeeId: t.String({ format: "uuid" }),
146491
- description: t.Optional(t.String()),
146492
- isApproved: t.Optional(t.Boolean())
146493
- });
146494
- const createSchema = createInsertSchema(crmInspectionTable, {
146495
- inspection: t.Array(inspectionSchema, {
146496
- minItems: 1
146497
- })
146498
- });
146499
- CrmInspectionModel.create = t.Omit(OmitBaseSchema(createSchema), [
146500
- "expireAt",
146501
- "companyId",
146502
- "branchId",
146503
- "vehicleId"
146504
- ]);
146505
- })(CrmInspectionModel ||= {});
146506
- var model_default15 = CrmInspectionModel;
146507
-
146508
- // src/routes/crm/inspection/index.ts
146509
- var inspectionRoutes = new Elysia({
146510
- prefix: "/inspection",
146511
- tags: ["CrmInspection"]
146512
- }).use(better_auth_default).guard({ auth: true }).model(prefix_model_default("CrmInspectionModel", model_default15)).post("/", async ({ body, user: user2 }) => logic_default15.create(body, user2), {
146513
- body: "CrmInspectionModel.create"
146514
- }).post("/:id/service-order", async ({ params: { id }, user: user2 }) => logic_default15.createCpOrder(id, user2), {
146515
- params: IdSchema
146516
- });
146517
- var inspection_default = inspectionRoutes;
146518
-
146519
146568
  // src/routes/crm/index.ts
146520
146569
  var crmSchemaRoutes = new Elysia({
146521
146570
  prefix: "/crm"
@@ -147060,8 +147109,7 @@ var $generate = function(options) {
147060
147109
  var UserLogic;
147061
147110
  ((UserLogic) => {
147062
147111
  UserLogic.select = async (query, user2) => {
147063
- const isAdmin = user2.kind === "ADMIN";
147064
- const filter = and(eq(user.branchId, query.branchId ?? "").if(query.branchId && isAdmin), eq(user.branchId, user2.branchId).if(!isAdmin), eq(user.companyId, user2.companyId).if(!isAdmin));
147112
+ const filter = and(eq(user.branchId, query.branchId ?? "").if(query.branchId && user2.kind !== "CUSTOMER"), eq(user.branchId, user2.branchId).if(user2.kind === "CUSTOMER"), eq(user.companyId, user2.companyId).if(user2.kind !== "ADMIN"));
147065
147113
  const columns = getTableColumns(user);
147066
147114
  const baseQuery = db_default.select({
147067
147115
  ...columns,
@@ -147088,13 +147136,11 @@ var UserLogic;
147088
147136
  let branchId = user2.branchId;
147089
147137
  let companyId = user2.companyId;
147090
147138
  const isAdmin = user2.kind === "ADMIN";
147091
- if (isAdmin) {
147092
- if (body.merchantId) {
147093
- companyId = body.merchantId;
147094
- }
147095
- if (body.branchId) {
147096
- branchId = body.branchId;
147097
- }
147139
+ if (isAdmin && body.merchantId) {
147140
+ companyId = body.merchantId;
147141
+ }
147142
+ if ((isAdmin || user2.kind === "COMPANY_ADMIN") && body.branchId) {
147143
+ branchId = body.branchId;
147098
147144
  }
147099
147145
  try {
147100
147146
  const result = await auth2.api.signUpEmail({
@@ -147164,7 +147210,16 @@ var userRoutes = new Elysia({
147164
147210
  }).get("/", async ({ query, user: user2 }) => logic_default18.select(query, user2), {
147165
147211
  query: selectUserSchema,
147166
147212
  userKind: "COMPANY_ADMIN"
147167
- }).get("/me", async ({ user: user2 }) => user2).post("/", async ({ body, user: user2 }) => logic_default18.registerUser(body, user2), {
147213
+ }).get("/me", async ({ user: user2 }) => {
147214
+ const company2 = await service2.get({
147215
+ id: user2.companyId,
147216
+ pagination: { size: 1, page: 1 }
147217
+ });
147218
+ return {
147219
+ ...user2,
147220
+ company: company2.result[0]
147221
+ };
147222
+ }).post("/", async ({ body, user: user2 }) => logic_default18.registerUser(body, user2), {
147168
147223
  body: createUserSchema,
147169
147224
  userKind: "COMPANY_ADMIN"
147170
147225
  }).put("/:id", async ({ body, user: user2, params: { id } }) => logic_default18.update(id, body, user2), {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autosync_backend2",
3
- "version": "1.1.52",
3
+ "version": "1.1.54",
4
4
  "module": "src/index.ts",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",