Skip to content

Commit

Permalink
hotfix: processes by idFlow
Browse files Browse the repository at this point in the history
  • Loading branch information
senaarth committed Jul 2, 2023
1 parent 6f4ab6e commit 7e6640e
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/controllers/ProcessController.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,19 +220,38 @@ class ProcessController {
try {
const { idFlow } = req.params;

const offset = parseInt(req.query.offset) || 0;
const limit = parseInt(req.query.limit) || 10;

const processes = await Database.connection.query(
'SELECT * FROM \
"flowProcess" \
JOIN "process" ON \
"flowProcess".record = process.record \
WHERE "flowProcess"."idFlow" = ? \
OFFSET ? \
LIMIT ?',
{
replacements: [idFlow, offset, limit],
type: QueryTypes.SELECT,
}
);
const countQuery = await Database.connection.query(
'SELECT COUNT(*) as total FROM \
"flowProcess" \
JOIN "process" ON \
"flowProcess".record = process.record \
WHERE "flowProcess"."idFlow" = ?',
{
replacements: [idFlow],
type: QueryTypes.SELECT,
}
);

const totalCount = countQuery[0].total;
const totalPages = Math.ceil(totalCount / limit) || 0;

return res.status(200).json(processes);
return res.status(200).json({ processes, totalPages });
} catch (error) {
return res
.status(500)
Expand Down Expand Up @@ -272,9 +291,9 @@ class ProcessController {
const startingProcess =
process.status === "notStarted" && status === "inProgress"
? {
idStage: flowStages[0].idStageA,
effectiveDate: new Date(),
}
idStage: flowStages[0].idStageA,
effectiveDate: new Date(),
}
: {};
let tempProgress = [];
if (process.status === "notStarted" && status === "inProgress") {
Expand All @@ -286,7 +305,7 @@ class ProcessController {
const stageEndDate = new Date(stageStartDate);
stageEndDate.setDate(
stageEndDate.getDate() +
handleVerifyDate(stageStartDate, currentStage.duration)
handleVerifyDate(stageStartDate, currentStage.duration)
);

const progressData = {
Expand Down Expand Up @@ -411,7 +430,7 @@ class ProcessController {
const stageEndDate = new Date(stageStartDate);
stageEndDate.setDate(
stageEndDate.getDate() +
handleVerifyDate(stageStartDate, currentToStage.duration)
handleVerifyDate(stageStartDate, currentToStage.duration)
);

maturityDate = stageEndDate;
Expand Down

0 comments on commit 7e6640e

Please sign in to comment.