@pxp-nd/flow 1.1.4 → 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.
- package/dist/controllers/Flow.d.ts +1 -0
- package/dist/controllers/Flow.js +160 -0
- package/package.json +1 -1
|
@@ -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;
|
package/dist/controllers/Flow.js
CHANGED
|
@@ -873,6 +873,157 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
873
873
|
const count = totalCount.count;
|
|
874
874
|
return { data, count };
|
|
875
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
|
+
}
|
|
876
1027
|
};
|
|
877
1028
|
__decorate([
|
|
878
1029
|
(0, core_1.Get)(),
|
|
@@ -974,6 +1125,15 @@ __decorate([
|
|
|
974
1125
|
__metadata("design:paramtypes", [Object]),
|
|
975
1126
|
__metadata("design:returntype", Promise)
|
|
976
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);
|
|
977
1137
|
Flow = __decorate([
|
|
978
1138
|
(0, core_1.Model)('flow-nd/Flow')
|
|
979
1139
|
], Flow);
|