@pxp-nd/flow 1.1.5 → 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.
@@ -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';
@@ -41,5 +42,7 @@ declare class Flow extends Controller {
41
42
  validateFlow(flowId: number, manager: EntityManager, status: string): Promise<unknown>;
42
43
  basicFlowList(params: Record<string, any>): Promise<unknown>;
43
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>;
44
47
  }
45
48
  export default Flow;
@@ -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) {
@@ -883,6 +884,7 @@ let Flow = class Flow extends core_1.Controller {
883
884
  const filter = (params === null || params === void 0 ? void 0 : params.filter) ? JSON.parse(params === null || params === void 0 ? void 0 : params.filter) : null;
884
885
  const filters = (filter === null || filter === void 0 ? void 0 : filter.items) || [];
885
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;
886
888
  const queryBuilder = await (0, typeorm_1.getManager)()
887
889
  .createQueryBuilder()
888
890
  .select([
@@ -910,6 +912,9 @@ let Flow = class Flow extends core_1.Controller {
910
912
  if (isActive !== undefined) {
911
913
  queryBuilder.where("f.is_active = :isActive", { isActive });
912
914
  }
915
+ if (publish !== undefined) {
916
+ queryBuilder.where("f.publish = :publish", { publish });
917
+ }
913
918
  if (type) {
914
919
  queryBuilder.andWhere("f.type = :type", { type });
915
920
  }
@@ -1003,6 +1008,9 @@ let Flow = class Flow extends core_1.Controller {
1003
1008
  if (isActive !== undefined) {
1004
1009
  countQuery.where("f.is_active = :isActive", { isActive });
1005
1010
  }
1011
+ if (publish !== undefined) {
1012
+ countQuery.where("f.publish = :publish", { publish });
1013
+ }
1006
1014
  if (type) {
1007
1015
  countQuery.andWhere("f.type = :type", { type });
1008
1016
  }
@@ -1024,6 +1032,41 @@ let Flow = class Flow extends core_1.Controller {
1024
1032
  const totalCount = await countQuery.getRawOne();
1025
1033
  return { data, count: totalCount.count };
1026
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
+ }
1027
1070
  };
1028
1071
  __decorate([
1029
1072
  (0, core_1.Get)(),
@@ -1134,6 +1177,15 @@ __decorate([
1134
1177
  __metadata("design:paramtypes", [Object]),
1135
1178
  __metadata("design:returntype", Promise)
1136
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);
1137
1189
  Flow = __decorate([
1138
1190
  (0, core_1.Model)('flow-nd/Flow')
1139
1191
  ], Flow);
@@ -17,4 +17,5 @@ export default class Flow extends PxpEntity {
17
17
  modifiedBy: string;
18
18
  templateType: string;
19
19
  flowType: string;
20
+ publish: string;
20
21
  }
@@ -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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pxp-nd/flow",
3
- "version": "1.1.05",
3
+ "version": "1.1.06",
4
4
  "description": "Workflow module for pxp-nd framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",