Merged in release/2022-11-10 (pull request #624)
release/2022-11-10 Approved-by: Patrick Fic
This commit is contained in:
@@ -3769,6 +3769,27 @@
|
|||||||
- active:
|
- active:
|
||||||
_eq: true
|
_eq: true
|
||||||
event_triggers:
|
event_triggers:
|
||||||
|
- name: job_status_transition
|
||||||
|
definition:
|
||||||
|
enable_manual: false
|
||||||
|
insert:
|
||||||
|
columns: '*'
|
||||||
|
update:
|
||||||
|
columns:
|
||||||
|
- status
|
||||||
|
retry_conf:
|
||||||
|
interval_sec: 10
|
||||||
|
num_retries: 0
|
||||||
|
timeout_sec: 60
|
||||||
|
webhook_from_env: HASURA_API_URL
|
||||||
|
headers:
|
||||||
|
- name: event-secret
|
||||||
|
value_from_env: EVENT_SECRET
|
||||||
|
request_transform:
|
||||||
|
query_params: {}
|
||||||
|
template_engine: Kriti
|
||||||
|
url: '{{$base_url}}/job/statustransition'
|
||||||
|
version: 2
|
||||||
- name: jobs_arms
|
- name: jobs_arms
|
||||||
definition:
|
definition:
|
||||||
enable_manual: false
|
enable_manual: false
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ var job = require("./server/job/job");
|
|||||||
app.post("/job/totals", fb.validateFirebaseIdToken, job.totals);
|
app.post("/job/totals", fb.validateFirebaseIdToken, job.totals);
|
||||||
app.post(
|
app.post(
|
||||||
"/job/statustransition",
|
"/job/statustransition",
|
||||||
fb.validateFirebaseIdToken,
|
// fb.validateFirebaseIdToken,
|
||||||
job.statustransition
|
job.statustransition
|
||||||
);
|
);
|
||||||
app.post("/job/totalsssu", fb.validateFirebaseIdToken, job.totalsSsu);
|
app.post("/job/totalsssu", fb.validateFirebaseIdToken, job.totalsSsu);
|
||||||
|
|||||||
@@ -7,22 +7,29 @@ const logger = require("../utils/logger");
|
|||||||
// Dinero.defaultCurrency = "USD";
|
// Dinero.defaultCurrency = "USD";
|
||||||
// Dinero.globalLocale = "en-CA";
|
// Dinero.globalLocale = "en-CA";
|
||||||
Dinero.globalRoundingMode = "HALF_EVEN";
|
Dinero.globalRoundingMode = "HALF_EVEN";
|
||||||
|
const path = require("path");
|
||||||
|
const client = require("../graphql-client/graphql-client").client;
|
||||||
|
require("dotenv").config({
|
||||||
|
path: path.resolve(
|
||||||
|
process.cwd(),
|
||||||
|
`.env.${process.env.NODE_ENV || "development"}`
|
||||||
|
),
|
||||||
|
});
|
||||||
async function StatusTransition(req, res) {
|
async function StatusTransition(req, res) {
|
||||||
const { jobid, value, bodyshopid } = req.body;
|
if (req.headers["event-secret"] !== process.env.EVENT_SECRET) {
|
||||||
|
res.status(403).send("Unauthorized");
|
||||||
const BearerToken = req.headers.authorization;
|
return;
|
||||||
logger.log("job-costing-start", "DEBUG", req.user.email, jobid, null);
|
}
|
||||||
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {
|
|
||||||
headers: {
|
|
||||||
Authorization: BearerToken,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
|
const {
|
||||||
|
id: jobid,
|
||||||
|
status: value,
|
||||||
|
shopid: bodyshopid,
|
||||||
|
} = req.body.event.data.new;
|
||||||
try {
|
try {
|
||||||
const { update_transitions } = await client
|
const { update_transitions } = await client.request(
|
||||||
.setHeaders({ Authorization: BearerToken })
|
queries.UPDATE_OLD_TRANSITION,
|
||||||
.request(queries.UPDATE_OLD_TRANSITION, {
|
{
|
||||||
jobid: jobid,
|
jobid: jobid,
|
||||||
existingTransition: {
|
existingTransition: {
|
||||||
end: new Date(),
|
end: new Date(),
|
||||||
@@ -30,7 +37,8 @@ async function StatusTransition(req, res) {
|
|||||||
|
|
||||||
//duration
|
//duration
|
||||||
},
|
},
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
let duration =
|
let duration =
|
||||||
update_transitions.affected_rows === 0
|
update_transitions.affected_rows === 0
|
||||||
@@ -38,29 +46,27 @@ async function StatusTransition(req, res) {
|
|||||||
: new Date(update_transitions.returning[0].end) -
|
: new Date(update_transitions.returning[0].end) -
|
||||||
new Date(update_transitions.returning[0].start);
|
new Date(update_transitions.returning[0].start);
|
||||||
|
|
||||||
const resp2 = await client
|
const resp2 = await client.request(queries.INSERT_NEW_TRANSITION, {
|
||||||
.setHeaders({ Authorization: BearerToken })
|
oldTransitionId:
|
||||||
.request(queries.INSERT_NEW_TRANSITION, {
|
update_transitions.affected_rows === 0
|
||||||
oldTransitionId:
|
? null
|
||||||
|
: update_transitions.returning[0].id,
|
||||||
|
duration,
|
||||||
|
newTransition: {
|
||||||
|
bodyshopid: bodyshopid,
|
||||||
|
jobid: jobid,
|
||||||
|
start:
|
||||||
|
update_transitions.affected_rows === 0
|
||||||
|
? new Date()
|
||||||
|
: update_transitions.returning[0].end,
|
||||||
|
prev_value:
|
||||||
update_transitions.affected_rows === 0
|
update_transitions.affected_rows === 0
|
||||||
? null
|
? null
|
||||||
: update_transitions.returning[0].id,
|
: update_transitions.returning[0].value,
|
||||||
duration,
|
value: value,
|
||||||
newTransition: {
|
type: "status",
|
||||||
bodyshopid: bodyshopid,
|
},
|
||||||
jobid: jobid,
|
});
|
||||||
start:
|
|
||||||
update_transitions.affected_rows === 0
|
|
||||||
? new Date()
|
|
||||||
: update_transitions.returning[0].end,
|
|
||||||
prev_value:
|
|
||||||
update_transitions.affected_rows === 0
|
|
||||||
? null
|
|
||||||
: update_transitions.returning[0].value,
|
|
||||||
value: value,
|
|
||||||
type: "status",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
//Check to see if there is an existing status transition record.
|
//Check to see if there is an existing status transition record.
|
||||||
//Query using Job ID, start is not null, end is null.
|
//Query using Job ID, start is not null, end is null.
|
||||||
|
|||||||
Reference in New Issue
Block a user