@pxp-nd/flow 1.1.4 → 1.1.6
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/controllers/Flow.d.ts +4 -0
- package/dist/controllers/Flow.js +212 -0
- package/dist/entity/Flow.d.ts +1 -0
- package/dist/entity/Flow.js +5 -0
- package/package.json +1 -1
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
* 16-Sep-2023 SP22SEP23 Mercedes Zambrana Change GET to POST in insertEventFlow
|
|
19
19
|
* 28-Sep-2023 SP06OCT23 Mercedes Zambrana Add Validation when change off status (validateFlow, deleteflow, saveFlow, saveflowName)
|
|
20
20
|
* 07-Feb-2025 8353064698 Mercedes Zambrana Add validation for opt in page when flow si funnel change
|
|
21
|
+
* 18-Feb-2025 8501163144 Mercedes Zambrana Add publish filter
|
|
21
22
|
* ******************************************************************************
|
|
22
23
|
*/
|
|
23
24
|
import { EntityManager } from 'typeorm';
|
|
@@ -40,5 +41,8 @@ declare class Flow extends Controller {
|
|
|
40
41
|
changeStatusFlow(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
|
|
41
42
|
validateFlow(flowId: number, manager: EntityManager, status: string): Promise<unknown>;
|
|
42
43
|
basicFlowList(params: Record<string, any>): Promise<unknown>;
|
|
44
|
+
listTemplates(params: Record<string, any>): Promise<unknown>;
|
|
45
|
+
changePublishTemplate(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
|
|
46
|
+
validatePublishTemplate(flowId: number, manager: EntityManager, publish: string): Promise<unknown>;
|
|
43
47
|
}
|
|
44
48
|
export default Flow;
|
package/dist/controllers/Flow.js
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
* 16-Sep-2023 SP22SEP23 Mercedes Zambrana Change GET to POST in insertEventFlow
|
|
20
20
|
* 28-Sep-2023 SP06OCT23 Mercedes Zambrana Add Validation when change off status (validateFlow, deleteflow, saveFlow, saveflowName)
|
|
21
21
|
* 07-Feb-2025 8353064698 Mercedes Zambrana Add validation for opt in page when flow si funnel change
|
|
22
|
+
* 18-Feb-2025 8501163144 Mercedes Zambrana Add publish filter
|
|
22
23
|
* ******************************************************************************
|
|
23
24
|
*/
|
|
24
25
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
@@ -873,6 +874,199 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
873
874
|
const count = totalCount.count;
|
|
874
875
|
return { data, count };
|
|
875
876
|
}
|
|
877
|
+
async listTemplates(params) {
|
|
878
|
+
var _a;
|
|
879
|
+
const isActive = params._isActive;
|
|
880
|
+
const type = params._type || "template"; // Filtrar solo templates
|
|
881
|
+
const vendorIds = params._vendorId ? params._vendorId.split(",").map(Number) : [];
|
|
882
|
+
const templateType = params._templateType;
|
|
883
|
+
const allowedColumns = ["name", "description"];
|
|
884
|
+
const filter = (params === null || params === void 0 ? void 0 : params.filter) ? JSON.parse(params === null || params === void 0 ? void 0 : params.filter) : null;
|
|
885
|
+
const filters = (filter === null || filter === void 0 ? void 0 : filter.items) || [];
|
|
886
|
+
const logicOperator = ((_a = filter === null || filter === void 0 ? void 0 : filter.logicOperator) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || "AND";
|
|
887
|
+
const publish = params._publish;
|
|
888
|
+
const queryBuilder = await (0, typeorm_1.getManager)()
|
|
889
|
+
.createQueryBuilder()
|
|
890
|
+
.select([
|
|
891
|
+
"f.flow_id as flowId",
|
|
892
|
+
"f.vendor_id as vendorId",
|
|
893
|
+
"f.code as code",
|
|
894
|
+
"f.name as name",
|
|
895
|
+
"f.enabled as enabled",
|
|
896
|
+
"f.type as type",
|
|
897
|
+
"f.created_by as createdBy",
|
|
898
|
+
"f.user_id_ai as userIdAi",
|
|
899
|
+
"f.user_ai as userAi",
|
|
900
|
+
"f.modified_by as modifiedBy",
|
|
901
|
+
"f.created_at as createdAt",
|
|
902
|
+
"f.modified_at as modifiedAt",
|
|
903
|
+
"f.is_active as isActive",
|
|
904
|
+
"f.description as description",
|
|
905
|
+
"f.icon as icon",
|
|
906
|
+
"f.status as status",
|
|
907
|
+
"COUNT(fi.flow_instance_id) AS numberOfInstance",
|
|
908
|
+
])
|
|
909
|
+
.from("twf_flow", "f")
|
|
910
|
+
.leftJoin("twf_flow_instance", "fi", "fi.flow_id = f.flow_id");
|
|
911
|
+
// Aplicar filtros
|
|
912
|
+
if (isActive !== undefined) {
|
|
913
|
+
queryBuilder.where("f.is_active = :isActive", { isActive });
|
|
914
|
+
}
|
|
915
|
+
if (publish !== undefined) {
|
|
916
|
+
queryBuilder.where("f.publish = :publish", { publish });
|
|
917
|
+
}
|
|
918
|
+
if (type) {
|
|
919
|
+
queryBuilder.andWhere("f.type = :type", { type });
|
|
920
|
+
}
|
|
921
|
+
if (templateType) {
|
|
922
|
+
queryBuilder.andWhere("f.template_type = :templateType", { templateType });
|
|
923
|
+
}
|
|
924
|
+
if (vendorIds.length > 0) {
|
|
925
|
+
queryBuilder.andWhere("f.vendor_id IN (:...vendorIds)", { vendorIds });
|
|
926
|
+
}
|
|
927
|
+
if (allowedColumns.includes(params.genericFilterFields)) {
|
|
928
|
+
if (params.genericFilterFields && params.genericFilterValue) {
|
|
929
|
+
queryBuilder.andWhere(`f.${params.genericFilterFields} LIKE :genericFilterValue`, {
|
|
930
|
+
genericFilterValue: `%${params.genericFilterValue}%`,
|
|
931
|
+
});
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
const applyDynamicFilters = (queryBuilder, filters, logicOperator) => {
|
|
935
|
+
filters.forEach((filter, index) => {
|
|
936
|
+
const { field, operator, value } = filter;
|
|
937
|
+
const queryField = `f.${field}`;
|
|
938
|
+
const parameterName = `filterValue${index}`;
|
|
939
|
+
let condition;
|
|
940
|
+
switch (operator) {
|
|
941
|
+
case 'contains':
|
|
942
|
+
condition = `${queryField} LIKE :${parameterName}`;
|
|
943
|
+
queryBuilder.setParameter(parameterName, `%${value}%`);
|
|
944
|
+
break;
|
|
945
|
+
case 'equals':
|
|
946
|
+
condition = `${queryField} = :${parameterName}`;
|
|
947
|
+
queryBuilder.setParameter(parameterName, value);
|
|
948
|
+
break;
|
|
949
|
+
case 'startsWith':
|
|
950
|
+
condition = `${queryField} LIKE :${parameterName}`;
|
|
951
|
+
queryBuilder.setParameter(parameterName, `${value}%`);
|
|
952
|
+
break;
|
|
953
|
+
case 'endsWith':
|
|
954
|
+
condition = `${queryField} LIKE :${parameterName}`;
|
|
955
|
+
queryBuilder.setParameter(parameterName, `%${value}`);
|
|
956
|
+
break;
|
|
957
|
+
case 'isEmpty':
|
|
958
|
+
condition = `${queryField} IS NULL OR ${queryField} = ''`;
|
|
959
|
+
break;
|
|
960
|
+
case 'isNotEmpty':
|
|
961
|
+
condition = `${queryField} IS NOT NULL AND ${queryField} <> ''`;
|
|
962
|
+
break;
|
|
963
|
+
case 'isAnyOf':
|
|
964
|
+
condition = `${queryField} IN (:...${parameterName})`;
|
|
965
|
+
queryBuilder.setParameter(parameterName, value.split(','));
|
|
966
|
+
break;
|
|
967
|
+
default:
|
|
968
|
+
throw new Error(`Operator ${operator} is not supported.`);
|
|
969
|
+
}
|
|
970
|
+
if (index === 0) {
|
|
971
|
+
queryBuilder.andWhere(condition);
|
|
972
|
+
}
|
|
973
|
+
else {
|
|
974
|
+
queryBuilder[logicOperator === 'OR' ? 'orWhere' : 'andWhere'](condition);
|
|
975
|
+
}
|
|
976
|
+
});
|
|
977
|
+
};
|
|
978
|
+
// Aplicar filtros dinámicos
|
|
979
|
+
applyDynamicFilters(queryBuilder, filters, logicOperator);
|
|
980
|
+
queryBuilder.groupBy([
|
|
981
|
+
"f.flow_id",
|
|
982
|
+
"f.vendor_id",
|
|
983
|
+
"f.code",
|
|
984
|
+
"f.name",
|
|
985
|
+
"f.enabled",
|
|
986
|
+
"f.type",
|
|
987
|
+
"f.created_by",
|
|
988
|
+
"f.user_id_ai",
|
|
989
|
+
"f.user_ai",
|
|
990
|
+
"f.modified_by",
|
|
991
|
+
"f.created_at",
|
|
992
|
+
"f.modified_at",
|
|
993
|
+
"f.is_active",
|
|
994
|
+
"f.description",
|
|
995
|
+
"f.icon",
|
|
996
|
+
"f.status",
|
|
997
|
+
]);
|
|
998
|
+
// Ordenamiento y paginación
|
|
999
|
+
queryBuilder.orderBy(`f.${params.sort || "flowId"}`, params.dir || "ASC");
|
|
1000
|
+
queryBuilder.limit(params.limit || 50).offset(params.start || 0);
|
|
1001
|
+
// Obtener los datos
|
|
1002
|
+
const data = await queryBuilder.getRawMany();
|
|
1003
|
+
// Query para contar registros
|
|
1004
|
+
const countQuery = await (0, typeorm_1.getManager)()
|
|
1005
|
+
.createQueryBuilder()
|
|
1006
|
+
.select("COUNT(f.flow_id)", "count")
|
|
1007
|
+
.from("twf_flow", "f");
|
|
1008
|
+
if (isActive !== undefined) {
|
|
1009
|
+
countQuery.where("f.is_active = :isActive", { isActive });
|
|
1010
|
+
}
|
|
1011
|
+
if (publish !== undefined) {
|
|
1012
|
+
countQuery.where("f.publish = :publish", { publish });
|
|
1013
|
+
}
|
|
1014
|
+
if (type) {
|
|
1015
|
+
countQuery.andWhere("f.type = :type", { type });
|
|
1016
|
+
}
|
|
1017
|
+
if (templateType) {
|
|
1018
|
+
countQuery.andWhere("f.template_type = :templateType", { templateType });
|
|
1019
|
+
}
|
|
1020
|
+
if (vendorIds.length > 0) {
|
|
1021
|
+
countQuery.andWhere("f.vendor_id IN (:...vendorIds)", { vendorIds });
|
|
1022
|
+
}
|
|
1023
|
+
if (allowedColumns.includes(params.genericFilterFields)) {
|
|
1024
|
+
if (params.genericFilterFields && params.genericFilterValue) {
|
|
1025
|
+
countQuery.andWhere(`f.${params.genericFilterFields} LIKE :genericFilterValue`, {
|
|
1026
|
+
genericFilterValue: `%${params.genericFilterValue}%`,
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
// Aplicar filtros dinámicos en el conteo
|
|
1031
|
+
applyDynamicFilters(countQuery, filters, logicOperator);
|
|
1032
|
+
const totalCount = await countQuery.getRawOne();
|
|
1033
|
+
return { data, count: totalCount.count };
|
|
1034
|
+
}
|
|
1035
|
+
async changePublishTemplate(params, manager) {
|
|
1036
|
+
let dataFlow = await (0, core_1.__)(Flow_1.default.findOne(params.flowId));
|
|
1037
|
+
if (dataFlow) {
|
|
1038
|
+
console.log("publish es:::::::::", dataFlow.publish);
|
|
1039
|
+
if (dataFlow.publish === 'N') {
|
|
1040
|
+
await this.validatePublishTemplate(params.flowId, manager, 'Y');
|
|
1041
|
+
//change to active
|
|
1042
|
+
dataFlow.publish = 'Y';
|
|
1043
|
+
}
|
|
1044
|
+
else {
|
|
1045
|
+
await this.validatePublishTemplate(params.flowId, manager, 'N');
|
|
1046
|
+
dataFlow.publish = 'N';
|
|
1047
|
+
}
|
|
1048
|
+
dataFlow.modifiedAt = new Date();
|
|
1049
|
+
dataFlow.modifiedBy = this.user.username;
|
|
1050
|
+
const updFlow = await (0, core_1.__)(manager.save(dataFlow));
|
|
1051
|
+
return { success: true };
|
|
1052
|
+
}
|
|
1053
|
+
else {
|
|
1054
|
+
return { success: false };
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
async validatePublishTemplate(flowId, manager, publish) {
|
|
1058
|
+
if (publish == 'Y') {
|
|
1059
|
+
const nodes = await Node_1.default.find({ flowId, isActive: true });
|
|
1060
|
+
let res = '';
|
|
1061
|
+
if (nodes.length < 2) {
|
|
1062
|
+
throw new core_1.PxpError(400, 'Your template must have at least 2 steps. Please finish configuring it before publish');
|
|
1063
|
+
}
|
|
1064
|
+
return true;
|
|
1065
|
+
}
|
|
1066
|
+
else {
|
|
1067
|
+
return true;
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
876
1070
|
};
|
|
877
1071
|
__decorate([
|
|
878
1072
|
(0, core_1.Get)(),
|
|
@@ -974,6 +1168,24 @@ __decorate([
|
|
|
974
1168
|
__metadata("design:paramtypes", [Object]),
|
|
975
1169
|
__metadata("design:returntype", Promise)
|
|
976
1170
|
], Flow.prototype, "basicFlowList", null);
|
|
1171
|
+
__decorate([
|
|
1172
|
+
(0, core_1.Get)(""),
|
|
1173
|
+
(0, core_1.DbSettings)("Orm"),
|
|
1174
|
+
(0, core_1.ReadOnly)(true),
|
|
1175
|
+
(0, core_1.Log)(true),
|
|
1176
|
+
__metadata("design:type", Function),
|
|
1177
|
+
__metadata("design:paramtypes", [Object]),
|
|
1178
|
+
__metadata("design:returntype", Promise)
|
|
1179
|
+
], Flow.prototype, "listTemplates", null);
|
|
1180
|
+
__decorate([
|
|
1181
|
+
(0, core_1.Post)(),
|
|
1182
|
+
(0, core_1.DbSettings)('Orm'),
|
|
1183
|
+
(0, core_1.ReadOnly)(false),
|
|
1184
|
+
(0, core_1.Log)(true),
|
|
1185
|
+
__metadata("design:type", Function),
|
|
1186
|
+
__metadata("design:paramtypes", [Object, typeorm_1.EntityManager]),
|
|
1187
|
+
__metadata("design:returntype", Promise)
|
|
1188
|
+
], Flow.prototype, "changePublishTemplate", null);
|
|
977
1189
|
Flow = __decorate([
|
|
978
1190
|
(0, core_1.Model)('flow-nd/Flow')
|
|
979
1191
|
], Flow);
|
package/dist/entity/Flow.d.ts
CHANGED
package/dist/entity/Flow.js
CHANGED
|
@@ -25,6 +25,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
* 04-Sep-2023 SP08SEP23 Rensi Arteaga add modified at and by
|
|
26
26
|
* 06-Dec-2024 8001237262 Mercedes Zambrana add flow_type
|
|
27
27
|
* 31-Jan-2025 8035304698 Mercedes Zambrana Change code to string
|
|
28
|
+
* 18-Feb-2025 8501163144 Mercedes Zambrana Add publish column
|
|
28
29
|
****************************************************************************/
|
|
29
30
|
const typeorm_1 = require("typeorm");
|
|
30
31
|
const FlowInstance_1 = __importDefault(require("./FlowInstance"));
|
|
@@ -92,6 +93,10 @@ __decorate([
|
|
|
92
93
|
(0, typeorm_1.Column)({ name: 'flow_type', type: 'varchar', nullable: true, length: 100 }),
|
|
93
94
|
__metadata("design:type", String)
|
|
94
95
|
], Flow.prototype, "flowType", void 0);
|
|
96
|
+
__decorate([
|
|
97
|
+
(0, typeorm_1.Column)({ name: 'publish', type: 'varchar', nullable: false, length: 1 }),
|
|
98
|
+
__metadata("design:type", String)
|
|
99
|
+
], Flow.prototype, "publish", void 0);
|
|
95
100
|
Flow = __decorate([
|
|
96
101
|
(0, typeorm_1.Entity)({ name: 'twf_flow' })
|
|
97
102
|
], Flow);
|