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