autosync_backend2 1.1.52 → 1.1.53

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 +209 -3
  2. package/dist/index.js +227 -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>;
@@ -715,6 +715,20 @@ export declare const app: Elysia<"", {
715
715
  experience: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>>;
716
716
  rank: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>>;
717
717
  licensePlate: import("@sinclair/typebox").TString;
718
+ status: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TEnum<{
719
+ CREATED: "CREATED";
720
+ APPROVED: "APPROVED";
721
+ CANCELLED: "CANCELLED";
722
+ }>>;
723
+ }>;
724
+ readonly "CrmInspectionModel.select": import("@sinclair/typebox").TObject<{
725
+ search: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
726
+ licensePlate: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
727
+ status: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
728
+ pagination: import("@sinclair/typebox").TObject<{
729
+ page: import("@sinclair/typebox").TInteger;
730
+ size: import("@sinclair/typebox").TInteger;
731
+ }>;
718
732
  }>;
719
733
  readonly "TechdocSupplierModel.select": import("@sinclair/typebox").TObject<{
720
734
  pagination: import("@sinclair/typebox").TObject<{
@@ -3598,6 +3612,33 @@ export declare const app: Elysia<"", {
3598
3612
  headers: unknown;
3599
3613
  response: {
3600
3614
  200: {
3615
+ company: Omit<{
3616
+ name: string;
3617
+ id: string;
3618
+ email: string;
3619
+ createdAt: string;
3620
+ updatedAt: string;
3621
+ deletedAt: string | null;
3622
+ regNumber: string;
3623
+ phone: string;
3624
+ serviceName: string;
3625
+ logoUrl: string;
3626
+ province: string | null;
3627
+ district: string | null;
3628
+ khoroo: string | null;
3629
+ street: string | null;
3630
+ socialUrls: string[] | null;
3631
+ ceoName: string | null;
3632
+ webUrl: string | null;
3633
+ googleMapUrl: string | null;
3634
+ isContract: boolean;
3635
+ isNoat: boolean;
3636
+ isNexus: boolean;
3637
+ isActive: boolean;
3638
+ branchCount: number;
3639
+ } & {
3640
+ totalCount: number;
3641
+ }, "totalCount">;
3601
3642
  id: string;
3602
3643
  name: string;
3603
3644
  emailVerified: boolean;
@@ -6348,6 +6389,169 @@ export declare const app: Elysia<"", {
6348
6389
  } & {
6349
6390
  crm: {
6350
6391
  inspection: {};
6392
+ } & {
6393
+ inspection: {
6394
+ get: {
6395
+ body: unknown;
6396
+ params: {};
6397
+ query: {
6398
+ search?: string | undefined;
6399
+ licensePlate?: string | undefined;
6400
+ status?: string | undefined;
6401
+ pagination: {
6402
+ size: number;
6403
+ page: number;
6404
+ };
6405
+ };
6406
+ headers: unknown;
6407
+ response: {
6408
+ 200: {
6409
+ totalCount: number;
6410
+ totalPage: number;
6411
+ result: {
6412
+ inspection: {
6413
+ companyId: string;
6414
+ branchId: string;
6415
+ vehicleId: string;
6416
+ inspection: {
6417
+ description?: string | undefined;
6418
+ isApproved?: boolean | undefined;
6419
+ type: string;
6420
+ employeeId: string;
6421
+ values: {
6422
+ description?: string | undefined;
6423
+ question: string;
6424
+ answer: string;
6425
+ };
6426
+ }[] | null;
6427
+ employeeId: string | null;
6428
+ expireAt: Date;
6429
+ experience: string | null;
6430
+ rank: string | null;
6431
+ licensePlate: string;
6432
+ description: string | null;
6433
+ status: "CREATED" | "APPROVED" | "CANCELLED";
6434
+ id: string;
6435
+ createdAt: string;
6436
+ updatedAt: string;
6437
+ deletedAt: string | null;
6438
+ };
6439
+ vehicle: {
6440
+ customerId: string | null;
6441
+ vehicleKindId: string;
6442
+ vin: string | null;
6443
+ licensePlate: string | null;
6444
+ color: string | null;
6445
+ engineCc: string | null;
6446
+ cylinder: string | null;
6447
+ gasType: string | null;
6448
+ transmissionType: string | null;
6449
+ vehicleType: string | null;
6450
+ yearManufacture: number | null;
6451
+ yearImport: number | null;
6452
+ steering: string | null;
6453
+ engineCode: string | null;
6454
+ transmissionCode: string | null;
6455
+ driveTrain: string | null;
6456
+ km: number;
6457
+ companyId: string | null;
6458
+ id: string;
6459
+ createdAt: string;
6460
+ updatedAt: string;
6461
+ deletedAt: string | null;
6462
+ } | null;
6463
+ }[];
6464
+ };
6465
+ 422: {
6466
+ type: "validation";
6467
+ on: string;
6468
+ summary?: string;
6469
+ message?: string;
6470
+ found?: unknown;
6471
+ property?: string;
6472
+ expected?: string;
6473
+ };
6474
+ };
6475
+ };
6476
+ };
6477
+ } & {
6478
+ inspection: {
6479
+ ":id": {
6480
+ get: {
6481
+ body: unknown;
6482
+ params: {
6483
+ id: string;
6484
+ };
6485
+ query: unknown;
6486
+ headers: unknown;
6487
+ response: {
6488
+ 200: {
6489
+ inspection: {
6490
+ companyId: string;
6491
+ branchId: string;
6492
+ vehicleId: string;
6493
+ inspection: {
6494
+ description?: string | undefined;
6495
+ isApproved?: boolean | undefined;
6496
+ type: string;
6497
+ employeeId: string;
6498
+ values: {
6499
+ description?: string | undefined;
6500
+ question: string;
6501
+ answer: string;
6502
+ };
6503
+ }[] | null;
6504
+ employeeId: string | null;
6505
+ expireAt: Date;
6506
+ experience: string | null;
6507
+ rank: string | null;
6508
+ licensePlate: string;
6509
+ description: string | null;
6510
+ status: "CREATED" | "APPROVED" | "CANCELLED";
6511
+ id: string;
6512
+ createdAt: string;
6513
+ updatedAt: string;
6514
+ deletedAt: string | null;
6515
+ };
6516
+ vehicle: {
6517
+ customerId: string | null;
6518
+ vehicleKindId: string;
6519
+ vin: string | null;
6520
+ licensePlate: string | null;
6521
+ color: string | null;
6522
+ engineCc: string | null;
6523
+ cylinder: string | null;
6524
+ gasType: string | null;
6525
+ transmissionType: string | null;
6526
+ vehicleType: string | null;
6527
+ yearManufacture: number | null;
6528
+ yearImport: number | null;
6529
+ steering: string | null;
6530
+ engineCode: string | null;
6531
+ transmissionCode: string | null;
6532
+ driveTrain: string | null;
6533
+ km: number;
6534
+ companyId: string | null;
6535
+ id: string;
6536
+ createdAt: string;
6537
+ updatedAt: string;
6538
+ deletedAt: string | null;
6539
+ } | null;
6540
+ };
6541
+ 404: "Үзлэг олдсонгүй.";
6542
+ 422: {
6543
+ type: "validation";
6544
+ on: string;
6545
+ summary?: string;
6546
+ message?: string;
6547
+ found?: unknown;
6548
+ property?: string;
6549
+ expected?: string;
6550
+ };
6551
+ };
6552
+ };
6553
+ };
6554
+ };
6351
6555
  } & {
6352
6556
  inspection: {
6353
6557
  post: {
@@ -6356,6 +6560,7 @@ export declare const app: Elysia<"", {
6356
6560
  description?: string | null | undefined;
6357
6561
  experience?: string | null | undefined;
6358
6562
  rank?: string | null | undefined;
6563
+ status?: "CREATED" | "APPROVED" | "CANCELLED" | undefined;
6359
6564
  inspection: {
6360
6565
  description?: string | undefined;
6361
6566
  isApproved?: boolean | undefined;
@@ -6398,6 +6603,7 @@ export declare const app: Elysia<"", {
6398
6603
  experience: string | null;
6399
6604
  rank: string | null;
6400
6605
  licensePlate: string;
6606
+ status: "CREATED" | "APPROVED" | "CANCELLED";
6401
6607
  };
6402
6608
  502: string;
6403
6609
  400: "Машины дугаар болон VIN хоёроос нэгийг нь оруулна уу." | "Машины VIN оруулсан бол машины төрөл оруулна уу.";
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,145 @@ 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
+ vehicle: crmVehicleTable,
146226
+ totalCount: totalCountSql
146227
+ }).from(crmInspectionTable).leftJoin(crmVehicleTable, eq(crmVehicleTable.id, crmInspectionTable.vehicleId)).where(CrmInspectionLogic.getFilter(query, user2)).orderBy(desc(crmInspectionTable.createdAt)).$dynamic();
146228
+ const result = await pagination_helper_default(baseQuery, query.pagination);
146229
+ const content = {
146230
+ totalCount: result[0]?.totalCount ?? 0,
146231
+ totalPage: result.length === 0 ? 0 : Math.ceil((result[0]?.totalCount ?? 0) / query.pagination.size)
146232
+ };
146233
+ return {
146234
+ result: result.map(({ totalCount, ...item }) => item),
146235
+ ...content
146236
+ };
146237
+ };
146238
+ CrmInspectionLogic.getById = async (id, user2) => {
146239
+ const [inspection] = await db_default.select({
146240
+ inspection: crmInspectionTable,
146241
+ vehicle: crmVehicleTable
146242
+ }).from(crmInspectionTable).leftJoin(crmVehicleTable, eq(crmVehicleTable.id, crmInspectionTable.vehicleId)).where(and(eq(crmInspectionTable.id, id), eq(crmInspectionTable.companyId, user2.companyId), eq(crmInspectionTable.branchId, user2.branchId).if(user2.kind === "CUSTOMER"), softDeletedFilter(crmInspectionTable)));
146243
+ if (!inspection) {
146244
+ return status("Not Found", "\u04AE\u0437\u043B\u044D\u0433 \u043E\u043B\u0434\u0441\u043E\u043D\u0433\u04AF\u0439.");
146245
+ }
146246
+ return inspection;
146247
+ };
146248
+ CrmInspectionLogic.create = async (body, user2) => {
146249
+ const vehicle = await logic_default9.findOrCreate({
146250
+ licensePlate: body.licensePlate
146251
+ });
146252
+ if ("code" in vehicle) {
146253
+ return vehicle;
146254
+ }
146255
+ const [res] = await db_default.insert(crmInspectionTable).values({
146256
+ companyId: user2.companyId,
146257
+ branchId: user2.branchId,
146258
+ vehicleId: vehicle.id,
146259
+ employeeId: user2.employeeId,
146260
+ ...body
146261
+ }).returning();
146262
+ return res;
146263
+ };
146264
+ CrmInspectionLogic.createCpOrder = async (id, user2) => {
146265
+ const [inspection] = await db_default.select().from(crmInspectionTable).where(eq(crmInspectionTable.id, id));
146266
+ if (!inspection) {
146267
+ return status("Not Found", "\u04AE\u0437\u043B\u044D\u0433 \u043E\u043B\u0434\u0441\u043E\u043D\u0433\u04AF\u0439.");
146268
+ }
146269
+ const cpOrder = await logic_default12.create({
146270
+ licensePlate: inspection.licensePlate
146271
+ }, user2, db_default);
146272
+ if ("code" in cpOrder) {
146273
+ return cpOrder;
146274
+ }
146275
+ try {
146276
+ await db_default.transaction(async (db2) => {
146277
+ const serviceKind = await logic_default2.getInspection(user2, db2);
146278
+ await logic_default5.create({
146279
+ quantity: 1,
146280
+ cpOrderId: cpOrder.id,
146281
+ companyServiceKindId: serviceKind.id
146282
+ }, user2);
146283
+ });
146284
+ } catch (err2) {
146285
+ await logic_default12.hardRemove(cpOrder.id, user2);
146286
+ if (err2 instanceof Error) {
146287
+ return status("Bad Request", err2.message);
146288
+ }
146289
+ 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.");
146290
+ }
146291
+ return {
146292
+ cpOrderId: cpOrder.id
146293
+ };
146294
+ };
146295
+ CrmInspectionLogic.approve = async (id, user2) => {
146296
+ await db_default.update(crmInspectionTable).set({
146297
+ status: "APPROVED"
146298
+ }).where(and(eq(crmInspectionTable.id, id), eq(crmInspectionTable.companyId, user2.companyId), eq(crmInspectionTable.branchId, user2.branchId).if(user2.kind === "CUSTOMER")));
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
+ employeeId: t.String({ format: "uuid" }),
146314
+ description: t.Optional(t.String()),
146315
+ isApproved: t.Optional(t.Boolean())
146316
+ });
146317
+ const createSchema = createInsertSchema(crmInspectionTable, {
146318
+ inspection: t.Array(inspectionSchema, {
146319
+ minItems: 1
146320
+ })
146321
+ });
146322
+ CrmInspectionModel.create = t.Omit(OmitBaseSchema(createSchema), [
146323
+ "expireAt",
146324
+ "companyId",
146325
+ "branchId",
146326
+ "vehicleId"
146327
+ ]);
146328
+ CrmInspectionModel.select = t.Composite([
146329
+ t.Partial(t.Object({
146330
+ search: t.String(),
146331
+ status: t.String(),
146332
+ licensePlate: t.String()
146333
+ })),
146334
+ PaginationSchema
146335
+ ]);
146336
+ })(CrmInspectionModel ||= {});
146337
+ var model_default11 = CrmInspectionModel;
146338
+
146339
+ // src/routes/crm/inspection/index.ts
146340
+ var inspectionRoutes = new Elysia({
146341
+ prefix: "/inspection",
146342
+ tags: ["CrmInspection"]
146343
+ }).use(better_auth_default).guard({ auth: true }).model(prefix_model_default("CrmInspectionModel", model_default11)).get("/", async ({ query, user: user2 }) => logic_default13.select(query, user2), {
146344
+ query: "CrmInspectionModel.select"
146345
+ }).get("/:id", async ({ params: { id }, user: user2 }) => logic_default13.getById(id, user2), {
146346
+ params: IdSchema
146347
+ }).post("/", async ({ body, user: user2 }) => logic_default13.create(body, user2), {
146348
+ body: "CrmInspectionModel.create"
146349
+ }).post("/:id/service-order", async ({ params: { id }, user: user2 }) => logic_default13.createCpOrder(id, user2), {
146350
+ params: IdSchema
146351
+ });
146352
+ var inspection_default = inspectionRoutes;
146353
+
146208
146354
  // src/routes/crm/spPackage/model.ts
146209
146355
  var CrmSpPackageModel;
146210
146356
  ((CrmSpPackageModel) => {
@@ -146218,7 +146364,7 @@ var CrmSpPackageModel;
146218
146364
  t.Partial(t.Pick(selectSchema, ["name", "priceTotal", "companyBranchId"]))
146219
146365
  ]);
146220
146366
  })(CrmSpPackageModel ||= {});
146221
- var model_default11 = CrmSpPackageModel;
146367
+ var model_default12 = CrmSpPackageModel;
146222
146368
 
146223
146369
  // src/routes/crm/spPackage/product/logic.ts
146224
146370
  var CrmSpPackageProductLogic;
@@ -146264,7 +146410,7 @@ var CrmSpPackageProductLogic;
146264
146410
  }).where(eq(crmSpPackageProductTable.id, id));
146265
146411
  };
