Commit a34d85ff by jay

seed data import

1 parent 39102147
'use strict';
"use strict";
/**
* game controller
*/
const { createCoreController } = require('@strapi/strapi').factories;
const { createCoreController } = require("@strapi/strapi").factories;
module.exports = createCoreController('api::game.game');
module.exports = createCoreController("api::game.game", () => ({
async importSeedData(ctx) {
await strapi.service("api::game.game").importSeedDataFromApi();
ctx.send({ ok: true });
},
}));
const routes = {
routes: [
{
method: "POST",
path: "/games/import-seed-data",
handler: "api::game.game.importSeedData",
config: {
// some configuration...
}
},
]
};
module.exports = routes;
\ No newline at end of file
'use strict';
"use strict";
const axios = require("axios");
const { factories } = require("@strapi/strapi");
/**
* game service
*/
const { createCoreService } = require('@strapi/strapi').factories;
const { createCoreService } = require("@strapi/strapi").factories;
module.exports = factories.createCoreService(
"api::game.game",
({ strapi: Strapi }) => ({
async importSeedDataFromApi() {
const seedData = await axios.get(
"https://public.connectnow.org.uk/applicant-test/"
);
// console.log("seedData", seedData.data[0]);
let seedDataFinal = seedData.data;
const date = new Date()
const deletedCnt = await strapi.db.query("api::game.game").deleteMany({ where: {} });
for (let i = 0; i < seedDataFinal.length; i++) {
const item = seedDataFinal[i];
// console.log("seedData", item);
module.exports = createCoreService('api::game.game');
// console.log(`Attempting to create country: `, country);
await strapi.entityService.create("api::game.game", {
data: {
firstReleaseDate: `${item.first_release_date}`,
name: item.name,
rating: `${item.rating}`,
summary: item.summary,
publishedAt: date
},
});
}
},
})
);
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!