| Current Path : /home/deltalab/PMS/sms-connector/graphql/types/ |
| Current File : //home/deltalab/PMS/sms-connector/graphql/types/shipment.type.js |
const { composeMongoose } = require('graphql-compose-mongoose');
const { toInputObjectType } = require('graphql-compose');
const { schemaComposer } = require('graphql-compose');
// RESOURCES =============================================
const { shipmentBaseInfoModel } = require('../../models/mongoose/shipment');
const { shipmentInfoModel } = require('../../models/mongoose/shipment');
const { shipmentModel } = require('../../models/mongoose/shipment');
require('./carrier.type'); // load the carrier
const shipmentStatusType = schemaComposer.createEnumTC(`
enum ShipmentStatusEnum {
INFO_RECEIVED
IN_TRANSIT
OUT_FOR_DELIVERY
MISSED_DELIVERY
DELIVERED
EXCEPTION
}
`);
class ShipmentError {
error = 'String';
}
class ShipmentStatus extends ShipmentError {
shipmentId = 'Int';
orderId = 'String';
carrier = 'Carrier';
trackingCarrier = 'String';
trackingNumber = 'String';
status = 'ShipmentStatusEnum';
labelUrl = '[String]';
}
class ShipmentCreation extends ShipmentError {
shipmentId = 'Int';
labelUrl = '[String]';
trackingCarrier = 'String';
trackingNumber = 'String';
}
// MODELS =======================
const shipmentErrorTC = schemaComposer.createObjectTC({
name: 'ShipmentError',
fields: new ShipmentError()
});
const shipmentCreationTC = schemaComposer.createObjectTC({
name: 'ShipmentCreation',
fields: new ShipmentCreation()
});
const shipmentStatusTC = schemaComposer.createObjectTC({
name: 'ShipmentStatus',
fields: new ShipmentStatus()
});
const shipmentBaseInfoTC = composeMongoose(shipmentBaseInfoModel);
const shipmentInfoTC = composeMongoose(shipmentInfoModel);
const shipmentTC = composeMongoose(shipmentModel);
// ShipmentManifest OTC is already defined withing shipmentModel
// just extract the TC from the existing schema composer
const shipmentManifestTC = schemaComposer.getOTC('ShipmentManifest');
const shipmentBaseInfoInputType = toInputObjectType(shipmentBaseInfoTC);
const shipmentInfoInputType = toInputObjectType(shipmentInfoTC);
// EXPORTS ==================================================
module.exports = {
shipmentBaseInfoTC,
shipmentBaseInfoInputType,
shipmentCreationTC,
shipmentInfoTC,
shipmentInfoInputType,
shipmentManifestTC,
shipmentStatusTC,
shipmentTC,
};