146266
146412
  })(CrmSpPackageProductLogic ||= {});
146267
- var logic_default13 = CrmSpPackageProductLogic;
146413
+ var logic_default14 = CrmSpPackageProductLogic;
146268
146414
 
146269
146415
  // src/routes/crm/spPackage/product/model.ts
146270
146416
  var CrmSpPackageProductModel;
@@ -146276,7 +146422,7 @@ var CrmSpPackageProductModel;
146276
146422
  CrmSpPackageProductModel.update = OmitBaseSchema(updateSchema);
146277
146423
  CrmSpPackageProductModel.select = t.Pick(selectSchema, ["spPackageId"]);
146278
146424
  })(CrmSpPackageProductModel ||= {});
146279
- var model_default12 = CrmSpPackageProductModel;
146425
+ var model_default13 = CrmSpPackageProductModel;
146280
146426
 
146281
146427
  // src/routes/crm/spPackage/product/index.ts
146282
146428
  var productRoutes = new Elysia({
@@ -146284,17 +146430,17 @@ var productRoutes = new Elysia({
146284
146430
  tags: ["CrmSpPackageProduct"]
146285
146431
  }).use(better_auth_default).guard({
146286
146432
  auth: true
146287
- }).model(prefix_model_default("CrmSpPackageProductModel", model_default12)).get("/", async ({ query }) => logic_default13.select(query), {
146433
+ }).model(prefix_model_default("CrmSpPackageProductModel", model_default13)).get("/", async ({ query }) => logic_default14.select(query), {
146288
146434
  query: "CrmSpPackageProductModel.select"
146289
- }).post("/", async ({ body }) => logic_default13.create(body), {
146435
+ }).post("/", async ({ body }) => logic_default14.create(body), {
146290
146436
  body: "CrmSpPackageProductModel.create"
146291
- }).post("/many", async ({ body }) => logic_default13.createMany(body), {
146437
+ }).post("/many", async ({ body }) => logic_default14.createMany(body), {
146292
146438
  body: "CrmSpPackageProductModel.create[]"
146293
146439
  }).guard({
146294
146440
  params: IdSchema
146295
- }).put("/:id", async ({ params, body }) => logic_default13.update(params.id, body), {
146441
+ }).put("/:id", async ({ params, body }) => logic_default14.update(params.id, body), {
146296
146442
  body: "CrmSpPackageProductModel.update"
146297
- }).delete("/:id", async ({ params }) => logic_default13.remove(params.id));
146443
+ }).delete("/:id", async ({ params }) => logic_default14.remove(params.id));
146298
146444
  var product_default = productRoutes;
