1
1
// Define a type for the strapi parameter
2
2
interface Strapi {
3
3
entityService : {
4
- count : ( query : string ) => Promise < number > ;
5
- create : ( query : string , data : { data : User } ) => Promise < void > ;
4
+ count : ( query : string ) => Promise < number > ;
5
+ create : ( query : string , data : { data : User } ) => Promise < void > ;
6
6
} ;
7
- }
8
-
9
- // Define a type for the user object
10
- interface User {
7
+ }
8
+
9
+ // Define a type for the user object
10
+ interface User {
11
11
username : string ;
12
12
email : string ;
13
13
provider : string ;
@@ -19,35 +19,35 @@ interface Strapi {
19
19
role : number ;
20
20
old_pw_hash : null ;
21
21
migrated_pw : boolean ;
22
- }
23
-
24
- export async function seedUsers ( strapi : Strapi ) {
22
+ }
23
+
24
+ export async function seedUsers ( strapi : Strapi ) {
25
25
const amountOfUsers = 10 ;
26
26
try {
27
- const count = await strapi . entityService . count ( "plugin::users-permissions.user" ) ;
28
- if ( count === 0 ) {
29
- for ( let i = 0 ; i < amountOfUsers ; i ++ ) {
30
- const user : User = {
31
- username : `dummyUser${ i } ` ,
32
- email : `dummyUser${ i } @example.com` ,
33
- provider : "local" ,
34
- password : "dummyPassword" ,
35
- resetPasswordToken : null ,
36
- confirmationToken : null ,
37
- confirmed : true ,
38
- blocked : false ,
39
- role : 1 ,
40
- old_pw_hash : null ,
41
- migrated_pw : false ,
42
- } ;
43
- await strapi . entityService . create ( "plugin::users-permissions.user" , { data : user } ) ;
27
+ const count = await strapi . entityService . count ( "plugin::users-permissions.user" ) ;
28
+ if ( count === 0 ) {
29
+ for ( let i = 0 ; i < amountOfUsers ; i ++ ) {
30
+ const user : User = {
31
+ username : `dummyUser${ i } ` ,
32
+ email : `dummyUser${ i } @example.com` ,
33
+ provider : "local" ,
34
+ password : "dummyPassword" ,
35
+ resetPasswordToken : null ,
36
+ confirmationToken : null ,
37
+ confirmed : true ,
38
+ blocked : false ,
39
+ role : 1 ,
40
+ old_pw_hash : null ,
41
+ migrated_pw : false ,
42
+ } ;
43
+ await strapi . entityService . create ( "plugin::users-permissions.user" , { data : user } ) ;
44
+ }
45
+ console . log ( "SUCCESS: Created user on bootstrap" ) ;
46
+ } else {
47
+ console . log ( "INFO: User have already been created on bootstrap" ) ;
44
48
}
45
- console . log ( "SUCCESS: Created user on bootstrap" ) ;
46
- } else {
47
- console . log ( "INFO: User have already been created on bootstrap" ) ;
48
- }
49
49
} catch ( err ) {
50
- console . log ( "ERROR: Could not create users on bootstrap" ) ;
51
- console . log ( err ) ;
50
+ console . log ( "ERROR: Could not create users on bootstrap" ) ;
51
+ console . log ( err ) ;
52
52
}
53
- }
53
+ }
0 commit comments