autosync_backend2 1.0.78 → 1.0.79
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 +4 -2
- package/dist/index.js +78 -25
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1458,10 +1458,12 @@ declare const app: Elysia<"", {
|
|
|
1458
1458
|
headers: unknown;
|
|
1459
1459
|
response: {
|
|
1460
1460
|
200: {
|
|
1461
|
-
|
|
1462
|
-
|
|
1461
|
+
pageQuantity: number;
|
|
1462
|
+
totalQuantity: number;
|
|
1463
1463
|
pagePrice: number;
|
|
1464
1464
|
totalPrice: number;
|
|
1465
|
+
totalCount: number;
|
|
1466
|
+
totalPage: number;
|
|
1465
1467
|
result: {
|
|
1466
1468
|
inventory: {
|
|
1467
1469
|
name: string;
|
package/dist/index.js
CHANGED
|
@@ -15775,6 +15775,7 @@ __export(exports_schema, {
|
|
|
15775
15775
|
verification: () => verification,
|
|
15776
15776
|
userRoleEnum: () => userRoleEnum,
|
|
15777
15777
|
user: () => user,
|
|
15778
|
+
statusEnum: () => statusEnum,
|
|
15778
15779
|
session: () => session,
|
|
15779
15780
|
permissionTable: () => permissionTable,
|
|
15780
15781
|
permissionGroupTable: () => permissionGroupTable,
|
|
@@ -15782,6 +15783,10 @@ __export(exports_schema, {
|
|
|
15782
15783
|
merchantTable: () => merchantTable,
|
|
15783
15784
|
merchantSchema: () => merchantSchema,
|
|
15784
15785
|
logTable: () => logTable,
|
|
15786
|
+
inventoryTransferRequestTable: () => inventoryTransferRequestTable,
|
|
15787
|
+
inventoryTransferRequestRelations: () => inventoryTransferRequestRelations,
|
|
15788
|
+
inventoryTransferRequestItemTable: () => inventoryTransferRequestItemTable,
|
|
15789
|
+
inventoryTransferRequestItemRelations: () => inventoryTransferRequestItemRelations,
|
|
15785
15790
|
inventorySupplierTable: () => inventorySupplierTable,
|
|
15786
15791
|
inventorySchema: () => inventorySchema,
|
|
15787
15792
|
inventoryRefundTable: () => inventoryRefundTable,
|
|
@@ -18802,6 +18807,12 @@ function extractTablesRelationalConfig(schema, configHelpers) {
|
|
|
18802
18807
|
}
|
|
18803
18808
|
return { tables: tablesConfig, tableNamesMap };
|
|
18804
18809
|
}
|
|
18810
|
+
function relations(table, relations2) {
|
|
18811
|
+
return new Relations(table, (helpers) => Object.fromEntries(Object.entries(relations2(helpers)).map(([key, value]) => [
|
|
18812
|
+
key,
|
|
18813
|
+
value.withFieldName(key)
|
|
18814
|
+
])));
|
|
18815
|
+
}
|
|
18805
18816
|
function createOne(sourceTable) {
|
|
18806
18817
|
return function one(table, config) {
|
|
18807
18818
|
return new One(sourceTable, table, config, config?.fields.reduce((res, f) => res && f.notNull, true) ?? false);
|
|
@@ -21015,14 +21026,46 @@ var inventoryRefundTable = inventorySchema.table("refund", {
|
|
|
21015
21026
|
merchantId: uuid().notNull(),
|
|
21016
21027
|
branchId: uuid().notNull(),
|
|
21017
21028
|
isApproved: boolean().default(false),
|
|
21018
|
-
userId:
|
|
21019
|
-
approvedUserId:
|
|
21029
|
+
userId: text().notNull(),
|
|
21030
|
+
approvedUserId: text()
|
|
21020
21031
|
});
|
|
21021
21032
|
var inventorySupplierTable = inventorySchema.table("supplier", {
|
|
21022
21033
|
...base_schema_helper_default,
|
|
21023
21034
|
name: varchar().notNull(),
|
|
21024
21035
|
image: varchar()
|
|
21025
21036
|
});
|
|
21037
|
+
var statusEnum = inventorySchema.enum("status", [
|
|
21038
|
+
"\u0417\u04E9\u0432\u0448\u04E9\u04E9\u0440\u04E9\u0433\u0434\u0441\u04E9\u043D",
|
|
21039
|
+
"\u0426\u0443\u0446\u043B\u0430\u0433\u0434\u0441\u0430\u043D",
|
|
21040
|
+
"\u0425\u04AF\u043B\u044D\u044D\u0433\u0434\u044D\u0436 \u0431\u0443\u0439"
|
|
21041
|
+
]);
|
|
21042
|
+
var inventoryTransferRequestTable = inventorySchema.table("transfer_request", {
|
|
21043
|
+
...base_schema_helper_default,
|
|
21044
|
+
status: statusEnum().notNull().default("\u0425\u04AF\u043B\u044D\u044D\u0433\u0434\u044D\u0436 \u0431\u0443\u0439"),
|
|
21045
|
+
createdUserId: text().notNull(),
|
|
21046
|
+
branchId: uuid().notNull(),
|
|
21047
|
+
merchantId: uuid().notNull(),
|
|
21048
|
+
to: uuid().notNull()
|
|
21049
|
+
});
|
|
21050
|
+
var inventoryTransferRequestRelations = relations(inventoryTransferRequestTable, ({ many }) => ({
|
|
21051
|
+
items: many(inventoryTransferRequestItemTable)
|
|
21052
|
+
}));
|
|
21053
|
+
var inventoryTransferRequestItemTable = inventorySchema.table("transfer_request_item", {
|
|
21054
|
+
...base_schema_helper_default,
|
|
21055
|
+
itemId: uuid().notNull(),
|
|
21056
|
+
quantity: numeric({ mode: "number" }).notNull(),
|
|
21057
|
+
requestId: uuid().notNull()
|
|
21058
|
+
});
|
|
21059
|
+
var inventoryTransferRequestItemRelations = relations(inventoryTransferRequestItemTable, ({ one }) => ({
|
|
21060
|
+
request: one(inventoryTransferRequestTable, {
|
|
21061
|
+
fields: [inventoryTransferRequestItemTable.requestId],
|
|
21062
|
+
references: [inventoryTransferRequestTable.id]
|
|
21063
|
+
}),
|
|
21064
|
+
item: one(inventoryItemTable, {
|
|
21065
|
+
fields: [inventoryTransferRequestItemTable.itemId],
|
|
21066
|
+
references: [inventoryItemTable.id]
|
|
21067
|
+
})
|
|
21068
|
+
}));
|
|
21026
21069
|
// src/lib/db/schema/common.schema.ts
|
|
21027
21070
|
var logTable = pgTable("log", {
|
|
21028
21071
|
...base_schema_helper_default,
|
|
@@ -73426,6 +73469,7 @@ var permission_default = permissionMacro;
|
|
|
73426
73469
|
function withPagination(qb, { size, page }) {
|
|
73427
73470
|
return qb.limit(size).offset((page - 1) * size);
|
|
73428
73471
|
}
|
|
73472
|
+
var totalCountSql = sql`count(*) over()`.mapWith(Number);
|
|
73429
73473
|
var pagination_helper_default = withPagination;
|
|
73430
73474
|
|
|
73431
73475
|
// src/lib/db/helpers/soft-delete.helper.ts
|
|
@@ -95953,20 +95997,30 @@ var InventoryLogLogic;
|
|
|
95953
95997
|
const base = db_default.select({
|
|
95954
95998
|
...columns,
|
|
95955
95999
|
inventory: inventoryItemTable,
|
|
95956
|
-
|
|
95957
|
-
|
|
96000
|
+
pageQuantity: sql`COALESCE(sum(${inventoryLogTable.quantity}), 0)`.mapWith(Number),
|
|
96001
|
+
totalQuantity: sql`COALESCE(sum(${inventoryLogTable.quantity}) over(), 0)`.mapWith(Number),
|
|
95958
96002
|
pagePrice: sql`sum(${inventoryLogTable.sellPrice} * ${inventoryLogTable.quantity})`.mapWith(Number),
|
|
95959
|
-
totalPrice: sql`sum(${inventoryLogTable.sellPrice} * ${inventoryLogTable.quantity}) over()`.mapWith(Number)
|
|
95960
|
-
|
|
96003
|
+
totalPrice: sql`sum(${inventoryLogTable.sellPrice} * ${inventoryLogTable.quantity}) over()`.mapWith(Number),
|
|
96004
|
+
totalCount: totalCountSql
|
|
96005
|
+
}).from(inventoryLogTable).innerJoin(inventoryItemTable, eq(inventoryLogTable.itemId, inventoryItemTable.id)).where(filter).groupBy(inventoryLogTable.id, inventoryItemTable.id).$dynamic();
|
|
95961
96006
|
const inventoryLogs = await pagination_helper_default(base, query.pagination);
|
|
95962
96007
|
const content = {
|
|
95963
|
-
|
|
95964
|
-
|
|
96008
|
+
pageQuantity: inventoryLogs[0]?.pageQuantity ?? 0,
|
|
96009
|
+
totalQuantity: inventoryLogs[0]?.totalQuantity ?? 0,
|
|
95965
96010
|
pagePrice: inventoryLogs[0]?.pagePrice ?? 0,
|
|
95966
|
-
totalPrice: inventoryLogs[0]?.totalPrice ?? 0
|
|
96011
|
+
totalPrice: inventoryLogs[0]?.totalPrice ?? 0,
|
|
96012
|
+
totalCount: inventoryLogs[0]?.totalCount ?? 0,
|
|
96013
|
+
totalPage: inventoryLogs.length === 0 ? 0 : Math.ceil(inventoryLogs[0].totalCount / query.pagination.size)
|
|
95967
96014
|
};
|
|
95968
96015
|
return {
|
|
95969
|
-
result: inventoryLogs.map(({
|
|
96016
|
+
result: inventoryLogs.map(({
|
|
96017
|
+
pageQuantity,
|
|
96018
|
+
totalQuantity,
|
|
96019
|
+
pagePrice,
|
|
96020
|
+
totalPrice,
|
|
96021
|
+
totalCount,
|
|
96022
|
+
...item
|
|
96023
|
+
}) => item),
|
|
95970
96024
|
...content
|
|
95971
96025
|
};
|
|
95972
96026
|
};
|
|
@@ -96329,7 +96383,7 @@ var InventoryItemLogic;
|
|
|
96329
96383
|
totalQuantity: sql`COALESCE(sum(${inventoryItemTable.quantity}) over(), 0)`.mapWith(Number),
|
|
96330
96384
|
pagePrice: sql`sum(${inventoryItemTable.sellPrice} * ${inventoryItemTable.quantity})`.mapWith(Number),
|
|
96331
96385
|
totalPrice: sql`sum(${inventoryItemTable.sellPrice} * ${inventoryItemTable.quantity}) over()`.mapWith(Number),
|
|
96332
|
-
totalCount:
|
|
96386
|
+
totalCount: totalCountSql
|
|
96333
96387
|
}).from(inventoryItemTable).where(InventoryItemLogic.getInventoryItemFilter(query, user2)).groupBy(inventoryItemTable.id).$dynamic();
|
|
96334
96388
|
const inventoryItems = await pagination_helper_default(base, query.pagination);
|
|
96335
96389
|
const content = {
|
|
@@ -96352,8 +96406,8 @@ var InventoryItemLogic;
|
|
|
96352
96406
|
...content
|
|
96353
96407
|
};
|
|
96354
96408
|
};
|
|
96355
|
-
InventoryItemLogic.create = async (body, user2) => {
|
|
96356
|
-
return await
|
|
96409
|
+
InventoryItemLogic.create = async (body, user2, desc2, tdb = db_default) => {
|
|
96410
|
+
return await tdb.transaction(async (db2) => {
|
|
96357
96411
|
const [inventoryItem] = await db2.insert(inventoryItemTable).values({
|
|
96358
96412
|
...body,
|
|
96359
96413
|
branchId: body.branchId ?? user2.branchId,
|
|
@@ -96363,7 +96417,7 @@ var InventoryItemLogic;
|
|
|
96363
96417
|
await logic_default2.create({
|
|
96364
96418
|
itemId: inventoryItem.id,
|
|
96365
96419
|
quantity: body.quantity,
|
|
96366
|
-
description: "\u0413\u0430\u0440\u0430\u0430\u0440 \u0431\u0430\u0440\u0430\u0430 \u043D\u044D\u043C\u0441\u044D\u043D.",
|
|
96420
|
+
description: desc2 ?? "\u0413\u0430\u0440\u0430\u0430\u0440 \u0431\u0430\u0440\u0430\u0430 \u043D\u044D\u043C\u0441\u044D\u043D.",
|
|
96367
96421
|
userId: user2.id
|
|
96368
96422
|
}, db2);
|
|
96369
96423
|
}
|
|
@@ -96513,7 +96567,7 @@ var InventoryRefundLogic;
|
|
|
96513
96567
|
const baseQuery = db_default.select({
|
|
96514
96568
|
...columns,
|
|
96515
96569
|
inventory: inventoryItemTable,
|
|
96516
|
-
totalCount:
|
|
96570
|
+
totalCount: totalCountSql
|
|
96517
96571
|
}).from(inventoryRefundTable).where(filter).innerJoin(inventoryItemTable, eq(inventoryRefundTable.itemId, inventoryItemTable.id)).$dynamic();
|
|
96518
96572
|
const refunds = await pagination_helper_default(baseQuery, query.pagination);
|
|
96519
96573
|
const content = {
|
|
@@ -96535,20 +96589,20 @@ var InventoryRefundLogic;
|
|
|
96535
96589
|
return refund;
|
|
96536
96590
|
};
|
|
96537
96591
|
InventoryRefundLogic.approve = async (id, user2) => {
|
|
96538
|
-
const currentRefund = await db_default.select({
|
|
96592
|
+
const [currentRefund] = await db_default.select({
|
|
96539
96593
|
isApproved: inventoryRefundTable.isApproved
|
|
96540
96594
|
}).from(inventoryRefundTable).where(and(eq(inventoryRefundTable.id, id), eq(inventoryRefundTable.merchantId, user2.merchantId)));
|
|
96541
|
-
if (currentRefund
|
|
96595
|
+
if (!currentRefund) {
|
|
96542
96596
|
return status("Not Found", "\u0411\u0443\u0446\u0430\u0430\u043B\u0442 \u043E\u043B\u0434\u0441\u043E\u043D\u0433\u04AF\u0439.");
|
|
96543
96597
|
}
|
|
96544
|
-
if (currentRefund
|
|
96598
|
+
if (currentRefund.isApproved) {
|
|
96545
96599
|
return status("Bad Request", "\u0411\u0443\u0446\u0430\u0430\u043B\u0442 \u0437\u04E9\u0432\u0448\u04E9\u04E9\u0440\u04E9\u0433\u0434\u0441\u04E9\u043D \u0431\u0430\u0439\u043D\u0430.");
|
|
96546
96600
|
}
|
|
96547
|
-
return
|
|
96601
|
+
return db_default.transaction(async (db2) => {
|
|
96548
96602
|
const [refund] = await db2.update(inventoryRefundTable).set({
|
|
96549
96603
|
isApproved: true,
|
|
96550
96604
|
approvedUserId: user2.id
|
|
96551
|
-
}).returning();
|
|
96605
|
+
}).where(eq(inventoryRefundTable.id, id)).returning();
|
|
96552
96606
|
await logic_default.handleQuantityChange({
|
|
96553
96607
|
id: refund.itemId,
|
|
96554
96608
|
quantity: refund.quantity,
|
|
@@ -96612,7 +96666,7 @@ var InventorySupplierLogic;
|
|
|
96612
96666
|
const columns = getTableColumns(inventorySupplierTable);
|
|
96613
96667
|
const baseQuery = db_default.select({
|
|
96614
96668
|
...columns,
|
|
96615
|
-
totalCount:
|
|
96669
|
+
totalCount: totalCountSql
|
|
96616
96670
|
}).from(inventorySupplierTable).where(softDeletedFilter(inventorySupplierTable)).$dynamic();
|
|
96617
96671
|
const suppliers = await pagination_helper_default(baseQuery, query.pagination);
|
|
96618
96672
|
const content = {
|
|
@@ -96684,7 +96738,6 @@ class CrudHelper {
|
|
|
96684
96738
|
}
|
|
96685
96739
|
async get(input, filter) {
|
|
96686
96740
|
const wheres = [softDeletedFilter(this.table)];
|
|
96687
|
-
console.log(input);
|
|
96688
96741
|
if (!filter) {
|
|
96689
96742
|
const tableKeys = Object.keys(this.table);
|
|
96690
96743
|
for (const key of Object.keys(input)) {
|
|
@@ -96706,7 +96759,7 @@ class CrudHelper {
|
|
|
96706
96759
|
const columns = getTableColumns(this.table);
|
|
96707
96760
|
const baseQuery = db_default.select({
|
|
96708
96761
|
...columns,
|
|
96709
|
-
totalCount:
|
|
96762
|
+
totalCount: totalCountSql
|
|
96710
96763
|
}).from(this.table).where(filter ?? and(...wheres)).$dynamic();
|
|
96711
96764
|
const result = await pagination_helper_default(baseQuery, input.pagination);
|
|
96712
96765
|
const content = {
|
|
@@ -97067,7 +97120,7 @@ var PermissionLogic;
|
|
|
97067
97120
|
const columns = getTableColumns(permissionGroupTable);
|
|
97068
97121
|
const baseQuery = db_default.select({
|
|
97069
97122
|
...columns,
|
|
97070
|
-
totalCount:
|
|
97123
|
+
totalCount: totalCountSql
|
|
97071
97124
|
}).from(permissionGroupTable).where(softDeletedFilter(permissionGroupTable)).$dynamic();
|
|
97072
97125
|
const permissionGroups = await pagination_helper_default(baseQuery, query.pagination);
|
|
97073
97126
|
const content = {
|
|
@@ -97266,7 +97319,7 @@ var UserLogic;
|
|
|
97266
97319
|
const columns = getTableColumns(user);
|
|
97267
97320
|
const baseQuery = db_default.select({
|
|
97268
97321
|
...columns,
|
|
97269
|
-
totalCount:
|
|
97322
|
+
totalCount: totalCountSql
|
|
97270
97323
|
}).from(user).where(filter).$dynamic();
|
|
97271
97324
|
const users = await pagination_helper_default(baseQuery, query.pagination);
|
|
97272
97325
|
const userPermissions2 = await logic_default6.selectByUserId(users.map((u) => u.id));
|