146299
146445
 
146300
146446
  // src/routes/crm/spPackage/service/logic.ts
@@ -146337,7 +146483,7 @@ var CrmSpPackageServiceLogic;
146337
146483
  }).where(and(eq(crmSpPackageServiceTable.id, id)));
146338
146484
  };
146339
146485
  })(CrmSpPackageServiceLogic ||= {});
146340
- var logic_default14 = CrmSpPackageServiceLogic;
146486
+ var logic_default15 = CrmSpPackageServiceLogic;
146341
146487
 
146342
146488
  // src/routes/crm/spPackage/service/model.ts
146343
146489
  var CrmSpPackageServiceModel;
@@ -146349,7 +146495,7 @@ var CrmSpPackageServiceModel;
146349
146495
  CrmSpPackageServiceModel.update = OmitBaseSchema(updateSchema);
146350
146496
  CrmSpPackageServiceModel.select = t.Pick(selectSchema, ["spPackageId"]);
146351
146497
  })(CrmSpPackageServiceModel ||= {});
146352
- var model_default13 = CrmSpPackageServiceModel;
146498
+ var model_default14 = CrmSpPackageServiceModel;
146353
146499
 
146354
146500
  // src/routes/crm/spPackage/service/index.ts
146355
146501
  var serviceRoutes = new Elysia({
@@ -146357,17 +146503,17 @@ var serviceRoutes = new Elysia({
146357
146503
  tags: ["CrmSpPackageService"]
146358
146504
  }).use(better_auth_default).guard({
146359
146505
  auth: true
146360
- }).model(prefix_model_default("CrmSpPackageServiceModel", model_default13)).get("/", async ({ query }) => logic_default14.select(query), {
146506
+ }).model(prefix_model_default("CrmSpPackageServiceModel", model_default14)).get("/", async ({ query }) => logic_default15.select(query), {
146361
146507
  query: "CrmSpPackageServiceModel.select"
146362
- }).post("/", async ({ body }) => logic_default14.create(body), {
146508
+ }).post("/", async ({ body }) => logic_default15.create(body), {
146363
146509
  body: "CrmSpPackageServiceModel.create"
146364
- }).post("/many", async ({ body }) => logic_default14.createMany(body), {
146510
+ }).post("/many", async ({ body }) => logic_default15.createMany(body), {
146365
146511
  body: "CrmSpPackageServiceModel.create[]"
146366
146512
  }).guard({
146367
146513
  params: IdSchema
146368
- }).put("/:id", async ({ params, body }) => logic_default14.update(params.id, body), {
146514
+ }).put("/:id", async ({ params, body }) => logic_default15.update(params.id, body), {
146369
146515
  body: "CrmSpPackageServiceModel.update"
146370
- }).delete("/:id", async ({ params }) => logic_default14.remove(params.id));
146516
+ }).delete("/:id", async ({ params }) => logic_default15.remove(params.id));
146371
146517
  var service_default = serviceRoutes;
