shiment id
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { cleanMongoData, extractDumpData, getCollectionData } from "./utils/extractDumpData";
|
||||
import { DeliveryType } from "../../common/enums/shipment.enum";
|
||||
import { Logger } from "../../core/logging/logger";
|
||||
import { ShipmentModel } from "../../modules/shipment/models/shipment.model";
|
||||
@@ -7,12 +6,10 @@ export const SeedShipment = async (logger: Logger) => {
|
||||
try {
|
||||
logger.info("ShipmentMethod seeding started");
|
||||
|
||||
// Extract data from dump
|
||||
const dumpData = extractDumpData();
|
||||
const shipmentsData = getCollectionData(dumpData, "shipments");
|
||||
// Remove all existing shipment documents
|
||||
await ShipmentModel.deleteMany({});
|
||||
logger.info("Existing shipment collection cleared");
|
||||
|
||||
if (shipmentsData.length === 0) {
|
||||
logger.warn("No shipment data found in dump, using fallback data");
|
||||
const fallbackProviders = [
|
||||
{
|
||||
name: "پست",
|
||||
@@ -74,33 +71,7 @@ export const SeedShipment = async (logger: Logger) => {
|
||||
for (const provider of fallbackProviders) {
|
||||
await ShipmentModel.create(provider);
|
||||
}
|
||||
logger.info("Shipment Providers seeded successfully with fallback data");
|
||||
return;
|
||||
}
|
||||
|
||||
// Clean and prepare shipment data (only non-deleted)
|
||||
const cleanedShipments = shipmentsData
|
||||
.map((shipment) => {
|
||||
const cleaned = cleanMongoData(shipment);
|
||||
if (cleaned.deleted) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
name: cleaned.name,
|
||||
description: cleaned.description,
|
||||
costs: cleaned.costs,
|
||||
deliveryTime: cleaned.deliveryTime,
|
||||
deliveryType: cleaned.deliveryType as DeliveryType,
|
||||
};
|
||||
})
|
||||
.filter((s) => s !== null);
|
||||
|
||||
if (cleanedShipments.length > 0) {
|
||||
await ShipmentModel.insertMany(cleanedShipments);
|
||||
logger.info(`Shipment Providers seeded successfully (${cleanedShipments.length} providers)`);
|
||||
} else {
|
||||
logger.warn("No valid shipments found after filtering");
|
||||
}
|
||||
logger.info("Shipment Providers seeded successfully");
|
||||
} catch (error) {
|
||||
logger.error("Error seeding Shipment providers:", error);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ class ShipmentRepository extends BaseRepository<IShipmentProviders> {
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
const count = await this.model.countDocuments({ deleted: false });
|
||||
const shipper = await this.model.find({ deleted: false }).skip(skip).limit(limit);
|
||||
const shipper = await this.model.find({ deleted: false }).skip(skip).limit(limit).lean();
|
||||
|
||||
return { shipper, count };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user