@pxp-nd/flow 1.1.3 → 1.1.5

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.
@@ -40,5 +40,6 @@ declare class Flow extends Controller {
40
40
  changeStatusFlow(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
41
41
  validateFlow(flowId: number, manager: EntityManager, status: string): Promise<unknown>;
42
42
  basicFlowList(params: Record<string, any>): Promise<unknown>;
43
+ listTemplates(params: Record<string, any>): Promise<unknown>;
43
44
  }
44
45
  export default Flow;
@@ -326,29 +326,25 @@ let Flow = class Flow extends core_1.Controller {
326
326
  }
327
327
  }
328
328
  if (flowIdDel.action.actionType.name === 'CHAINED FLOW') {
329
- console.log('CHAINED');
330
329
  if (((_a = flowIdDel.action) === null || _a === void 0 ? void 0 : _a.configJsonTemplate) && flowIdDel.actionConfigJson) {
331
330
  try {
332
331
  const parsedConfig = JSON.parse(flowIdDel.action.configJsonTemplate);
333
332
  const parsedValues = JSON.parse(flowIdDel.actionConfigJson);
334
- console.log('parsedConfig', parsedConfig);
335
- console.log('parsedValues', parsedValues);
336
333
  if (parsedConfig.deleteController && parsedValues.flowId) {
337
334
  const params = {
338
335
  flowId: parsedValues.flowId,
339
336
  };
340
- console.log('params', params);
341
337
  const config = {
342
338
  method: "post",
343
- url: `http://localhost:${process.env.PORT}/api/${parsedConfig.addController}`,
339
+ url: `http://localhost:${process.env.PORT}/api/${parsedConfig.deleteController}`,
344
340
  headers: {
345
341
  Authorization: "" + process.env.TOKEN_PXP_ND + "",
346
342
  "Content-Type": "application/json",
347
343
  },
348
344
  data: params,
349
345
  };
350
- console.log('config', config);
351
346
  const resControllerAxios = await (0, axios_1.default)(config);
347
+ console.log('resControllerAxios.data', resControllerAxios.data);
352
348
  }
353
349
  }
354
350
  catch (error) {
@@ -877,6 +873,157 @@ let Flow = class Flow extends core_1.Controller {
877
873
  const count = totalCount.count;
878
874
  return { data, count };
879
875
  }
876
+ async listTemplates(params) {
877
+ var _a;
878
+ const isActive = params._isActive;
879
+ const type = params._type || "template"; // Filtrar solo templates
880
+ const vendorIds = params._vendorId ? params._vendorId.split(",").map(Number) : [];
881
+ const templateType = params._templateType;
882
+ const allowedColumns = ["name", "description"];
883
+ const filter = (params === null || params === void 0 ? void 0 : params.filter) ? JSON.parse(params === null || params === void 0 ? void 0 : params.filter) : null;
884
+ const filters = (filter === null || filter === void 0 ? void 0 : filter.items) || [];
885
+ const logicOperator = ((_a = filter === null || filter === void 0 ? void 0 : filter.logicOperator) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || "AND";
886
+ const queryBuilder = await (0, typeorm_1.getManager)()
887
+ .createQueryBuilder()
888
+ .select([
889
+ "f.flow_id as flowId",
890
+ "f.vendor_id as vendorId",
891
+ "f.code as code",
892
+ "f.name as name",
893
+ "f.enabled as enabled",
894
+ "f.type as type",
895
+ "f.created_by as createdBy",
896
+ "f.user_id_ai as userIdAi",
897
+ "f.user_ai as userAi",
898
+ "f.modified_by as modifiedBy",
899
+ "f.created_at as createdAt",
900
+ "f.modified_at as modifiedAt",
901
+ "f.is_active as isActive",
902
+ "f.description as description",
903
+ "f.icon as icon",
904
+ "f.status as status",
905
+ "COUNT(fi.flow_instance_id) AS numberOfInstance",
906
+ ])
907
+ .from("twf_flow", "f")
908
+ .leftJoin("twf_flow_instance", "fi", "fi.flow_id = f.flow_id");
909
+ // Aplicar filtros
910
+ if (isActive !== undefined) {
911
+ queryBuilder.where("f.is_active = :isActive", { isActive });
912
+ }
913
+ if (type) {
914
+ queryBuilder.andWhere("f.type = :type", { type });
915
+ }
916
+ if (templateType) {
917
+ queryBuilder.andWhere("f.template_type = :templateType", { templateType });
918
+ }
919
+ if (vendorIds.length > 0) {
920
+ queryBuilder.andWhere("f.vendor_id IN (:...vendorIds)", { vendorIds });
921
+ }
922
+ if (allowedColumns.includes(params.genericFilterFields)) {
923
+ if (params.genericFilterFields && params.genericFilterValue) {
924
+ queryBuilder.andWhere(`f.${params.genericFilterFields} LIKE :genericFilterValue`, {
925
+ genericFilterValue: `%${params.genericFilterValue}%`,
926
+ });
927
+ }
928
+ }
929
+ const applyDynamicFilters = (queryBuilder, filters, logicOperator) => {
930
+ filters.forEach((filter, index) => {
931
+ const { field, operator, value } = filter;
932
+ const queryField = `f.${field}`;
933
+ const parameterName = `filterValue${index}`;
934
+ let condition;
935
+ switch (operator) {
936
+ case 'contains':
937
+ condition = `${queryField} LIKE :${parameterName}`;
938
+ queryBuilder.setParameter(parameterName, `%${value}%`);
939
+ break;
940
+ case 'equals':
941
+ condition = `${queryField} = :${parameterName}`;
942
+ queryBuilder.setParameter(parameterName, value);
943
+ break;
944
+ case 'startsWith':
945
+ condition = `${queryField} LIKE :${parameterName}`;
946
+ queryBuilder.setParameter(parameterName, `${value}%`);
947
+ break;
948
+ case 'endsWith':
949
+ condition = `${queryField} LIKE :${parameterName}`;
950
+ queryBuilder.setParameter(parameterName, `%${value}`);
951
+ break;
952
+ case 'isEmpty':
953
+ condition = `${queryField} IS NULL OR ${queryField} = ''`;
954
+ break;
955
+ case 'isNotEmpty':
956
+ condition = `${queryField} IS NOT NULL AND ${queryField} <> ''`;
957
+ break;
958
+ case 'isAnyOf':
959
+ condition = `${queryField} IN (:...${parameterName})`;
960
+ queryBuilder.setParameter(parameterName, value.split(','));
961
+ break;
962
+ default:
963
+ throw new Error(`Operator ${operator} is not supported.`);
964
+ }
965
+ if (index === 0) {
966
+ queryBuilder.andWhere(condition);
967
+ }
968
+ else {
969
+ queryBuilder[logicOperator === 'OR' ? 'orWhere' : 'andWhere'](condition);
970
+ }
971
+ });
972
+ };
973
+ // Aplicar filtros dinámicos
974
+ applyDynamicFilters(queryBuilder, filters, logicOperator);
975
+ queryBuilder.groupBy([
976
+ "f.flow_id",
977
+ "f.vendor_id",
978
+ "f.code",
979
+ "f.name",
980
+ "f.enabled",
981
+ "f.type",
982
+ "f.created_by",
983
+ "f.user_id_ai",
984
+ "f.user_ai",
985
+ "f.modified_by",
986
+ "f.created_at",
987
+ "f.modified_at",
988
+ "f.is_active",
989
+ "f.description",
990
+ "f.icon",
991
+ "f.status",
992
+ ]);
993
+ // Ordenamiento y paginación
994
+ queryBuilder.orderBy(`f.${params.sort || "flowId"}`, params.dir || "ASC");
995
+ queryBuilder.limit(params.limit || 50).offset(params.start || 0);
996
+ // Obtener los datos
997
+ const data = await queryBuilder.getRawMany();
998
+ // Query para contar registros
999
+ const countQuery = await (0, typeorm_1.getManager)()
1000
+ .createQueryBuilder()
1001
+ .select("COUNT(f.flow_id)", "count")
1002
+ .from("twf_flow", "f");
1003
+ if (isActive !== undefined) {
1004
+ countQuery.where("f.is_active = :isActive", { isActive });
1005
+ }
1006
+ if (type) {
1007
+ countQuery.andWhere("f.type = :type", { type });
1008
+ }
1009
+ if (templateType) {
1010
+ countQuery.andWhere("f.template_type = :templateType", { templateType });
1011
+ }
1012
+ if (vendorIds.length > 0) {
1013
+ countQuery.andWhere("f.vendor_id IN (:...vendorIds)", { vendorIds });
1014
+ }
1015
+ if (allowedColumns.includes(params.genericFilterFields)) {
1016
+ if (params.genericFilterFields && params.genericFilterValue) {
1017
+ countQuery.andWhere(`f.${params.genericFilterFields} LIKE :genericFilterValue`, {
1018
+ genericFilterValue: `%${params.genericFilterValue}%`,
1019
+ });
1020
+ }
1021
+ }
1022
+ // Aplicar filtros dinámicos en el conteo
1023
+ applyDynamicFilters(countQuery, filters, logicOperator);
1024
+ const totalCount = await countQuery.getRawOne();
1025
+ return { data, count: totalCount.count };
1026
+ }
880
1027
  };
881
1028
  __decorate([
882
1029
  (0, core_1.Get)(),
@@ -978,6 +1125,15 @@ __decorate([
978
1125
  __metadata("design:paramtypes", [Object]),
979
1126
  __metadata("design:returntype", Promise)
980
1127
  ], Flow.prototype, "basicFlowList", null);
1128
+ __decorate([
1129
+ (0, core_1.Get)(""),
1130
+ (0, core_1.DbSettings)("Orm"),
1131
+ (0, core_1.ReadOnly)(true),
1132
+ (0, core_1.Log)(true),
1133
+ __metadata("design:type", Function),
1134
+ __metadata("design:paramtypes", [Object]),
1135
+ __metadata("design:returntype", Promise)
1136
+ ], Flow.prototype, "listTemplates", null);
981
1137
  Flow = __decorate([
982
1138
  (0, core_1.Model)('flow-nd/Flow')
983
1139
  ], Flow);
@@ -17,5 +17,4 @@ export default class Flow extends PxpEntity {
17
17
  modifiedBy: string;
18
18
  templateType: string;
19
19
  flowType: string;
20
- isActiveFlow: number;
21
20
  }
@@ -25,8 +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
- * 11-Feb-2025 8353091310 Merecedes Zambrana Add isActive
29
- ****************************************************************************/
28
+ ****************************************************************************/
30
29
  const typeorm_1 = require("typeorm");
31
30
  const FlowInstance_1 = __importDefault(require("./FlowInstance"));
32
31
  const Node_1 = __importDefault(require("./Node"));
@@ -93,10 +92,6 @@ __decorate([
93
92
  (0, typeorm_1.Column)({ name: 'flow_type', type: 'varchar', nullable: true, length: 100 }),
94
93
  __metadata("design:type", String)
95
94
  ], Flow.prototype, "flowType", void 0);
96
- __decorate([
97
- (0, typeorm_1.Column)({ name: 'is_active', type: 'int', nullable: false }),
98
- __metadata("design:type", Number)
99
- ], Flow.prototype, "isActiveFlow", void 0);
100
95
  Flow = __decorate([
101
96
  (0, typeorm_1.Entity)({ name: 'twf_flow' })
102
97
  ], Flow);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pxp-nd/flow",
3
- "version": "1.1.03",
3
+ "version": "1.1.05",
4
4
  "description": "Workflow module for pxp-nd framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",