146372
146518
 
146373
146519
  // src/routes/crm/spPackage/index.ts
@@ -146376,7 +146522,7 @@ var spPackageRoutes = new Elysia({
146376
146522
  tags: ["CrmSpPackage"]
146377
146523
  }).use(better_auth_default).use(service_default).use(product_default).guard({
146378
146524
  auth: true
146379
- }).model(prefix_model_default("CrmSpPackageModel", model_default11)).get("/", async ({ query, user: user2 }) => logic_default7.select(query, user2), {
146525
+ }).model(prefix_model_default("CrmSpPackageModel", model_default12)).get("/", async ({ query, user: user2 }) => logic_default7.select(query, user2), {
146380
146526
  query: "CrmSpPackageModel.select"
146381
146527
  }).post("/", async ({ body, user: user2 }) => logic_default7.create(body, user2), {
146382
146528
  body: "CrmSpPackageModel.create"
@@ -146401,7 +146547,7 @@ var CrmVehicleModel;
146401
146547
  }))
146402
146548
  ]);
146403
146549
  })(CrmVehicleModel ||= {});
146404
- var model_default14 = CrmVehicleModel;
146550
+ var model_default15 = CrmVehicleModel;
146405
146551
 
146406
146552
  // src/routes/crm/vehicle/index.ts
