autosync_backend2 1.2.48 → 1.2.50
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 +210 -206
- package/dist/index.js +165 -105
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -142533,11 +142533,16 @@ __export(exports_schema, {
|
|
|
142533
142533
|
companySchema: () => companySchema,
|
|
142534
142534
|
companyPackageTable: () => companyPackageTable,
|
|
142535
142535
|
companyMachineTable: () => companyMachineTable,
|
|
142536
|
+
companyInvoiceTable: () => companyInvoiceTable,
|
|
142537
|
+
companyInvoiceStatusEnum: () => companyInvoiceStatusEnum,
|
|
142538
|
+
companyInvoicePaymentTable: () => companyInvoicePaymentTable,
|
|
142536
142539
|
companyEmployeeTable: () => companyEmployeeTable,
|
|
142537
142540
|
companyCompanyTable: () => companyCompanyTable,
|
|
142538
142541
|
companyBranchWorkSchdedule: () => companyBranchWorkSchdedule,
|
|
142539
142542
|
companyBranchWorkLogTable: () => companyBranchWorkLogTable,
|
|
142540
142543
|
companyBranchTable: () => companyBranchTable,
|
|
142544
|
+
companyBillingPlanTable: () => companyBillingPlanTable,
|
|
142545
|
+
companyBillingPeriodEnum: () => companyBillingPeriodEnum,
|
|
142541
142546
|
companyAccountTable: () => companyAccountTable,
|
|
142542
142547
|
account: () => account
|
|
142543
142548
|
});
|
|
@@ -142834,6 +142839,53 @@ var companyMachineTable = companySchema.table("machine", {
|
|
|
142834
142839
|
km: integer2().notNull().default(0),
|
|
142835
142840
|
customData: jsonb()
|
|
142836
142841
|
});
|
|
142842
|
+
var companyBillingPeriodEnum = companySchema.enum("billing_period", [
|
|
142843
|
+
"MONTHLY",
|
|
142844
|
+
"ANNUAL",
|
|
142845
|
+
"YEARLY"
|
|
142846
|
+
]);
|
|
142847
|
+
var companyInvoiceStatusEnum = companySchema.enum("invoice_status", [
|
|
142848
|
+
"PENDING",
|
|
142849
|
+
"PAID",
|
|
142850
|
+
"OVERDUE",
|
|
142851
|
+
"CANCELLED"
|
|
142852
|
+
]);
|
|
142853
|
+
var companyBillingPlanTable = companySchema.table("billing_plan", {
|
|
142854
|
+
...base_schema_helper_default,
|
|
142855
|
+
companyId: uuid5().notNull(),
|
|
142856
|
+
billingPeriod: companyBillingPeriodEnum().notNull().default("MONTHLY"),
|
|
142857
|
+
basePrice: numeric({ mode: "number" }).notNull(),
|
|
142858
|
+
pricePerCar: numeric({ mode: "number" }).notNull(),
|
|
142859
|
+
carLimit: integer2().notNull(),
|
|
142860
|
+
maxCarCount: integer2(),
|
|
142861
|
+
active: boolean4().notNull().default(true),
|
|
142862
|
+
note: text()
|
|
142863
|
+
});
|
|
142864
|
+
var companyInvoiceTable = companySchema.table("invoice", {
|
|
142865
|
+
...base_schema_helper_default,
|
|
142866
|
+
companyId: uuid5().notNull(),
|
|
142867
|
+
billingPlanId: uuid5().notNull(),
|
|
142868
|
+
periodStart: date7().notNull(),
|
|
142869
|
+
periodEnd: date7().notNull(),
|
|
142870
|
+
carCount: integer2().notNull(),
|
|
142871
|
+
basePrice: numeric({ mode: "number" }).notNull(),
|
|
142872
|
+
carPrice: numeric({ mode: "number" }).notNull(),
|
|
142873
|
+
totalPrice: numeric({ mode: "number" }).notNull(),
|
|
142874
|
+
status: companyInvoiceStatusEnum().notNull().default("PENDING"),
|
|
142875
|
+
issuedAt: timestamp({ withTimezone: true, mode: "string" }).notNull(),
|
|
142876
|
+
paidAt: timestamp({ withTimezone: true, mode: "string" }),
|
|
142877
|
+
dueAt: timestamp({ withTimezone: true, mode: "string" }).notNull(),
|
|
142878
|
+
note: text()
|
|
142879
|
+
});
|
|
142880
|
+
var companyInvoicePaymentTable = companySchema.table("invoice_payment", {
|
|
142881
|
+
...base_schema_helper_default,
|
|
142882
|
+
invoiceId: uuid5().notNull(),
|
|
142883
|
+
amount: numeric({ mode: "number" }).notNull(),
|
|
142884
|
+
paidAt: timestamp({ withTimezone: true, mode: "string" }).notNull(),
|
|
142885
|
+
paymentType: varchar().notNull(),
|
|
142886
|
+
reference: varchar(),
|
|
142887
|
+
note: text()
|
|
142888
|
+
});
|
|
142837
142889
|
// src/lib/db/schema/crm.schema.ts
|
|
142838
142890
|
var crmSchema = pgSchema("crm");
|
|
142839
142891
|
var crmCustomerTable = crmSchema.table("customer", {
|
|
@@ -146594,7 +146646,7 @@ var StringEnum = (values) => {
|
|
|
146594
146646
|
async function getSession2(headers) {
|
|
146595
146647
|
const session2 = await auth2.api.getSession({ headers });
|
|
146596
146648
|
if (session2 === null) {
|
|
146597
|
-
return status("Unauthorized", "
|
|
146649
|
+
return status("Unauthorized", "\u0422\u043E\u043A\u0435\u043D \u043E\u043B\u0434\u0441\u043E\u043D\u0433\u04AF\u0439");
|
|
146598
146650
|
}
|
|
146599
146651
|
return {
|
|
146600
146652
|
user: session2.user,
|
|
@@ -147585,7 +147637,7 @@ var WarehouseItemLogic;
|
|
|
147585
147637
|
};
|
|
147586
147638
|
WarehouseItemLogic.selectTransaction = async (query, user2) => {
|
|
147587
147639
|
const columns = getTableColumns(warehouseItemTransactionTable);
|
|
147588
|
-
const filter = and(softDeletedFilter(warehouseItemTransactionTable), ...query.product ? [logic_default5.getFilter(query.product, user2)] : [], eq(warehouseItemTransactionTable.transactionType, query.transactionType ?? "IN").if(query.transactionType), eq(warehouseItemTransactionTable.transactionKind, query.transactionKind ?? "TRANSFER").if(query.transactionKind), eq(warehouseItemTransactionTable.employeeId, query.employeeId ?? "").if(query.employeeId), eq(warehouseItemTransactionTable.userId, query.userId ?? "").if(query.userId), eq(warehouseItemTransactionTable.salesId, query.salesId ?? "").if(query.salesId), eq(warehouseItemTransactionTable.orderId, query.orderId ?? "").if(query.orderId), eq(warehouseItemTransactionTable.transferId, query.transferId ?? "").if(query.transferId), eq(warehouseItemTransactionTable.itemId, query.itemId ?? "").if(query.itemId), gte(warehouseItemTransactionTable.createdAt, query.dateFrom ?? "").if(query.dateFrom), lte(warehouseItemTransactionTable.createdAt, query.dateTo ?? "").if(query.dateTo), gte(warehouseItemTransactionTable.quantity, query.minQuantity ?? 0).if(query.minQuantity), lte(warehouseItemTransactionTable.quantity, query.maxQuantity ?? 0).if(query.maxQuantity));
|
|
147640
|
+
const filter = and(softDeletedFilter(warehouseItemTransactionTable), ...query.product ? [logic_default5.getFilter(query.product, user2)] : [], eq(warehouseItemTransactionTable.transactionType, query.transactionType ?? "IN").if(query.transactionType), eq(warehouseItemTransactionTable.transactionKind, query.transactionKind ?? "TRANSFER").if(query.transactionKind), eq(warehouseItemTransactionTable.employeeId, query.employeeId ?? "").if(query.employeeId), eq(warehouseItemTransactionTable.userId, query.userId ?? "").if(query.userId), eq(warehouseItemTransactionTable.salesId, query.salesId ?? "").if(query.salesId), eq(warehouseItemTransactionTable.orderId, query.orderId ?? "").if(query.orderId), eq(warehouseItemTransactionTable.transferId, query.transferId ?? "").if(query.transferId), eq(warehouseItemTransactionTable.itemId, query.itemId ?? "").if(query.itemId), gte(warehouseItemTransactionTable.createdAt, query.dateFrom ?? "").if(query.dateFrom), lte(warehouseItemTransactionTable.createdAt, query.dateTo ?? "").if(query.dateTo), gte(warehouseItemTransactionTable.quantity, query.minQuantity ?? 0).if(query.minQuantity), lte(warehouseItemTransactionTable.quantity, query.maxQuantity ?? 0).if(query.maxQuantity), eq(warehouseItemTable.warehouseId, query.warehouseId).if(query.warehouseId));
|
|
147589
147641
|
const baseQuery = db_default.select({
|
|
147590
147642
|
...columns,
|
|
147591
147643
|
totalCount: totalCountSql,
|
|
@@ -150739,101 +150791,6 @@ var StorePay = class {
|
|
|
150739
150791
|
});
|
|
150740
150792
|
}
|
|
150741
150793
|
};
|
|
150742
|
-
var UbPay = class {
|
|
150743
|
-
constructor(clientId, clientSecret, saveToken, baseUrl) {
|
|
150744
|
-
this.baseUrl = "https://merchant-payment-api.dev.p.ubcabtech.com";
|
|
150745
|
-
this.clientId = clientId;
|
|
150746
|
-
this.clientSecret = clientSecret;
|
|
150747
|
-
this.baseUrl = baseUrl || this.baseUrl;
|
|
150748
|
-
this.saveToken = saveToken;
|
|
150749
|
-
}
|
|
150750
|
-
login() {
|
|
150751
|
-
return __async(this, null, function* () {
|
|
150752
|
-
const req = yield fetch(`${this.baseUrl}/auth/token`, {
|
|
150753
|
-
method: "POST",
|
|
150754
|
-
body: JSON.stringify({
|
|
150755
|
-
clientId: this.clientId,
|
|
150756
|
-
clientSecret: this.clientSecret
|
|
150757
|
-
})
|
|
150758
|
-
});
|
|
150759
|
-
const res = yield req.json();
|
|
150760
|
-
if (!res.success) {
|
|
150761
|
-
throw new Error(res.error.message);
|
|
150762
|
-
}
|
|
150763
|
-
return {
|
|
150764
|
-
access_token: res.data.accessToken,
|
|
150765
|
-
refresh_token: res.data.refreshToken,
|
|
150766
|
-
refresh_expires_in: res.data.refreshTokenExpiresIn,
|
|
150767
|
-
expires_in: res.data.accessTokenExpiresIn
|
|
150768
|
-
};
|
|
150769
|
-
});
|
|
150770
|
-
}
|
|
150771
|
-
getRefreshToken(token) {
|
|
150772
|
-
return __async(this, null, function* () {
|
|
150773
|
-
const req = yield fetch(`${this.baseUrl}/auth/refresh-token`, {
|
|
150774
|
-
method: "POST",
|
|
150775
|
-
body: JSON.stringify({
|
|
150776
|
-
refreshToken: token.refresh_token
|
|
150777
|
-
})
|
|
150778
|
-
});
|
|
150779
|
-
const res = yield req.json();
|
|
150780
|
-
return __spreadProps2(__spreadValues2({}, token), {
|
|
150781
|
-
access_token: res.data.accessToken,
|
|
150782
|
-
expires_in: parseInt(res.data.accessTokenExpriresIn, 10)
|
|
150783
|
-
});
|
|
150784
|
-
});
|
|
150785
|
-
}
|
|
150786
|
-
checkToken(inputToken) {
|
|
150787
|
-
return __async(this, null, function* () {
|
|
150788
|
-
let token = inputToken;
|
|
150789
|
-
if (!token || !token.refresh_expires_in) {
|
|
150790
|
-
token = yield this.login();
|
|
150791
|
-
}
|
|
150792
|
-
if (token.refresh_expires_in && new Date(token.refresh_expires_in * 1000) <= /* @__PURE__ */ new Date) {
|
|
150793
|
-
token = yield this.login();
|
|
150794
|
-
} else if (new Date(token.expires_in * 1000) <= /* @__PURE__ */ new Date) {
|
|
150795
|
-
token = yield this.getRefreshToken(token);
|
|
150796
|
-
}
|
|
150797
|
-
if (this.saveToken && JSON.stringify(inputToken) !== JSON.stringify(token)) {
|
|
150798
|
-
yield this.saveToken(token);
|
|
150799
|
-
}
|
|
150800
|
-
return token;
|
|
150801
|
-
});
|
|
150802
|
-
}
|
|
150803
|
-
createInvoice(input, token) {
|
|
150804
|
-
return __async(this, null, function* () {
|
|
150805
|
-
token = yield this.checkToken(token);
|
|
150806
|
-
const req = yield fetch(`${this.baseUrl}/api/v1/invoices`, {
|
|
150807
|
-
method: "POST",
|
|
150808
|
-
headers: {
|
|
150809
|
-
"Content-Type": "application/json",
|
|
150810
|
-
Authorization: `Bearer ${token.access_token}`
|
|
150811
|
-
},
|
|
150812
|
-
body: JSON.stringify(input)
|
|
150813
|
-
});
|
|
150814
|
-
const res = yield req.json();
|
|
150815
|
-
return {
|
|
150816
|
-
data: res,
|
|
150817
|
-
token
|
|
150818
|
-
};
|
|
150819
|
-
});
|
|
150820
|
-
}
|
|
150821
|
-
checkInvoice(invoiceId, token) {
|
|
150822
|
-
return __async(this, null, function* () {
|
|
150823
|
-
token = yield this.checkToken(token);
|
|
150824
|
-
const req = yield fetch(`${this.baseUrl}/api/v1/invoices/${invoiceId}`, {
|
|
150825
|
-
headers: {
|
|
150826
|
-
Authorization: `Bearer ${token.access_token}`
|
|
150827
|
-
}
|
|
150828
|
-
});
|
|
150829
|
-
const res = yield req.json();
|
|
150830
|
-
return {
|
|
150831
|
-
data: res,
|
|
150832
|
-
token
|
|
150833
|
-
};
|
|
150834
|
-
});
|
|
150835
|
-
}
|
|
150836
|
-
};
|
|
150837
150794
|
|
|
150838
150795
|
// src/routes/crm/cpOrder/payment/gateways/index.ts
|
|
150839
150796
|
var CALLBACK_URL = env_default.NODE_ENV === "production" ? "https://v2.api.autosync.mn/api/crm/cp-order/payment" : "http://202.70.40.82:3000/api/crm/cp-order/payment";
|
|
@@ -150973,6 +150930,99 @@ class StorePayGateway extends PaymentGateway {
|
|
|
150973
150930
|
}
|
|
150974
150931
|
}
|
|
150975
150932
|
|
|
150933
|
+
// src/routes/crm/cpOrder/payment/helpers/ubpay.ts
|
|
150934
|
+
class UbPay {
|
|
150935
|
+
clientId;
|
|
150936
|
+
clientSecret;
|
|
150937
|
+
saveToken;
|
|
150938
|
+
baseUrl = "https://merchant-payment-api.dev.p.ubcabtech.com";
|
|
150939
|
+
constructor(clientId, clientSecret, saveToken, baseUrl) {
|
|
150940
|
+
this.clientId = clientId;
|
|
150941
|
+
this.clientSecret = clientSecret;
|
|
150942
|
+
this.baseUrl = baseUrl || this.baseUrl;
|
|
150943
|
+
this.saveToken = saveToken;
|
|
150944
|
+
}
|
|
150945
|
+
async login() {
|
|
150946
|
+
console.log(this.clientId, this.clientSecret);
|
|
150947
|
+
const req = await fetch(`${this.baseUrl}/auth/token`, {
|
|
150948
|
+
method: "POST",
|
|
150949
|
+
body: JSON.stringify({
|
|
150950
|
+
clientId: this.clientId,
|
|
150951
|
+
clientSecret: this.clientSecret
|
|
150952
|
+
})
|
|
150953
|
+
});
|
|
150954
|
+
const res = await req.json();
|
|
150955
|
+
console.log(res);
|
|
150956
|
+
if (!res.success) {
|
|
150957
|
+
throw new Error(res.error.message);
|
|
150958
|
+
}
|
|
150959
|
+
return {
|
|
150960
|
+
access_token: res.data.accessToken,
|
|
150961
|
+
refresh_token: res.data.refreshToken,
|
|
150962
|
+
refresh_expires_in: res.data.refreshTokenExpiresIn,
|
|
150963
|
+
expires_in: res.data.accessTokenExpiresIn
|
|
150964
|
+
};
|
|
150965
|
+
}
|
|
150966
|
+
async getRefreshToken(token) {
|
|
150967
|
+
const req = await fetch(`${this.baseUrl}/auth/refresh-token`, {
|
|
150968
|
+
method: "POST",
|
|
150969
|
+
body: JSON.stringify({
|
|
150970
|
+
refreshToken: token.refresh_token
|
|
150971
|
+
})
|
|
150972
|
+
});
|
|
150973
|
+
const res = await req.json();
|
|
150974
|
+
return {
|
|
150975
|
+
...token,
|
|
150976
|
+
access_token: res.data.accessToken,
|
|
150977
|
+
expires_in: Number.parseInt(res.data.accessTokenExpriresIn, 10)
|
|
150978
|
+
};
|
|
150979
|
+
}
|
|
150980
|
+
async checkToken(inputToken) {
|
|
150981
|
+
let token = inputToken;
|
|
150982
|
+
if (!token || !token.refresh_expires_in) {
|
|
150983
|
+
token = await this.login();
|
|
150984
|
+
}
|
|
150985
|
+
if (token.refresh_expires_in && new Date(token.refresh_expires_in * 1000) <= new Date) {
|
|
150986
|
+
token = await this.login();
|
|
150987
|
+
} else if (new Date(token.expires_in * 1000) <= new Date) {
|
|
150988
|
+
token = await this.getRefreshToken(token);
|
|
150989
|
+
}
|
|
150990
|
+
if (this.saveToken && JSON.stringify(inputToken) !== JSON.stringify(token)) {
|
|
150991
|
+
await this.saveToken(token);
|
|
150992
|
+
}
|
|
150993
|
+
return token;
|
|
150994
|
+
}
|
|
150995
|
+
async createInvoice(input, token) {
|
|
150996
|
+
token = await this.checkToken(token);
|
|
150997
|
+
const req = await fetch(`${this.baseUrl}/api/v1/invoices`, {
|
|
150998
|
+
method: "POST",
|
|
150999
|
+
headers: {
|
|
151000
|
+
"Content-Type": "application/json",
|
|
151001
|
+
Authorization: `Bearer ${token.access_token}`
|
|
151002
|
+
},
|
|
151003
|
+
body: JSON.stringify(input)
|
|
151004
|
+
});
|
|
151005
|
+
const res = await req.json();
|
|
151006
|
+
return {
|
|
151007
|
+
data: res,
|
|
151008
|
+
token
|
|
151009
|
+
};
|
|
151010
|
+
}
|
|
151011
|
+
async checkInvoice(invoiceId, token) {
|
|
151012
|
+
token = await this.checkToken(token);
|
|
151013
|
+
const req = await fetch(`${this.baseUrl}/api/v1/invoices/${invoiceId}`, {
|
|
151014
|
+
headers: {
|
|
151015
|
+
Authorization: `Bearer ${token.access_token}`
|
|
151016
|
+
}
|
|
151017
|
+
});
|
|
151018
|
+
const res = await req.json();
|
|
151019
|
+
return {
|
|
151020
|
+
data: res,
|
|
151021
|
+
token
|
|
151022
|
+
};
|
|
151023
|
+
}
|
|
151024
|
+
}
|
|
151025
|
+
|
|
150976
151026
|
// src/routes/crm/cpOrder/payment/gateways/ubpay.ts
|
|
150977
151027
|
class UbPayGateway extends PaymentGateway {
|
|
150978
151028
|
ubPay;
|
|
@@ -151156,6 +151206,7 @@ var CrmCpOrderPaymentLogic;
|
|
|
151156
151206
|
};
|
|
151157
151207
|
CrmCpOrderPaymentLogic.createUbPay = async (body, user2) => {
|
|
151158
151208
|
const paymentInfo = await getPaymentInfo("UbPay", user2);
|
|
151209
|
+
console.log(paymentInfo);
|
|
151159
151210
|
if ("code" in paymentInfo) {
|
|
151160
151211
|
return paymentInfo;
|
|
151161
151212
|
}
|
|
@@ -151176,6 +151227,7 @@ var CrmCpOrderPaymentLogic;
|
|
|
151176
151227
|
});
|
|
151177
151228
|
return result;
|
|
151178
151229
|
} catch (err2) {
|
|
151230
|
+
console.log(err2);
|
|
151179
151231
|
if (err2 instanceof Error) {
|
|
151180
151232
|
return status("Bad Request", err2.message);
|
|
151181
151233
|
}
|
|
@@ -151216,7 +151268,9 @@ var CrmCpOrderPaymentLogic;
|
|
|
151216
151268
|
if (!payment) {
|
|
151217
151269
|
return status("Not Found", "\u0422\u04E9\u043B\u0431\u04E9\u0440\u0438\u0439\u043D \u0442\u043E\u0445\u0438\u0440\u0433\u043E\u043E \u043E\u043B\u0434\u0441\u043E\u043D\u0433\u04AF\u0439.");
|
|
151218
151270
|
}
|
|
151219
|
-
await redis_client_default.set(cacheKey, payment
|
|
151271
|
+
await redis_client_default.set(cacheKey, payment, {
|
|
151272
|
+
ex: 60 * 60 * 24
|
|
151273
|
+
});
|
|
151220
151274
|
return payment;
|
|
151221
151275
|
};
|
|
151222
151276
|
const getPaymentInfoByPaymentId = async (id, type) => {
|
|
@@ -151238,7 +151292,7 @@ var CrmCpOrderLogic;
|
|
|
151238
151292
|
CrmCpOrderLogic.select = async (query, user2) => {
|
|
151239
151293
|
const make = alias(techdocVehicleKindTable, "make");
|
|
151240
151294
|
const model = alias(techdocVehicleKindTable, "model");
|
|
151241
|
-
const filter = and(eq(crmCpOrderTable.companyId, user2.companyId), eq(crmCpOrderTable.companyBranchId, user2.branchId).if(user2.kind === "CUSTOMER"), eq(crmCpOrderTable.state, query.state ?? "CREATED").if(query.state), eq(crmCpOrderTable.id, query.id ?? "").if(query.id), gte(sql3`date(${crmCpOrderTable.createdAt})`, query.createdAt).if(query.createdAt), lte(sql3`date(${crmCpOrderTable.createdAt})`, query.timeCompleted).if(query.timeCompleted), softDeletedFilter(crmCpOrderTable), like(crmCpOrderTable.orderId, query.orderId ?? "").if(query.orderId), eq(crmCpOrderTable.vehicleId, query.vehicleId ?? "").if(query.vehicleId), eq(crmCpOrderTable.type, query.type).if(query.type), eq(crmCpOrderTable.oldId, query.oldId).if(query.oldId), ilike(model.name, `%${query.model}%`).if(query.model), like(crmVehicleTable.licensePlate, `${query.licensePlate}%`).if(query.licensePlate), ilike(crmVehicleTable.vin, `%${query.vin}%`).if(query.vin), like(crmCustomerTable.phoneNumber, `${query.phone}%`).if(query.phone));
|
|
151295
|
+
const filter = and(eq(crmCpOrderTable.companyId, user2.companyId), eq(crmCpOrderTable.companyBranchId, user2.branchId).if(user2.kind === "CUSTOMER"), eq(crmCpOrderTable.state, query.state ?? "CREATED").if(query.state), eq(crmCpOrderTable.id, query.id ?? "").if(query.id), gte(sql3`date(${crmCpOrderTable.createdAt})`, query.createdAt).if(query.createdAt), lte(sql3`date(${crmCpOrderTable.createdAt})`, query.timeCompleted).if(query.timeCompleted), softDeletedFilter(crmCpOrderTable), like(crmCpOrderTable.orderId, query.orderId ?? "").if(query.orderId), eq(crmCpOrderTable.vehicleId, query.vehicleId ?? "").if(query.vehicleId), eq(crmCpOrderTable.type, query.type).if(query.type), eq(crmCpOrderTable.oldId, query.oldId).if(query.oldId), eq(crmCpOrderTable.companyBranchId, query.branchId).if(query.branchId && user2.kind !== "CUSTOMER"), ilike(model.name, `%${query.model}%`).if(query.model), like(crmVehicleTable.licensePlate, `${query.licensePlate}%`).if(query.licensePlate), ilike(crmVehicleTable.vin, `%${query.vin}%`).if(query.vin), like(crmCustomerTable.phoneNumber, `${query.phone}%`).if(query.phone));
|
|
151242
151296
|
const baseQuery = db_default.select({
|
|
151243
151297
|
totalCount: totalCountSql,
|
|
151244
151298
|
order: crmCpOrderTable,
|
|
@@ -151936,7 +151990,8 @@ var CrmCpOrderModel;
|
|
|
151936
151990
|
default: "Service"
|
|
151937
151991
|
}),
|
|
151938
151992
|
oldId: t.Number(),
|
|
151939
|
-
isPaid: t.Boolean()
|
|
151993
|
+
isPaid: t.Boolean(),
|
|
151994
|
+
branchId: t.String({ format: "uuid" })
|
|
151940
151995
|
}))
|
|
151941
151996
|
]);
|
|
151942
151997
|
CrmCpOrderModel.complete = t.Object({
|
|
@@ -152894,7 +152949,7 @@ var CrmReportsLogic;
|
|
|
152894
152949
|
totalPrice: sql3`CASE WHEN ${crmCpOrderTable.isNoat} = FALSE THEN ${crmCpOrderItemTable.priceTotal} ELSE 0 END`.as("total_price"),
|
|
152895
152950
|
totalPriceNoat: sql3`CASE WHEN ${crmCpOrderTable.isNoat} = TRUE THEN ${crmCpOrderItemTable.priceTotal} * 1.1 ELSE 0 END`.as("total_price_noat"),
|
|
152896
152951
|
totalCount: totalCountSql
|
|
152897
|
-
}).from(crmCpOrderItemTable).leftJoin(crmCpOrderTable, eq(crmCpOrderTable.id, crmCpOrderItemTable.cpOrderId)).leftJoin(crmCustomerTable, eq(crmCustomerTable.id, crmCpOrderTable.customerId)).leftJoin(crmVehicleTable, eq(crmVehicleTable.id, crmCpOrderTable.vehicleId)).leftJoin(warehouseProductTable, eq(warehouseProductTable.id, crmCpOrderItemTable.companyProductId)).leftJoin(companyServiceKindTable, eq(companyServiceKindTable.id, crmCpOrderItemTable.companyServiceKindId)).leftJoin(crmCpOrderItemEmployeeTable, eq(crmCpOrderItemEmployeeTable.cpOrderItemId, crmCpOrderItemTable.id)).leftJoin(companyEmployeeTable, eq(companyEmployeeTable.id, crmCpOrderItemEmployeeTable.employeeId)).leftJoin(crmDiscountApplyTable, eq(crmDiscountApplyTable.cpOrderItemId, crmCpOrderItemTable.id)).where(and(eq(crmCpOrderTable.companyId, user2.companyId), eq(crmCpOrderTable.companyBranchId, user2.branchId).if(user2.kind === "CUSTOMER"), isNotNull(crmCpOrderItemTable.companyProductId).if(query.type === "Product"), isNotNull(crmCpOrderItemTable.companyServiceKindId).if(query.type === "Service"), eq(crmCpOrderItemEmployeeTable.employeeId, query.employeeId).if(query.employeeId), gte(crmCpOrderTable.createdAt, query.startDate).if(query.startDate), lte(crmCpOrderTable.createdAt, query.endDate).if(query.endDate), eq(crmCustomerTable.phoneNumber, query.phoneNumber).if(query.phoneNumber), eq(crmVehicleTable.licensePlate, query.licensePlate).if(query.licensePlate), eq(crmCpOrderTable.type, query.orderType).if(query.orderType), ilike(warehouseProductTable.partNumber, `%${query.partNumber}%`).if(query.partNumber), ilike(companyServiceKindTable.name, `%${query.serviceKindName}%`).if(query.serviceKindName), ilike(warehouseProductTable.name, `%${query.productName}%`).if(query.productName))).orderBy(desc(crmCpOrderTable.createdAt), desc(crmCpOrderItemTable.createdAt)).groupBy((t2) => [
|
|
152952
|
+
}).from(crmCpOrderItemTable).leftJoin(crmCpOrderTable, eq(crmCpOrderTable.id, crmCpOrderItemTable.cpOrderId)).leftJoin(crmCustomerTable, eq(crmCustomerTable.id, crmCpOrderTable.customerId)).leftJoin(crmVehicleTable, eq(crmVehicleTable.id, crmCpOrderTable.vehicleId)).leftJoin(warehouseProductTable, eq(warehouseProductTable.id, crmCpOrderItemTable.companyProductId)).leftJoin(companyServiceKindTable, eq(companyServiceKindTable.id, crmCpOrderItemTable.companyServiceKindId)).leftJoin(crmCpOrderItemEmployeeTable, eq(crmCpOrderItemEmployeeTable.cpOrderItemId, crmCpOrderItemTable.id)).leftJoin(companyEmployeeTable, eq(companyEmployeeTable.id, crmCpOrderItemEmployeeTable.employeeId)).leftJoin(crmDiscountApplyTable, eq(crmDiscountApplyTable.cpOrderItemId, crmCpOrderItemTable.id)).where(and(eq(crmCpOrderTable.companyId, user2.companyId), eq(crmCpOrderTable.companyBranchId, user2.branchId).if(user2.kind === "CUSTOMER"), isNotNull(crmCpOrderItemTable.companyProductId).if(query.type === "Product"), isNotNull(crmCpOrderItemTable.companyServiceKindId).if(query.type === "Service"), eq(crmCpOrderItemEmployeeTable.employeeId, query.employeeId).if(query.employeeId), gte(crmCpOrderTable.createdAt, query.startDate).if(query.startDate), lte(crmCpOrderTable.createdAt, query.endDate).if(query.endDate), eq(crmCustomerTable.phoneNumber, query.phoneNumber).if(query.phoneNumber), eq(crmVehicleTable.licensePlate, query.licensePlate).if(query.licensePlate), eq(crmCpOrderTable.type, query.orderType).if(query.orderType), eq(crmCpOrderTable.companyBranchId, query.branchId).if(query.branchId && user2.kind !== "CUSTOMER"), ilike(warehouseProductTable.partNumber, `%${query.partNumber}%`).if(query.partNumber), ilike(companyServiceKindTable.name, `%${query.serviceKindName}%`).if(query.serviceKindName), ilike(warehouseProductTable.name, `%${query.productName}%`).if(query.productName))).orderBy(desc(crmCpOrderTable.createdAt), desc(crmCpOrderItemTable.createdAt)).groupBy((t2) => [
|
|
152898
152953
|
t2.createdAt,
|
|
152899
152954
|
t2.orderId,
|
|
152900
152955
|
t2.phone,
|
|
@@ -153010,7 +153065,8 @@ var CrmReportsModel;
|
|
|
153010
153065
|
}),
|
|
153011
153066
|
partNumber: t.String(),
|
|
153012
153067
|
productName: t.String(),
|
|
153013
|
-
serviceKindName: t.String()
|
|
153068
|
+
serviceKindName: t.String(),
|
|
153069
|
+
branchId: t.String({ format: "uuid" })
|
|
153014
153070
|
})),
|
|
153015
153071
|
PaginationSchema
|
|
153016
153072
|
]);
|
|
@@ -154291,7 +154347,8 @@ var WarehouseItemModel;
|
|
|
154291
154347
|
dateFrom: t.String({ format: "date-time", default: undefined }),
|
|
154292
154348
|
dateTo: t.String({ format: "date-time", default: undefined }),
|
|
154293
154349
|
minQuantity: t.Number({ minimum: 0 }),
|
|
154294
|
-
maxQuantity: t.Number({ minimum: 0 })
|
|
154350
|
+
maxQuantity: t.Number({ minimum: 0 }),
|
|
154351
|
+
warehouseId: t.String({ format: "uuid" })
|
|
154295
154352
|
}))
|
|
154296
154353
|
]);
|
|
154297
154354
|
const createTransactionSchema = createInsertSchema2(warehouseItemTransactionTable);
|
|
@@ -154657,7 +154714,7 @@ var fieldResult_default = fieldResultRoutes;
|
|
|
154657
154714
|
var InspectionLogic;
|
|
154658
154715
|
((InspectionLogic) => {
|
|
154659
154716
|
InspectionLogic.select = async (query, user2) => {
|
|
154660
|
-
const filter = and(eq(inspectionTable.machineId, query.machineId).if(query.machineId), eq(inspectionTable.templateId, query.templateId).if(query.templateId), eq(inspectionTable.state, query.state).if(query.state), gte(inspectionTable.createdAt, query.startDate).if(query.startDate), lte(inspectionTable.createdAt, query.endDate).if(query.endDate), eq(inspectionTable.id, query.id).if(query.id), or(eq(inspectionTemplateTable.companyId, user2.companyId), isNull2(inspectionTemplateTable.companyId)));
|
|
154717
|
+
const filter = and(eq(inspectionTable.machineId, query.machineId).if(query.machineId), eq(inspectionTable.templateId, query.templateId).if(query.templateId), eq(inspectionTable.state, query.state).if(query.state), eq(inspectionTable.stateResult, query.stateResult).if(query.stateResult), gte(inspectionTable.createdAt, query.startDate).if(query.startDate), lte(inspectionTable.createdAt, query.endDate).if(query.endDate), eq(inspectionTable.id, query.id).if(query.id), or(eq(inspectionTemplateTable.companyId, user2.companyId), isNull2(inspectionTemplateTable.companyId)));
|
|
154661
154718
|
const baseQuery = db_default.select({
|
|
154662
154719
|
inspection: inspectionTable,
|
|
154663
154720
|
machine: companyMachineTable,
|
|
@@ -154713,6 +154770,9 @@ var InspectionModel;
|
|
|
154713
154770
|
state: t.UnionEnum(inspectionTable.state.enumValues, {
|
|
154714
154771
|
default: undefined
|
|
154715
154772
|
}),
|
|
154773
|
+
stateResult: t.UnionEnum(inspectionTable.stateResult.enumValues, {
|
|
154774
|
+
default: undefined
|
|
154775
|
+
}),
|
|
154716
154776
|
startDate: t.String({ format: "date" }),
|
|
154717
154777
|
endDate: t.String({ format: "date" }),
|
|
154718
154778
|
id: t.String({ format: "uuid" })
|
|
@@ -154778,7 +154838,7 @@ var schedule_default = scheduleRoutes;
|
|
|
154778
154838
|
var InspectionTemplateLogic;
|
|
154779
154839
|
((InspectionTemplateLogic) => {
|
|
154780
154840
|
InspectionTemplateLogic.select = async (query, user2) => {
|
|
154781
|
-
const filter = or(eq(inspectionTemplateTable.companyId, user2.companyId).if(user2.kind !== "ADMIN"), isNull2(inspectionTemplateTable.companyId));
|
|
154841
|
+
const filter = and(softDeletedFilter(inspectionTemplateTable), or(eq(inspectionTemplateTable.companyId, user2.companyId).if(user2.kind !== "ADMIN"), isNull2(inspectionTemplateTable.companyId)));
|
|
154782
154842
|
const columns = getTableColumns(inspectionTemplateTable);
|
|
154783
154843
|
const baseQuery = db_default.select({
|
|
154784
154844
|
...columns,
|