-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from AplinkosMinisterija/fix-seeds
Fixing seeds - double check before creating
- Loading branch information
Showing
2 changed files
with
59 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,9 @@ POSTMARK_PASSWORD_RESET_TEMPLATE_ID= | |
|
||
RECAPTCHA_SECRET=secret | ||
|
||
SENTRY_DSN= | ||
SENTRY_DSN= | ||
|
||
DEFAULT_SUPER_ADMIN_EMAIL=[email protected] | ||
DEFAULT_SUPER_ADMIN_PASSWORD=Slaptazodis1@ | ||
DEFAULT_ADMIN_APP_URL=https://admin.biip.lt | ||
DEFAULT_PROJECT_NAME_GENITIVE=BĮIP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,35 +11,58 @@ import { AppType } from './apps.service'; | |
export default class SeedService extends moleculer.Service { | ||
@Action() | ||
async real(ctx: Context<Record<string, unknown>>) { | ||
// create apps | ||
await ctx.call('apps.create', { | ||
name: 'Admin', | ||
type: AppType.ADMIN, | ||
url: 'https://admin.biip.lt', | ||
settings: { | ||
productNameTo: 'BĮIP administravimo sistemos', | ||
}, | ||
}); | ||
|
||
await ctx.call('apps.create', { | ||
name: 'Vidiniai naudotojai', | ||
type: AppType.USERS, | ||
url: 'https://admin.biip.lt', | ||
settings: { | ||
productNameTo: 'BĮĮP naudotojų valdymo sistemos', | ||
}, | ||
}); | ||
const adminEmail = process.env.DEFAULT_SUPER_ADMIN_EMAIL || '[email protected]'; | ||
const adminPassword = process.env.DEFAULT_SUPER_ADMIN_PASSWORD || 'Slaptazodis1@'; | ||
const adminAppUrl = process.env.DEFAULT_ADMIN_APP_URL || 'https://admin.biip.lt'; | ||
const projectNameGenitive = process.env.DEFAULT_PROJECT_NAME_GENITIVE || 'BĮIP'; | ||
const adminAppExists = await ctx.call('apps.count', { query: { type: AppType.ADMIN } }); | ||
const usersAppExists = await ctx.call('apps.count', { query: { type: AppType.USERS } }); | ||
const userExists = await ctx.call('users.count', { query: { email: adminEmail } }); | ||
|
||
// create local user | ||
await ctx.call('usersLocal.invite', { | ||
email: '[email protected]', | ||
firstName: 'Super', | ||
lastName: 'Admin', | ||
password: 'Slaptazodis1@', | ||
phone: '+37060000000', | ||
type: UserType.SUPER_ADMIN, | ||
doNotSendEmail: true, | ||
}); | ||
if (!adminAppExists) { | ||
// create admin app | ||
await ctx.call('apps.create', { | ||
name: 'Admin', | ||
type: AppType.ADMIN, | ||
url: adminAppUrl, | ||
settings: { | ||
productNameTo: `${projectNameGenitive} administravimo sistemos`, | ||
}, | ||
}); | ||
} | ||
|
||
if (!usersAppExists) { | ||
// create users app | ||
await ctx.call('apps.create', { | ||
name: 'Vidiniai naudotojai', | ||
type: AppType.USERS, | ||
url: adminAppUrl, | ||
settings: { | ||
productNameTo: `${projectNameGenitive} naudotojų valdymo sistemos`, | ||
}, | ||
}); | ||
} | ||
|
||
if (!userExists) { | ||
// create super admin user | ||
await ctx.call( | ||
'usersLocal.invite', | ||
{ | ||
email: adminEmail, | ||
firstName: 'Super', | ||
lastName: 'Admin', | ||
password: adminPassword, | ||
phone: '+37060000000', | ||
type: UserType.SUPER_ADMIN, | ||
doNotSendEmail: true, | ||
}, | ||
{ | ||
meta: { | ||
hasPermissions: true, | ||
}, | ||
}, | ||
); | ||
} | ||
|
||
return true; | ||
} | ||
|
@@ -58,8 +81,9 @@ export default class SeedService extends moleculer.Service { | |
.waitForServices(['users', 'usersLocal', 'apps', 'groups', 'permissions']) | ||
.then(async () => { | ||
const usersCount: number = await this.broker.call('users.count'); | ||
const appsCount: number = await this.broker.call('apps.count'); | ||
|
||
if (usersCount === 0) { | ||
if (!usersCount || !appsCount) { | ||
await this.broker.call('seed.real', {}, { timeout: 120 * 1000 }); | ||
} | ||
}); | ||
|