Resolved duplicate vehicles uniqueness constraint on initial import BOD-397

This commit is contained in:
Patrick Fic
2020-10-05 14:15:41 -07:00
parent 7d9b02bb22
commit f188e9512b
13 changed files with 336 additions and 73 deletions

View File

@@ -1,4 +1,4 @@
import { useMutation, useQuery } from "@apollo/react-hooks";
import { useApolloClient, useMutation, useQuery } from "@apollo/react-hooks";
import { notification } from "antd";
import Axios from "axios";
import Dinero from "dinero.js";
@@ -13,6 +13,7 @@ import {
QUERY_AVAILABLE_NEW_JOBS,
} from "../../graphql/available-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 AlertComponent from "../alert/alert.component";
import LoadingSpinner from "../loading-spinner/loading-spinner.component";
@@ -39,6 +40,7 @@ export function JobsAvailableContainer({
const [insertLoading, setInsertLoading] = useState(false);
const [deleteAllNewJobs] = useMutation(DELETE_ALL_AVAILABLE_NEW_JOBS);
const [insertNewJob] = useMutation(INSERT_NEW_JOB);
const client = useApolloClient();
const [loadEstData, estData] = estDataLazyLoad;
const onModalOk = async () => {
@@ -59,63 +61,72 @@ export function JobsAvailableContainer({
notification["error"]({
message: t("jobs.errors.creating", { error: "No job data present." }),
});
} else {
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;
return;
}
const newJob = {
...estData.data.available_jobs_by_pk.est_data,
clm_total: Dinero(newTotals.totals.total_repairs).toFormat("0.00"),
owner_owing: Dinero(newTotals.custPayable.total).toFormat("0.00"),
job_totals: newTotals,
queued_for_parts: true,
};
insertNewJob({
variables: {
job: selectedOwner
? Object.assign(
{},
newJob,
{ owner: null },
{ ownerid: selectedOwner }
)
: newJob,
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,
},
})
.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.
).data;
deleteJob({
variables: { id: estData.data.available_jobs_by_pk.id },
}).then((r) => {
refetch();
setInsertLoading(false);
});
})
.catch((r) => {
//error while inserting
notification["error"]({
message: t("jobs.errors.creating", { error: r.message }),
});
const existingVehicles = await client.query({
query: SEARCH_VEHICLE_BY_VIN,
variables: {
vin: estData.data.available_jobs_by_pk.est_data.vehicle.data.v_vin,
},
});
const newJob = {
...estData.data.available_jobs_by_pk.est_data,
clm_total: Dinero(newTotals.totals.total_repairs).toFormat("0.00"),
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();
setInsertLoading(false);
});
}
})
.catch((r) => {
//error while inserting
notification["error"]({
message: t("jobs.errors.creating", { error: r.message }),
});
refetch();
setInsertLoading(false);
});
};
const onModalCancel = () => {

View File

@@ -62,7 +62,14 @@ export default function JobsAvailableSupplementComponent({
sorter: (a, b) => alphaSort(a, b),
sortOrder:
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"),

View File

@@ -102,7 +102,9 @@ export function JobsAvailableSupplementContainer({
job: {
...supp,
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,
queued_for_parts: true,
},

View File

@@ -17,6 +17,7 @@ export const QUERY_AVAILABLE_NEW_JOBS = gql`
supplement_number
updated_at
uploaded_by
ins_co_nm
vehicle_info
}
}
@@ -39,10 +40,12 @@ export const QUERY_AVAILABLE_SUPPLEMENT_JOBS = gql`
supplement_number
updated_at
uploaded_by
ins_co_nm
vehicle_info
job {
id
ro_number
est_number
}
}
}

View File

@@ -0,0 +1,5 @@
- args:
cascade: false
read_only: false
sql: ALTER TABLE "public"."available_jobs" DROP COLUMN "ins_co_nm";
type: run_sql

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -276,40 +276,42 @@ tables:
- active:
_eq: true
columns:
- id
- created_at
- updated_at
- uploaded_by
- cieca_id
- bodyshopid
- est_data
- issupplement
- jobid
- supplement_number
- ownr_name
- vehicle_info
- 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
select_permissions:
- role: user
permission:
columns:
- issupplement
- supplement_number
- est_data
- clm_amt
- 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
- created_at
- updated_at
- bodyshopid
- id
- jobid
filter:
bodyshop:
associations:
@@ -326,6 +328,7 @@ tables:
- cieca_id
- clm_amt
- est_data
- ins_co_nm
- issupplement
- ownr_name
- source_system