Resolved duplicate vehicles uniqueness constraint on initial import BOD-397
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useMutation, useQuery } from "@apollo/react-hooks";
|
import { useApolloClient, useMutation, useQuery } from "@apollo/react-hooks";
|
||||||
import { notification } from "antd";
|
import { notification } from "antd";
|
||||||
import Axios from "axios";
|
import Axios from "axios";
|
||||||
import Dinero from "dinero.js";
|
import Dinero from "dinero.js";
|
||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
QUERY_AVAILABLE_NEW_JOBS,
|
QUERY_AVAILABLE_NEW_JOBS,
|
||||||
} from "../../graphql/available-jobs.queries";
|
} from "../../graphql/available-jobs.queries";
|
||||||
import { INSERT_NEW_JOB } from "../../graphql/jobs.queries";
|
import { INSERT_NEW_JOB } from "../../graphql/jobs.queries";
|
||||||
|
import { SEARCH_VEHICLE_BY_VIN } from "../../graphql/vehicles.queries";
|
||||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||||
import AlertComponent from "../alert/alert.component";
|
import AlertComponent from "../alert/alert.component";
|
||||||
import LoadingSpinner from "../loading-spinner/loading-spinner.component";
|
import LoadingSpinner from "../loading-spinner/loading-spinner.component";
|
||||||
@@ -39,6 +40,7 @@ export function JobsAvailableContainer({
|
|||||||
const [insertLoading, setInsertLoading] = useState(false);
|
const [insertLoading, setInsertLoading] = useState(false);
|
||||||
const [deleteAllNewJobs] = useMutation(DELETE_ALL_AVAILABLE_NEW_JOBS);
|
const [deleteAllNewJobs] = useMutation(DELETE_ALL_AVAILABLE_NEW_JOBS);
|
||||||
const [insertNewJob] = useMutation(INSERT_NEW_JOB);
|
const [insertNewJob] = useMutation(INSERT_NEW_JOB);
|
||||||
|
const client = useApolloClient();
|
||||||
const [loadEstData, estData] = estDataLazyLoad;
|
const [loadEstData, estData] = estDataLazyLoad;
|
||||||
|
|
||||||
const onModalOk = async () => {
|
const onModalOk = async () => {
|
||||||
@@ -59,63 +61,72 @@ export function JobsAvailableContainer({
|
|||||||
notification["error"]({
|
notification["error"]({
|
||||||
message: t("jobs.errors.creating", { error: "No job data present." }),
|
message: t("jobs.errors.creating", { error: "No job data present." }),
|
||||||
});
|
});
|
||||||
} else {
|
return;
|
||||||
const newTotals = (
|
}
|
||||||
await Axios.post("/job/totals", {
|
|
||||||
job: {
|
|
||||||
...estData.data.available_jobs_by_pk.est_data,
|
|
||||||
joblines: estData.data.available_jobs_by_pk.est_data.joblines.data,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
).data;
|
|
||||||
|
|
||||||
const newJob = {
|
const newTotals = (
|
||||||
...estData.data.available_jobs_by_pk.est_data,
|
await Axios.post("/job/totals", {
|
||||||
clm_total: Dinero(newTotals.totals.total_repairs).toFormat("0.00"),
|
job: {
|
||||||
owner_owing: Dinero(newTotals.custPayable.total).toFormat("0.00"),
|
...estData.data.available_jobs_by_pk.est_data,
|
||||||
job_totals: newTotals,
|
joblines: estData.data.available_jobs_by_pk.est_data.joblines.data,
|
||||||
queued_for_parts: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
insertNewJob({
|
|
||||||
variables: {
|
|
||||||
job: selectedOwner
|
|
||||||
? Object.assign(
|
|
||||||
{},
|
|
||||||
newJob,
|
|
||||||
{ owner: null },
|
|
||||||
{ ownerid: selectedOwner }
|
|
||||||
)
|
|
||||||
: newJob,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((r) => {
|
).data;
|
||||||
notification["success"]({
|
|
||||||
message: t("jobs.successes.created"),
|
|
||||||
onClick: () => {
|
|
||||||
history.push(
|
|
||||||
`/manage/jobs/${r.data.insert_jobs.returning[0].id}`
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
//Job has been inserted. Clean up the available jobs record.
|
|
||||||
|
|
||||||
deleteJob({
|
const existingVehicles = await client.query({
|
||||||
variables: { id: estData.data.available_jobs_by_pk.id },
|
query: SEARCH_VEHICLE_BY_VIN,
|
||||||
}).then((r) => {
|
variables: {
|
||||||
refetch();
|
vin: estData.data.available_jobs_by_pk.est_data.vehicle.data.v_vin,
|
||||||
setInsertLoading(false);
|
},
|
||||||
});
|
});
|
||||||
})
|
|
||||||
.catch((r) => {
|
const newJob = {
|
||||||
//error while inserting
|
...estData.data.available_jobs_by_pk.est_data,
|
||||||
notification["error"]({
|
clm_total: Dinero(newTotals.totals.total_repairs).toFormat("0.00"),
|
||||||
message: t("jobs.errors.creating", { error: r.message }),
|
owner_owing: Dinero(newTotals.totals.custPayable.total).toFormat("0.00"),
|
||||||
});
|
job_totals: newTotals,
|
||||||
|
queued_for_parts: true,
|
||||||
|
...(existingVehicles.data.vehicles.length > 0
|
||||||
|
? { vehicleid: existingVehicles.data.vehicles[0].id, vehicle: null }
|
||||||
|
: {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
insertNewJob({
|
||||||
|
variables: {
|
||||||
|
job: selectedOwner
|
||||||
|
? Object.assign(
|
||||||
|
{},
|
||||||
|
newJob,
|
||||||
|
{ owner: null },
|
||||||
|
{ ownerid: selectedOwner }
|
||||||
|
)
|
||||||
|
: newJob,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then((r) => {
|
||||||
|
notification["success"]({
|
||||||
|
message: t("jobs.successes.created"),
|
||||||
|
onClick: () => {
|
||||||
|
history.push(`/manage/jobs/${r.data.insert_jobs.returning[0].id}`);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
//Job has been inserted. Clean up the available jobs record.
|
||||||
|
|
||||||
|
deleteJob({
|
||||||
|
variables: { id: estData.data.available_jobs_by_pk.id },
|
||||||
|
}).then((r) => {
|
||||||
refetch();
|
refetch();
|
||||||
setInsertLoading(false);
|
setInsertLoading(false);
|
||||||
});
|
});
|
||||||
}
|
})
|
||||||
|
.catch((r) => {
|
||||||
|
//error while inserting
|
||||||
|
notification["error"]({
|
||||||
|
message: t("jobs.errors.creating", { error: r.message }),
|
||||||
|
});
|
||||||
|
refetch();
|
||||||
|
setInsertLoading(false);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const onModalCancel = () => {
|
const onModalCancel = () => {
|
||||||
|
|||||||
@@ -62,7 +62,14 @@ export default function JobsAvailableSupplementComponent({
|
|||||||
sorter: (a, b) => alphaSort(a, b),
|
sorter: (a, b) => alphaSort(a, b),
|
||||||
sortOrder:
|
sortOrder:
|
||||||
state.sortedInfo.columnKey === "cieca_id" && state.sortedInfo.order,
|
state.sortedInfo.columnKey === "cieca_id" && state.sortedInfo.order,
|
||||||
render: (text, record) => <div>{record.job && record.job.ro_number}</div>,
|
render: (text, record) => (
|
||||||
|
<div>{`${(record.job && record.job.est_number) || ""}${
|
||||||
|
(record.job &&
|
||||||
|
record.job.ro_number &&
|
||||||
|
` / ${record.job.ro_number}`) ||
|
||||||
|
""
|
||||||
|
}`}</div>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: t("jobs.fields.owner"),
|
title: t("jobs.fields.owner"),
|
||||||
|
|||||||
@@ -102,7 +102,9 @@ export function JobsAvailableSupplementContainer({
|
|||||||
job: {
|
job: {
|
||||||
...supp,
|
...supp,
|
||||||
clm_total: Dinero(newTotals.totals.total_repairs).toFormat("0.00"),
|
clm_total: Dinero(newTotals.totals.total_repairs).toFormat("0.00"),
|
||||||
owner_owing: Dinero(newTotals.custPayable.total).toFormat("0.00"),
|
owner_owing: Dinero(newTotals.totals.custPayable.total).toFormat(
|
||||||
|
"0.00"
|
||||||
|
),
|
||||||
job_totals: newTotals,
|
job_totals: newTotals,
|
||||||
queued_for_parts: true,
|
queued_for_parts: true,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export const QUERY_AVAILABLE_NEW_JOBS = gql`
|
|||||||
supplement_number
|
supplement_number
|
||||||
updated_at
|
updated_at
|
||||||
uploaded_by
|
uploaded_by
|
||||||
|
ins_co_nm
|
||||||
vehicle_info
|
vehicle_info
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,10 +40,12 @@ export const QUERY_AVAILABLE_SUPPLEMENT_JOBS = gql`
|
|||||||
supplement_number
|
supplement_number
|
||||||
updated_at
|
updated_at
|
||||||
uploaded_by
|
uploaded_by
|
||||||
|
ins_co_nm
|
||||||
vehicle_info
|
vehicle_info
|
||||||
job {
|
job {
|
||||||
id
|
id
|
||||||
ro_number
|
ro_number
|
||||||
|
est_number
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
- args:
|
||||||
|
cascade: false
|
||||||
|
read_only: false
|
||||||
|
sql: ALTER TABLE "public"."available_jobs" DROP COLUMN "ins_co_nm";
|
||||||
|
type: run_sql
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
- args:
|
||||||
|
cascade: false
|
||||||
|
read_only: false
|
||||||
|
sql: ALTER TABLE "public"."available_jobs" ADD COLUMN "ins_co_nm" text NULL;
|
||||||
|
type: run_sql
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
- args:
|
||||||
|
role: user
|
||||||
|
table:
|
||||||
|
name: available_jobs
|
||||||
|
schema: public
|
||||||
|
type: drop_insert_permission
|
||||||
|
- args:
|
||||||
|
permission:
|
||||||
|
check:
|
||||||
|
bodyshop:
|
||||||
|
associations:
|
||||||
|
_and:
|
||||||
|
- user:
|
||||||
|
authid:
|
||||||
|
_eq: X-Hasura-User-Id
|
||||||
|
- active:
|
||||||
|
_eq: true
|
||||||
|
columns:
|
||||||
|
- id
|
||||||
|
- created_at
|
||||||
|
- updated_at
|
||||||
|
- uploaded_by
|
||||||
|
- cieca_id
|
||||||
|
- bodyshopid
|
||||||
|
- est_data
|
||||||
|
- issupplement
|
||||||
|
- jobid
|
||||||
|
- supplement_number
|
||||||
|
- ownr_name
|
||||||
|
- vehicle_info
|
||||||
|
- clm_amt
|
||||||
|
- clm_no
|
||||||
|
- source_system
|
||||||
|
set: {}
|
||||||
|
role: user
|
||||||
|
table:
|
||||||
|
name: available_jobs
|
||||||
|
schema: public
|
||||||
|
type: create_insert_permission
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
- args:
|
||||||
|
role: user
|
||||||
|
table:
|
||||||
|
name: available_jobs
|
||||||
|
schema: public
|
||||||
|
type: drop_insert_permission
|
||||||
|
- args:
|
||||||
|
permission:
|
||||||
|
check:
|
||||||
|
bodyshop:
|
||||||
|
associations:
|
||||||
|
_and:
|
||||||
|
- user:
|
||||||
|
authid:
|
||||||
|
_eq: X-Hasura-User-Id
|
||||||
|
- active:
|
||||||
|
_eq: true
|
||||||
|
columns:
|
||||||
|
- bodyshopid
|
||||||
|
- cieca_id
|
||||||
|
- clm_amt
|
||||||
|
- clm_no
|
||||||
|
- created_at
|
||||||
|
- est_data
|
||||||
|
- id
|
||||||
|
- ins_co_nm
|
||||||
|
- issupplement
|
||||||
|
- jobid
|
||||||
|
- ownr_name
|
||||||
|
- source_system
|
||||||
|
- supplement_number
|
||||||
|
- updated_at
|
||||||
|
- uploaded_by
|
||||||
|
- vehicle_info
|
||||||
|
set: {}
|
||||||
|
role: user
|
||||||
|
table:
|
||||||
|
name: available_jobs
|
||||||
|
schema: public
|
||||||
|
type: create_insert_permission
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
- args:
|
||||||
|
role: user
|
||||||
|
table:
|
||||||
|
name: available_jobs
|
||||||
|
schema: public
|
||||||
|
type: drop_select_permission
|
||||||
|
- args:
|
||||||
|
permission:
|
||||||
|
allow_aggregations: false
|
||||||
|
columns:
|
||||||
|
- issupplement
|
||||||
|
- supplement_number
|
||||||
|
- est_data
|
||||||
|
- clm_amt
|
||||||
|
- cieca_id
|
||||||
|
- clm_no
|
||||||
|
- ownr_name
|
||||||
|
- source_system
|
||||||
|
- uploaded_by
|
||||||
|
- vehicle_info
|
||||||
|
- created_at
|
||||||
|
- updated_at
|
||||||
|
- bodyshopid
|
||||||
|
- id
|
||||||
|
- jobid
|
||||||
|
computed_fields: []
|
||||||
|
filter:
|
||||||
|
bodyshop:
|
||||||
|
associations:
|
||||||
|
_and:
|
||||||
|
- user:
|
||||||
|
authid:
|
||||||
|
_eq: X-Hasura-User-Id
|
||||||
|
- active:
|
||||||
|
_eq: true
|
||||||
|
role: user
|
||||||
|
table:
|
||||||
|
name: available_jobs
|
||||||
|
schema: public
|
||||||
|
type: create_select_permission
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
- args:
|
||||||
|
role: user
|
||||||
|
table:
|
||||||
|
name: available_jobs
|
||||||
|
schema: public
|
||||||
|
type: drop_select_permission
|
||||||
|
- args:
|
||||||
|
permission:
|
||||||
|
allow_aggregations: false
|
||||||
|
columns:
|
||||||
|
- bodyshopid
|
||||||
|
- cieca_id
|
||||||
|
- clm_amt
|
||||||
|
- clm_no
|
||||||
|
- created_at
|
||||||
|
- est_data
|
||||||
|
- id
|
||||||
|
- ins_co_nm
|
||||||
|
- issupplement
|
||||||
|
- jobid
|
||||||
|
- ownr_name
|
||||||
|
- source_system
|
||||||
|
- supplement_number
|
||||||
|
- updated_at
|
||||||
|
- uploaded_by
|
||||||
|
- vehicle_info
|
||||||
|
computed_fields: []
|
||||||
|
filter:
|
||||||
|
bodyshop:
|
||||||
|
associations:
|
||||||
|
_and:
|
||||||
|
- user:
|
||||||
|
authid:
|
||||||
|
_eq: X-Hasura-User-Id
|
||||||
|
- active:
|
||||||
|
_eq: true
|
||||||
|
role: user
|
||||||
|
table:
|
||||||
|
name: available_jobs
|
||||||
|
schema: public
|
||||||
|
type: create_select_permission
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
- args:
|
||||||
|
role: user
|
||||||
|
table:
|
||||||
|
name: available_jobs
|
||||||
|
schema: public
|
||||||
|
type: drop_update_permission
|
||||||
|
- args:
|
||||||
|
permission:
|
||||||
|
columns:
|
||||||
|
- cieca_id
|
||||||
|
- clm_amt
|
||||||
|
- est_data
|
||||||
|
- issupplement
|
||||||
|
- ownr_name
|
||||||
|
- source_system
|
||||||
|
- supplement_number
|
||||||
|
- uploaded_by
|
||||||
|
- vehicle_info
|
||||||
|
filter:
|
||||||
|
bodyshop:
|
||||||
|
associations:
|
||||||
|
_and:
|
||||||
|
- user:
|
||||||
|
authid:
|
||||||
|
_eq: X-Hasura-User-Id
|
||||||
|
- active:
|
||||||
|
_eq: true
|
||||||
|
set: {}
|
||||||
|
role: user
|
||||||
|
table:
|
||||||
|
name: available_jobs
|
||||||
|
schema: public
|
||||||
|
type: create_update_permission
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
- args:
|
||||||
|
role: user
|
||||||
|
table:
|
||||||
|
name: available_jobs
|
||||||
|
schema: public
|
||||||
|
type: drop_update_permission
|
||||||
|
- args:
|
||||||
|
permission:
|
||||||
|
columns:
|
||||||
|
- cieca_id
|
||||||
|
- clm_amt
|
||||||
|
- est_data
|
||||||
|
- ins_co_nm
|
||||||
|
- issupplement
|
||||||
|
- ownr_name
|
||||||
|
- source_system
|
||||||
|
- supplement_number
|
||||||
|
- uploaded_by
|
||||||
|
- vehicle_info
|
||||||
|
filter:
|
||||||
|
bodyshop:
|
||||||
|
associations:
|
||||||
|
_and:
|
||||||
|
- user:
|
||||||
|
authid:
|
||||||
|
_eq: X-Hasura-User-Id
|
||||||
|
- active:
|
||||||
|
_eq: true
|
||||||
|
set: {}
|
||||||
|
role: user
|
||||||
|
table:
|
||||||
|
name: available_jobs
|
||||||
|
schema: public
|
||||||
|
type: create_update_permission
|
||||||
@@ -276,40 +276,42 @@ tables:
|
|||||||
- active:
|
- active:
|
||||||
_eq: true
|
_eq: true
|
||||||
columns:
|
columns:
|
||||||
- id
|
|
||||||
- created_at
|
|
||||||
- updated_at
|
|
||||||
- uploaded_by
|
|
||||||
- cieca_id
|
|
||||||
- bodyshopid
|
- bodyshopid
|
||||||
- est_data
|
- cieca_id
|
||||||
- issupplement
|
|
||||||
- jobid
|
|
||||||
- supplement_number
|
|
||||||
- ownr_name
|
|
||||||
- vehicle_info
|
|
||||||
- clm_amt
|
- clm_amt
|
||||||
- clm_no
|
- clm_no
|
||||||
|
- created_at
|
||||||
|
- est_data
|
||||||
|
- id
|
||||||
|
- ins_co_nm
|
||||||
|
- issupplement
|
||||||
|
- jobid
|
||||||
|
- ownr_name
|
||||||
- source_system
|
- source_system
|
||||||
|
- supplement_number
|
||||||
|
- updated_at
|
||||||
|
- uploaded_by
|
||||||
|
- vehicle_info
|
||||||
select_permissions:
|
select_permissions:
|
||||||
- role: user
|
- role: user
|
||||||
permission:
|
permission:
|
||||||
columns:
|
columns:
|
||||||
- issupplement
|
- bodyshopid
|
||||||
- supplement_number
|
|
||||||
- est_data
|
|
||||||
- clm_amt
|
|
||||||
- cieca_id
|
- cieca_id
|
||||||
|
- clm_amt
|
||||||
- clm_no
|
- clm_no
|
||||||
|
- created_at
|
||||||
|
- est_data
|
||||||
|
- id
|
||||||
|
- ins_co_nm
|
||||||
|
- issupplement
|
||||||
|
- jobid
|
||||||
- ownr_name
|
- ownr_name
|
||||||
- source_system
|
- source_system
|
||||||
|
- supplement_number
|
||||||
|
- updated_at
|
||||||
- uploaded_by
|
- uploaded_by
|
||||||
- vehicle_info
|
- vehicle_info
|
||||||
- created_at
|
|
||||||
- updated_at
|
|
||||||
- bodyshopid
|
|
||||||
- id
|
|
||||||
- jobid
|
|
||||||
filter:
|
filter:
|
||||||
bodyshop:
|
bodyshop:
|
||||||
associations:
|
associations:
|
||||||
@@ -326,6 +328,7 @@ tables:
|
|||||||
- cieca_id
|
- cieca_id
|
||||||
- clm_amt
|
- clm_amt
|
||||||
- est_data
|
- est_data
|
||||||
|
- ins_co_nm
|
||||||
- issupplement
|
- issupplement
|
||||||
- ownr_name
|
- ownr_name
|
||||||
- source_system
|
- source_system
|
||||||
|
|||||||
Reference in New Issue
Block a user