Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Jay Mehta
/
strapi-setup-file
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Registry
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit a34d85ff
authored
2023-03-08 15:50:47 +0530
by
jay
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
seed data import
1 parent
39102147
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
6 deletions
src/api/game/controllers/game.js
src/api/game/routes/custom-routes.js
src/api/game/services/game.js
src/api/game/controllers/game.js
View file @
a34d85f
'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
});
},
}));
src/api/game/routes/custom-routes.js
0 → 100644
View file @
a34d85f
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
src/api/game/services/game.js
View file @
a34d85f
'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
},
});
}
},
})
);
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment