1
1
// Define a type for the strapi parameter
2
2
interface Strapi {
3
- entityService : {
4
- count : ( query : string ) => Promise < number > ;
5
- create : ( query : string , data : { data : User } ) => Promise < void > ;
6
- } ;
3
+ entityService : {
4
+ count : ( query : string ) => Promise < number > ;
5
+ create : ( query : string , data : { data : User } ) => Promise < void > ;
6
+ } ;
7
7
}
8
8
9
9
// Define a type for the user object
10
10
interface User {
11
- username : string ;
12
- email : string ;
13
- provider : string ;
14
- password : string ;
15
- resetPasswordToken : null ;
16
- confirmationToken : null ;
17
- confirmed : boolean ;
18
- blocked : boolean ;
19
- role : number ;
20
- old_pw_hash : null ;
21
- migrated_pw : boolean ;
11
+ username : string ;
12
+ email : string ;
13
+ provider : string ;
14
+ password : string ;
15
+ resetPasswordToken : null ;
16
+ confirmationToken : null ;
17
+ confirmed : boolean ;
18
+ blocked : boolean ;
19
+ role : number ;
20
+ old_pw_hash : null ;
21
+ migrated_pw : boolean ;
22
22
}
23
23
24
24
export async function seedUsers ( strapi : Strapi ) {
25
- const amountOfUsers = 10 ;
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 } ) ;
44
- }
45
- console . log ( "SUCCESS: Created user on bootstrap" ) ;
46
- } else {
47
- console . log ( "INFO: User have already been created on bootstrap" ) ;
48
- }
49
- } catch ( err ) {
50
- console . log ( "ERROR: Could not create users on bootstrap" ) ;
51
- console . log ( err ) ;
52
- }
53
- }
25
+ const amountOfUsers = 10 ;
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 } ) ;
44
+ }
45
+ console . log ( "SUCCESS: Created user on bootstrap" ) ;
46
+ } else {
47
+ console . log ( "INFO: User have already been created on bootstrap" ) ;
48
+ }
49
+ } catch ( err ) {
50
+ console . log ( "ERROR: Could not create users on bootstrap" ) ;
51
+ console . log ( err ) ;
52
+ }
53
+ }
0 commit comments