Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented: schema for shipment, defined action to fetch the shipments, and added transformation rule(#2vd6xty) #14

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { events, Product, Response, Order, OrderItem, OrderPart, User } from '@/types'
import { events, Product, Response, Order, OrderItem, OrderPart, Shipment, User } from '@/types'
import { init, resetConfig, updateToken, updateInstanceUrl } from '@/api'
import { isError } from '@/util'
import { fetchProducts, getOrderDetails, getProfile, updateOrderStatus } from '@/modules'
import { fetchProducts, fetchShipments, getOrderDetails, getProfile, updateOrderStatus } from '@/modules'

export {
getOrderDetails,
updateOrderStatus,
fetchProducts,
fetchShipments,
init,
isError,
resetConfig,
Expand All @@ -16,6 +17,7 @@ export {
events,
Product,
Response,
Shipment,
Order,
OrderItem,
OrderPart,
Expand Down
13 changes: 13 additions & 0 deletions src/mappings/shipment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const shipmentTransformRule = {
item: {
shipmentId: "shipmentId",
estimatedArrivalDate: "estimatedArrivalDate",
fromPartyId: "partyIdFrom",
toPartyId: "partyIdTo",
statusId: "statusId",
shipmentItemCount: "shipmentItemCount",
destinationFacilityId: "destinationFacilityId"
}
}

export { shipmentTransformRule }
2 changes: 2 additions & 0 deletions src/modules/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { getOrderDetails, updateOrderStatus } from '@/modules/order'
import { fetchProducts } from '@/modules/product'
import { getProfile } from '@/modules/user'
import { fetchShipments } from '@/modules/shipment'

export {
fetchProducts,
fetchShipments,
getOrderDetails,
getProfile,
updateOrderStatus
Expand Down
59 changes: 59 additions & 0 deletions src/modules/shipment/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import api from "@/api";
import { hasError } from "@/util";
import { Response, Shipment } from "@/types";
import { shipmentTransformRule } from "@/mappings/shipment";
import { transform } from "node-json-transform";

async function fetchShipments(payload: any): Promise <Shipment[] | Response> {
let response = {} as Shipment[] | Response

const query = {
"inputFields": {
"destinationFacilityId": payload.facilityId,
"statusId": "PURCH_SHIP_SHIPPED",
Copy link
Contributor

@adityasharma7 adityasharma7 Dec 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are allowing to fetch only shipped and incoming shipments here. I would suggest making it configurable along with the following improvements:

We should define shipment status enumerations for apps (created, shipped...) and perform mapping in the package. This way package could easily take care of the different status values of different backend servers. The app query will be static for different backends having a defined status and the package does the magic.

For incoming/outgoing shipment conditions, I would suggest 2 possible solutions:

  1. We should have separate methods for incoming and outgoing shipments.
  2. We should have a payload parameter, that identifies if the query is for incoming/outgoing shipment. If we consider handling with payload, we need to add these conditions to the query only when we receive certain parameters with payload.

For example, we identify a field shipmentType with values incoming/outgoing. If we do not receive any value we fetch all shipments else add

      "shipmentTypeId_fld0_value": "INCOMING_SHIPMENT",
      "shipmentTypeId_fld0_op": "equals",
      "shipmentTypeId_fld0_grp": "1",
      "parentTypeId_fld0_value": "INCOMING_SHIPMENT",
      "parentTypeId_fld0_op": "equals",
      "parentTypeId_fld0_grp": "2",

This way we are abstracting applications from server details. The app needs incoming shipments, different backends may have different data models. If we define these conditions in apps, we may diverge from the bodiless approach and have to perform workarounds when switching between backends.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed with @adityasharma7 Sir and @dt2patel Sir, we will define two separate methods for incoming and outgoing shipments.

Also will create enums for shipment type and shipment status in oms package.

"shipmentTypeId_fld0_value": "INCOMING_SHIPMENT",
"shipmentTypeId_fld0_op": "equals",
"shipmentTypeId_fld0_grp": "1",
"parentTypeId_fld0_value": "INCOMING_SHIPMENT",
"parentTypeId_fld0_op": "equals",
"parentTypeId_fld0_grp": "2",
},
"entityName": "ShipmentAndTypeAndItemCount",
"fieldList" : ["shipmentId", "primaryShipGroupSeqId", "partyIdFrom", "partyIdTo", "estimatedArrivalDate", "destinationFacilityId", "statusId", "shipmentItemCount"],
"noConditionFind": "Y",
"viewSize": payload.viewSize,
"viewIndex": payload.viewIndex,
} as any

if(payload.queryString) {
query.inputFields["shipmentId"] = payload.queryString;
query.inputFields["shipmentId_op"] = "contains";
query.inputFields["shipmentId_ic"] = "Y";
}

try {
const resp = await api({
url: '/performFind',
method: 'post',
data: query,
cache: true
}) as any

if (resp.status === 200 && resp.data.docs?.length > 0 && !hasError(resp)) {
const shipments: Array<Shipment> = transform(resp.data.docs, shipmentTransformRule)
response = shipments;
} else {
response = [];
}
} catch(err) {
response = {
code: 'error',
message: 'Something went wrong',
serverResponse: err
}
}

return response;
}

export { fetchShipments }
75 changes: 75 additions & 0 deletions src/types/Shipment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { Enumeration, Party, Status, Uom } from "./index"

export interface ShipmentItemSource {
shipmentItemSourceId?: string;
orderId?: string;
orderItemSeqId?: string;
returnId?: string;
returnItemSeqId?: string;
statusId?: string;
invoiceId?: string;
invoiceItemSeqId?: string;
}

export interface Shipment {
shipmentId: string;
shipmentTypeEnumId?: string;
statusId?: string;
fromPartyId?: string;
toPartyId?: string;
binLocationNumber?: number;
productStoreId?: string;
priority?: number;
entryDate?: number;
shipAfterDate?: number;
shipBeforeDate?: number;
estimatedReadyDate?: number;
estimatedShipDate?: number;
estimatedArrivalDate?: number;
latestCancelDate?: number;
packedDate?: number;
pickContainerId?: string;
estimatedShipCost?: number;
costUomId?: string;
addtlShippingCharge?: number;
addtlShippingChargeDesc?: string;
signatureRequiredEnumId?: string;
handlingInstructions?: string;
otherPartyOrderId?: string;
systemMessageRemoteId?: string;
externalId?: string;
originId?: string;
type?: Enumeration;
status?: Status;
fromParty?: Party;
toParty?: Party;
costUom?: Uom;
contents?: Array<{
shipmentContentId?: string;
shipmentContentTypeEnumId?: string;
shipmentId?: string;
productId?: string;
shipmentPackageSeqId?: string;
shipmentRouteSegmentSeqId?: string;
contentLocation?: string;
description?: string;
contentDate?: number;
userId?: string;
}>;
items?: Array<{
shipmentId?: string;
productId?: string;
quantity?: number;
itemSource?: ShipmentItemSource;
}>;
packages?: Array<{
shipmentId?: string;
shipmentPackageSeqId?: string;
shipmentBoxTypeId?: string;
weight?: number;
weightUomId?: string;
gatewayPackageId?: string;
}>;
shipmentItemCount?: number; // Item count in shipment
destinationFacilityId?: string; // Destination facility Id for shipment
}
2 changes: 2 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Party } from './Party';
import { Product } from './Product';
import { Status } from './Status';
import { Uom } from './Uom';
import { Shipment } from './Shipment';
import { User } from './User';

const events = {
Expand All @@ -30,6 +31,7 @@ export {
OrderPart,
Party,
Product,
Shipment,
Status,
Uom,
User,
Expand Down