Commit 4b8fc48b by jaymehta

pincode seed

1 parent ce85cc22
......@@ -10,9 +10,9 @@ const { createCoreController } = require("@strapi/strapi").factories;
module.exports = createCoreController("api::vendor.vendor", () => ({
async importSeedData(ctx) {
await strapi.service("api::vendor.vendor").importCountrySeedData();
await strapi.service("api::vendor.vendor").importStateSeedData();
await strapi.service("api::vendor.vendor").importCitySeedData();
// await strapi.service("api::vendor.vendor").importCountrySeedData();
// await strapi.service("api::vendor.vendor").importStateSeedData();
// await strapi.service("api::vendor.vendor").importCitySeedData();
await strapi.service("api::vendor.vendor").importPincodeSeedData();
// await strapi.service("api::jeweler.jeweler").importColorSeedData();
// await strapi.service("api::jeweler.jeweler").importKaratSeedData();
......
PINCODE,CITY_NM,STATE_NM
10001,Mumbai,Punjab
10002,Mumbai,Punjab
10003,Mumbai,Punjab
10004,Mumbai,Punjab
10005,Mumbai,Punjab
10006,Mumbai,Punjab
10007,Mumbai,Punjab
10009,Mumbai,Punjab
10010,Mumbai,Punjab
10011,Mumbai,Punjab
10012,Mumbai,Punjab
10013,Mumbai,Punjab
10014,Mumbai,Punjab
10016,Mumbai,Punjab
10017,Mumbai,Punjab
10018,Mumbai,Punjab
10019,Mumbai,Punjab
10020,Mumbai,Punjab
10021,Mumbai,Punjab
10022,Mumbai,Punjab
10023,Mumbai,Punjab
10024,Mumbai,Punjab
10025,Mumbai,Punjab
10026,Mumbai,Punjab
10027,Mumbai,Punjab
10028,Mumbai,Punjab
10029,Mumbai,Punjab
10030,Mumbai,Punjab
10031,Mumbai,Punjab
10032,Mumbai,Punjab
10033,Mumbai,Punjab
10034,Mumbai,Punjab
10035,Mumbai,Punjab
10036,Mumbai,Punjab
10037,Mumbai,Punjab
10038,Mumbai,Punjab
10039,Mumbai,Punjab
10040,Mumbai,Punjab
10044,Mumbai,Punjab
10048,Mumbai,Punjab
10065,Mumbai,Punjab
10069,Mumbai,Punjab
10075,Mumbai,Punjab
10128,Mumbai,Punjab
10280,Mumbai,Punjab
10282,Mumbai,Punjab
10301,Mumbai,Punjab
10302,Mumbai,Punjab
10303,Mumbai,Punjab
10304,Mumbai,Punjab
10305,Mumbai,Punjab
10306,Mumbai,Punjab
10307,Mumbai,Punjab
10308,Mumbai,Punjab
10309,Mumbai,Punjab
10310,Mumbai,Punjab
10311,Mumbai,Punjab
10312,Mumbai,Punjab
10314,Mumbai,Punjab
10451,Mumbai,Punjab
10452,Mumbai,Punjab
10453,Mumbai,Punjab
10454,Mumbai,Punjab
10455,Mumbai,Punjab
10456,Mumbai,Punjab
10457,Mumbai,Punjab
10458,Mumbai,Punjab
10459,Mumbai,Punjab
10460,Mumbai,Punjab
10461,Mumbai,Punjab
10462,Mumbai,Punjab
10463,Mumbai,Punjab
10464,Mumbai,Punjab
10465,Mumbai,Punjab
10466,Mumbai,Punjab
10467,Mumbai,Punjab
10468,Mumbai,Punjab
10469,Mumbai,Punjab
10470,Mumbai,Punjab
10471,Mumbai,Punjab
10472,Mumbai,Punjab
10473,Mumbai,Punjab
10474,Mumbai,Punjab
10475,Mumbai,Punjab
11001,Mumbai,Punjab
11002,Mumbai,Punjab
11003,Mumbai,Punjab
11004,Mumbai,Punjab
11005,Mumbai,Punjab
11010,Mumbai,Punjab
11020,Mumbai,Punjab
11021,Mumbai,Punjab
11022,Mumbai,Punjab
11023,Mumbai,Punjab
11024,Mumbai,Punjab
11030,Mumbai,Punjab
11040,Mumbai,Punjab
11042,Mumbai,Punjab
11050,Mumbai,Punjab
11096,Mumbai,Punjab
11101,Mumbai,Punjab
11102,Mumbai,Punjab
11103,Mumbai,Punjab
11104,Mumbai,Punjab
11105,Mumbai,Punjab
11106,Mumbai,Punjab
11109,Mumbai,Punjab
11201,Mumbai,Punjab
11203,Mumbai,Punjab
11204,Mumbai,Punjab
11205,Mumbai,Punjab
11206,Mumbai,Punjab
11207,Mumbai,Punjab
11208,Mumbai,Punjab
11209,Mumbai,Punjab
11210,Mumbai,Punjab
11211,Mumbai,Punjab
11212,Mumbai,Punjab
11213,Mumbai,Punjab
11214,Mumbai,Punjab
11215,Mumbai,Punjab
11216,Mumbai,Punjab
11217,Mumbai,Punjab
11218,Mumbai,Punjab
11219,Mumbai,Punjab
11220,Mumbai,Punjab
11221,Mumbai,Punjab
11222,Mumbai,Punjab
11223,Mumbai,Punjab
11224,Mumbai,Punjab
11225,Mumbai,Punjab
11226,Mumbai,Punjab
11228,Mumbai,Punjab
11229,Mumbai,Punjab
11230,Mumbai,Punjab
11231,Mumbai,Punjab
11232,Mumbai,Punjab
11233,Mumbai,Punjab
11234,Mumbai,Punjab
11235,Mumbai,Punjab
11236,Mumbai,Punjab
11237,Mumbai,Punjab
11238,Mumbai,Punjab
11239,Mumbai,Punjab
11249,Mumbai,Punjab
11251,Mumbai,Punjab
11351,Mumbai,Punjab
11352,Mumbai,Punjab
11354,Mumbai,Punjab
11355,Mumbai,Punjab
11356,Mumbai,Punjab
11357,Mumbai,Punjab
11358,Mumbai,Punjab
11359,Mumbai,Punjab
11360,Mumbai,Punjab
11361,Mumbai,Punjab
11362,Mumbai,Punjab
11363,Mumbai,Punjab
11364,Mumbai,Punjab
11365,Mumbai,Punjab
11366,Mumbai,Punjab
11367,Mumbai,Punjab
11368,Mumbai,Punjab
11369,Mumbai,Punjab
11370,Mumbai,Punjab
11371,Mumbai,Punjab
11372,Mumbai,Punjab
11373,Mumbai,Punjab
11374,Mumbai,Punjab
11375,Mumbai,Punjab
11377,Mumbai,Punjab
11378,Mumbai,Punjab
11379,Mumbai,Punjab
11380,Mumbai,Punjab
11381,Mumbai,Punjab
11385,Mumbai,Punjab
11411,Mumbai,Punjab
11412,Mumbai,Punjab
11413,Mumbai,Punjab
11414,Mumbai,Punjab
11415,Mumbai,Punjab
11416,Mumbai,Punjab
11417,Mumbai,Punjab
11418,Mumbai,Punjab
11419,Mumbai,Punjab
11420,Mumbai,Punjab
11421,Mumbai,Punjab
11422,Mumbai,Punjab
11423,Mumbai,Punjab
11424,Mumbai,Punjab
11425,Mumbai,Punjab
11426,Mumbai,Punjab
11427,Mumbai,Punjab
11428,Mumbai,Punjab
11429,Mumbai,Punjab
11430,Mumbai,Punjab
11431,Mumbai,Punjab
11432,Mumbai,Punjab
11433,Mumbai,Punjab
11434,Mumbai,Punjab
11435,Mumbai,Punjab
11436,Mumbai,Punjab
11439,Mumbai,Punjab
11451,Mumbai,Punjab
11501,Mumbai,Punjab
11507,Mumbai,Punjab
11509,Mumbai,Punjab
11510,Mumbai,Punjab
11514,Mumbai,Punjab
11516,Mumbai,Punjab
11518,Mumbai,Punjab
11520,Mumbai,Punjab
11530,Mumbai,Punjab
11531,Mumbai,Punjab
11542,Mumbai,Punjab
11545,Mumbai,Punjab
11547,Mumbai,Punjab
11548,Mumbai,Punjab
11549,Mumbai,Punjab
11550,Mumbai,Punjab
11552,Mumbai,Punjab
11554,Mumbai,Punjab
11556,Mumbai,Punjab
11557,Mumbai,Punjab
11558,Mumbai,Punjab
11559,Mumbai,Punjab
11560,Mumbai,Punjab
11561,Mumbai,Punjab
11563,Mumbai,Punjab
11565,Mumbai,Punjab
11568,Mumbai,Punjab
11570,Mumbai,Punjab
11572,Mumbai,Punjab
11575,Mumbai,Punjab
11576,Mumbai,Punjab
11577,Mumbai,Punjab
11579,Mumbai,Punjab
11580,Mumbai,Punjab
11581,Mumbai,Punjab
11590,Mumbai,Punjab
11596,Mumbai,Punjab
11598,Mumbai,Punjab
11691,Mumbai,Punjab
11692,Mumbai,Punjab
11693,Mumbai,Punjab
11694,Mumbai,Punjab
11695,Mumbai,Punjab
11697,Mumbai,Punjab
\ No newline at end of file
......@@ -21,9 +21,9 @@ module.exports = createCoreService(
// console.log(countries);
// get rid of all existing countries.
const deletedCnt = await strapi.db
.query("api::master-country.master-country")
.deleteMany({ where: {} });
// const deletedCnt = await strapi.db
// .query("api::master-country.master-country")
// .deleteMany({ where: {} });
// console.log(`Bulk deleted existing countries, got rid of: ${deletedCnt.count} country records.`);
// re-create them again.
......@@ -105,15 +105,15 @@ module.exports = createCoreService(
// re-create them again.
for (let i = 0; i < cities.length; i++) {
const city = cities[i];
const matchingStates = await strapi.entityService.findMany(
"api::master-state.master-state",
{
fields: ["id"],
filters: { name: city.state },
}
);
// const matchingStates = await strapi.entityService.findMany(
// "api::master-state.master-state",
// {
// fields: ["id"],
// filters: { name: city.state },
// }
// );
if (!matchingStates || matchingStates.length === 0) {
if (false) {
console.log(
`Unable to resolve a state with name ${
city.state
......@@ -124,7 +124,7 @@ module.exports = createCoreService(
await strapi.entityService.create("api::master-city.master-city", {
data: {
name: city.name,
masterState: matchingStates[0].id,
// masterState: matchingStates[0].id,
},
});
}
......@@ -143,17 +143,15 @@ module.exports = createCoreService(
const deletedCnt = await strapi.db
.query("api::master-pincode.master-pincode")
.deleteMany({ where: {} });
const deletedStateCnt = await strapi.db
.query("api::master-state.master-state")
.deleteMany({ where: {} });
const deletedCityCnt = await strapi.db
.query("api::master-city.master-city")
.deleteMany({ where: {} });
// const deletedStateCnt = await strapi.db
// .query("api::master-state.master-state")
// .deleteMany({ where: {} });
// const deletedCityCnt = await strapi.db
// .query("api::master-city.master-city")
// .deleteMany({ where: {} });
// const pincodeData = fs.createReadStream(`${__dirname}/../seed-data/StateCityPinMasterSeeder.csv`).pipe(parse({ delimiter: ",", from_line: 1 }));
fs.createReadStream(
`${__dirname}/../seed-data/StateCityPinMasterSeeder.csv`
)
fs.createReadStream(`${__dirname}/../seed-data/result.csv`)
.pipe(parse({}))
.on("data", (data) => {
// console.log("data", data);
......@@ -176,48 +174,48 @@ module.exports = createCoreService(
console.log("pincode", pincode);
console.log("city", city);
console.log("state", state);
const resolveCountry = await strapi
.query("api::master-country.master-country")
.findOne({
where: {
$and: [{ name: "India" }],
},
});
console.log("resolveCountry", resolveCountry);
let resolveState = await strapi
.query("api::master-state.master-state")
.findOne({
where: {
$and: [{ name: state }],
},
});
console.log("resolveState", resolveState);
// const resolveCountry = await strapi
// .query("api::master-country.master-country")
// .findOne({
// where: {
// $and: [{ name: "India" }],
// },
// });
// console.log("resolveCountry", resolveCountry);
// let resolveState = await strapi
// .query("api::master-state.master-state")
// .findOne({
// where: {
// $and: [{ name: state }],
// },
// });
// console.log("resolveState", resolveState);
if (resolveState == null) {
resolveState = await strapi.entityService.create(
"api::master-state.master-state",
{
data: {
name: state,
masterCountry: resolveCountry.id,
},
}
);
console.log("resolveState", resolveState);
// if (resolveState == null) {
// resolveState = await strapi.entityService.create(
// "api::master-state.master-state",
// {
// data: {
// name: state,
// masterCountry: resolveCountry.id,
// },
// }
// );
// console.log("resolveState", resolveState);
stateId = resolveState.id;
} else {
stateId = resolveState.id;
}
let resolveCity = await strapi
.query("api::master-city.master-city")
.findOne({
where: {
$and: [{ name: city, masterState: stateId }],
},
});
console.log("resolveCity", resolveCity);
if (resolveCity == null) {
// stateId = resolveState.id;
// } else {
// stateId = resolveState.id;
// }
// let resolveCity = await strapi
// .query("api::master-city.master-city")
// .findOne({
// where: {
// $and: [{ name: city, masterState: stateId }],
// },
// });
// console.log("resolveCity", resolveCity);
if (false) {
resolveCity = await strapi.entityService.create(
"api::master-city.master-city",
{
......@@ -231,23 +229,23 @@ module.exports = createCoreService(
cityId = resolveCity.id;
} else {
cityId = resolveCity.id;
// cityId = resolveCity.id;
}
let resolvePincode = await strapi
.query("api::master-pincode.master-pincode")
.findOne({
where: {
$and: [{ name: state }],
$and: [{ name: "test" }],
},
});
let currentCity = await strapi
.query("api::master-city.master-city")
.findOne({
where: {
$and: [{ name: city }],
},
});
// let currentCity = await strapi
// .query("api::master-city.master-city")
// .findOne({
// where: {
// $and: [{ name: city }],
// },
// });
if (resolvePincode == null) {
resolvePincode = await strapi.entityService.create(
......@@ -255,7 +253,7 @@ module.exports = createCoreService(
{
data: {
name: pincode,
masterCity: currentCity.id,
// masterCity: currentCity.id,
},
}
);
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!