Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
Partition.createPartition = async (organisationId, params = {}, options = {}) => {

		const currentTx = options.transaction;
		const {
			description,
			color,
			polygon_data: polygonData,
			tags: tags = [],
			hub_id: hubId
		} = params;
		assert(currentTx, 'currentTx is required');
		assert(organisationId, 'organisationId is required');
		assert(params.partition_code, 'partitionCode is required');
		assert(params.hub_id, 'hubId is required');
		assert(Array.isArray(tags), 'tags should be array');
		
		if (!(Array.isArray(polygonData) && polygonData.length)) {
			throw helper.wrongInputError('partition data should be array');
		};
		
		if (!(Array.isArray(bounds) && bounds.length)) {
			throw helper.wrongInputError('bounds data should be array');
		};

		const partitionCode = helper.sanitizeStringCode(params.partition_code);
		const existingPartition = await extendedModels.Partition.findOne({
			where: {
				partition_code: partitionCode
			},
			fields: { id: true }
		}, { transaction: currentTx });

		if (existingPartition) {
			throw helper.wrongInputError('', {
				message: 'Partition code already exists',
				reason: 'PARTITION_ALREADY_EXISTS'
			});
		};
		if (helper.hasKey(params, 'hub_id', { blankIsFalse: true })) {
			partitionAttributesToUpdate.hubId = helper.sanitizeStringCode(hubId);
		};
		const polygon = postgisHelper.geojsonToWkb(postgisHelper.createPolyGeoJson([polygonData]));
		const bounds = postgisHelper.geojsonToWkb(postgisHelper.createPolyGeoJson([bounds]));
		await Partition.create({
			organisation_id: organisationId,
			partition_code: partitionCode,
			description: description,
			tags: tags,
			polygon: polygon,
			color: color,
			bounds: bounds,
			hub_id: hubId
		}, { transaction: currentTx });
	};

For hub Allocation using partition based method, a new IDB key will be used partition_based_origin_hub_allocation while creating softadata and calling fn getConsignmentOriginHub

Code Block
else if(orgConfig.partition_based_origin_hub_allocation) {
        const lat = get(params, 'origin_address.lat', null);
        const lng = get(params, 'origin_address.lng', null);
        if (!lat || !lng){            
			throw helper.wrongInputError('', {
				message: 'latitude and latitude should be present for proximity based hub allocation'
            });
        }
        const partition = await extendedModels.Partition.findValidPartition( organisationId,
            {
                lat: inputParams.lat,
                lng: inputParams.lng,
            }, options);
        if( partition && partition.hub_id){
            hubId = partition.hub_id;
        }
    }