autosync_backend2 1.2.56 → 1.2.57

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
@@ -10687,22 +10687,17 @@ export declare const app: Elysia<"", {
10687
10687
  plan: {
10688
10688
  post: {
10689
10689
  body: {
10690
- oldId?: number | null | undefined;
10691
- description?: string | null | undefined;
10692
- dateStart?: Date | null | undefined;
10693
- dateEnd?: Date | null | undefined;
10694
- name: string;
10695
- companyId: string;
10690
+ machineId: string;
10691
+ pmTemplateId: string;
10696
10692
  };
10697
10693
  params: {};
10698
10694
  query: unknown;
10699
10695
  headers: unknown;
10700
10696
  response: {
10701
- 200: {
10702
- id: string;
10703
- };
10697
+ 400: "Ажилтны мэдээлэл шаардлагатай." | "Машины төрөл хэрэглэгчийн машин төрөлтэй тэнцүү байхгүй.";
10704
10698
  401: "Токен олдсонгүй";
10705
10699
  403: "Хандах эрхгүй байна.";
10700
+ 404: "Pm Template олдсонгүй." | "Машин олдсонгүй.";
10706
10701
  422: {
10707
10702
  type: "validation";
10708
10703
  on: string;
package/dist/index.js CHANGED
@@ -143446,7 +143446,7 @@ var pmPlanMachineTable = pmSchema.table("plan_machine", {
143446
143446
  pmTemplateId: uuid5().notNull(),
143447
143447
  machineId: uuid5().notNull(),
143448
143448
  employeeCreatedId: uuid5().notNull(),
143449
- userCreatedId: uuid5().notNull(),
143449
+ userCreatedId: text().notNull(),
143450
143450
  note: text()
143451
143451
  });
143452
143452
  var pmPlanProductTable = pmSchema.table("plan_product", {
@@ -155680,13 +155680,48 @@ var PmPlanLogic;
155680
155680
  return getPaginationContent(result, query.pagination.size);
155681
155681
  };
155682
155682
  PmPlanLogic.create = async (body, user2) => {
155683
- const [result] = await db_default.insert(pmPlanTable).values({
155684
- ...body,
155685
- companyId: user2.companyId
155686
- }).returning({
155687
- id: pmPlanTable.id
155683
+ if (!user2.employeeId) {
155684
+ return status("Bad Request", "\u0410\u0436\u0438\u043B\u0442\u043D\u044B \u043C\u044D\u0434\u044D\u044D\u043B\u044D\u043B \u0448\u0430\u0430\u0440\u0434\u043B\u0430\u0433\u0430\u0442\u0430\u0439.");
155685
+ }
155686
+ const [[template], [machine]] = await Promise.all([
155687
+ db_default.select().from(pmTemplateTable).where(eq(pmTemplateTable.id, body.pmTemplateId)).limit(1),
155688
+ db_default.select().from(companyMachineTable).where(eq(companyMachineTable.id, body.machineId)).limit(1)
155689
+ ]);
155690
+ if (!template) {
155691
+ return status("Not Found", "Pm Template \u043E\u043B\u0434\u0441\u043E\u043D\u0433\u04AF\u0439.");
155692
+ }
155693
+ if (!machine) {
155694
+ return status("Not Found", "\u041C\u0430\u0448\u0438\u043D \u043E\u043B\u0434\u0441\u043E\u043D\u0433\u04AF\u0439.");
155695
+ }
155696
+ if (template.machineKindId !== machine.machineKindId) {
155697
+ return status("Bad Request", "\u041C\u0430\u0448\u0438\u043D\u044B \u0442\u04E9\u0440\u04E9\u043B \u0445\u044D\u0440\u044D\u0433\u043B\u044D\u0433\u0447\u0438\u0439\u043D \u043C\u0430\u0448\u0438\u043D \u0442\u04E9\u0440\u04E9\u043B\u0442\u044D\u0439 \u0442\u044D\u043D\u0446\u04AF\u04AF \u0431\u0430\u0439\u0445\u0433\u04AF\u0439.");
155698
+ }
155699
+ const products = await db_default.select().from(pmTemplateProductTable).where(eq(pmTemplateProductTable.pmTemplateId, template.id));
155700
+ return db_default.transaction(async (db2) => {
155701
+ const [plan] = await db2.insert(pmPlanTable).values({
155702
+ companyId: user2.companyId,
155703
+ name: template.name,
155704
+ description: template.description
155705
+ }).returning({
155706
+ id: pmPlanTable.id
155707
+ });
155708
+ await db2.insert(pmPlanMachineTable).values({
155709
+ pmPlanId: plan.id,
155710
+ pmTemplateId: template.id,
155711
+ machineId: machine.id,
155712
+ employeeCreatedId: user2.employeeId,
155713
+ userCreatedId: user2.id
155714
+ });
155715
+ if (products.length > 0) {
155716
+ await db2.insert(pmPlanProductTable).values(products.map((product) => ({
155717
+ pmPlanId: plan.id,
155718
+ productKindId: product.productKindId,
155719
+ uomId: product.uomId,
155720
+ quantity: product.quantity,
155721
+ pmQuantity: product.id
155722
+ })));
155723
+ }
155688
155724
  });
155689
- return result;
155690
155725
  };
155691
155726
  PmPlanLogic.update = async (id, body, user2) => {
155692
155727
  await db_default.update(pmPlanTable).set({
@@ -155783,6 +155818,19 @@ var machineRoutes2 = new Elysia({
155783
155818
  }).delete("/:id", async ({ params: { id } }) => logic_default41.remove(id));
155784
155819
  var machine_default2 = machineRoutes2;
155785
155820
 
155821
+ // src/routes/fleet/pm/plan/model.ts
155822
+ var PmPlanModel;
155823
+ ((PmPlanModel) => {
155824
+ const updateSchema = createUpdateSchema(pmPlanTable);
155825
+ PmPlanModel.create = t.Object({
155826
+ pmTemplateId: t.String({ format: "uuid" }),
155827
+ machineId: t.String({ format: "uuid" })
155828
+ });
155829
+ PmPlanModel.update = OmitBaseSchema(updateSchema);
155830
+ PmPlanModel.select = t.Composite([PaginationSchema]);
155831
+ })(PmPlanModel ||= {});
155832
+ var model_default41 = PmPlanModel;
155833
+
155786
155834
  // src/routes/fleet/pm/plan/product/logic.ts
155787
155835
  var PmPlanProductLogic;
155788
155836
  ((PmPlanProductLogic) => {
@@ -155836,7 +155884,7 @@ var PmPlanProductModel;
155836
155884
  ]);
155837
155885
  PmPlanProductModel.createMany = t.Array(OmitBaseSchema(createSchema));
155838
155886
  })(PmPlanProductModel ||= {});
155839
- var model_default41 = PmPlanProductModel;
155887
+ var model_default42 = PmPlanProductModel;
155840
155888
 
155841
155889
  // src/routes/fleet/pm/plan/product/index.ts
155842
155890
  var productRoutes5 = new Elysia({
@@ -155845,29 +155893,18 @@ var productRoutes5 = new Elysia({
155845
155893
  }).use(better_auth_default).guard({
155846
155894
  auth: true
155847
155895
  }).get("/", async ({ query }) => logic_default42.select(query), {
155848
- query: model_default41.select
155896
+ query: model_default42.select
155849
155897
  }).post("/", async ({ body }) => logic_default42.create(body), {
155850
- body: model_default41.create
155898
+ body: model_default42.create
155851
155899
  }).post("/many", async ({ body }) => logic_default42.createMany(body), {
155852
- body: model_default41.createMany
155900
+ body: model_default42.createMany
155853
155901
  }).guard({
155854
155902
  params: IdSchema
155855
155903
  }).put("/:id", async ({ body, params: { id } }) => logic_default42.update(id, body), {
155856
- body: model_default41.update
155904
+ body: model_default42.update
155857
155905
  }).delete("/:id", async ({ params: { id } }) => logic_default42.remove(id));
155858
155906
  var product_default5 = productRoutes5;
155859
155907
 
155860
- // src/routes/fleet/pm/plan/model.ts
155861
- var PmPlanModel;
155862
- ((PmPlanModel) => {
155863
- const createSchema = createInsertSchema2(pmPlanTable);
155864
- const updateSchema = createUpdateSchema(pmPlanTable);
155865
- PmPlanModel.create = OmitBaseSchema(createSchema);
155866
- PmPlanModel.update = OmitBaseSchema(updateSchema);
155867
- PmPlanModel.select = t.Composite([PaginationSchema]);
155868
- })(PmPlanModel ||= {});
155869
- var model_default42 = PmPlanModel;
155870
-
155871
155908
  // src/routes/fleet/pm/plan/index.ts
155872
155909
  var planRoutes = new Elysia({
155873
155910
  prefix: "/plan",
@@ -155875,13 +155912,13 @@ var planRoutes = new Elysia({
155875
155912
  }).use(better_auth_default).use(machine_default2).use(product_default5).guard({
155876
155913
  userKind: "COMPANY_ADMIN"
155877
155914
  }).get("/", async ({ query, user: user2 }) => logic_default40.select(query, user2), {
155878
- query: model_default42.select
155915
+ query: model_default41.select
155879
155916
  }).post("/", async ({ body, user: user2 }) => logic_default40.create(body, user2), {
155880
- body: model_default42.create
155917
+ body: model_default41.create
155881
155918
  }).guard({
155882
155919
  params: IdSchema
155883
155920
  }).put("/:id", async ({ body, params: { id }, user: user2 }) => logic_default40.update(id, body, user2), {
155884
- body: model_default42.update
155921
+ body: model_default41.update
155885
155922
  }).delete("/:id", async ({ params: { id }, user: user2 }) => logic_default40.remove(id, user2));
155886
155923
  var plan_default = planRoutes;
155887
155924
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autosync_backend2",
3
- "version": "1.2.56",
3
+ "version": "1.2.57",
4
4
  "module": "src/index.ts",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",