146407
146553
  var vehicleRoutes = new Elysia({
@@ -146414,108 +146560,16 @@ var vehicleRoutes = new Elysia({
146414
146560
  auth: true,
146415
146561
  tags: ["Vehicle"]
146416
146562
  }).get("/", async ({ query, user: user2 }) => logic_default9.select(query, user2), {
146417
- query: model_default14.select
146563
+ query: model_default15.select
146418
146564
  }).post("/", async ({ body, user: user2 }) => logic_default9.create(body, user2), {
146419
- body: model_default14.create
146565
+ body: model_default15.create
146420
146566
  }).guard({
146421
146567
  params: IdSchema
146422
146568
  }).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
146569
+ body: model_default15.update
146424
146570
  }).delete("/:id", async ({ params, user: user2 }) => logic_default9.remove(params.id, user2)));
146425
146571
  var vehicle_default = vehicleRoutes;
146426
146572
 
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
146573
  // src/routes/crm/index.ts
146520
146574
  var crmSchemaRoutes = new Elysia({
146521
146575
  prefix: "/crm"
@@ -147060,8 +147114,7 @@ var $generate = function(options) {
147060
147114
  var UserLogic;
147061
147115
  ((UserLogic) => {
147062
147116
  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));
147117
+ 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
147118
  const columns = getTableColumns(user);
147066
147119
  const baseQuery = db_default.select({
147067
147120
  ...columns,
@@ -147088,13 +147141,11 @@ var UserLogic;
147088
147141
  let branchId = user2.branchId;
147089
147142
  let companyId = user2.companyId;
147090
147143
  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
- }
147144
+ if (isAdmin && body.merchantId) {
147145
+ companyId = body.merchantId;
147146
+ }
147147
+ if ((isAdmin || user2.kind === "COMPANY_ADMIN") && body.branchId) {
147148
+ branchId = body.branchId;
147098
147149
  }
147099
147150
  try {
147100
147151
  const result = await auth2.api.signUpEmail({
@@ -147164,7 +147215,16 @@ var userRoutes = new Elysia({
147164
147215
  }).get("/", async ({ query, user: user2 }) => logic_default18.select(query, user2), {
147165
147216
  query: selectUserSchema,
147166
147217
  userKind: "COMPANY_ADMIN"
147167
- }).get("/me", async ({ user: user2 }) => user2).post("/", async ({ body, user: user2 }) => logic_default18.registerUser(body, user2), {
147218
+ }).get("/me", async ({ user: user2 }) => {
147219
+ const company2 = await service2.get({
147220
+ id: user2.companyId,
147221
+ pagination: { size: 1, page: 1 }
147222
+ });
147223
+ return {
147224
+ ...user2,
147225
+ company: company2.result[0]
147226
+ };
147227
+ }).post("/", async ({ body, user: user2 }) => logic_default18.registerUser(body, user2), {
147168
147228
  body: createUserSchema,
147169
147229
  userKind: "COMPANY_ADMIN"
147170
147230
  }).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.53",
4
4
  "module": "src/index.ts",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",