feat: add POST /api/v1/installation/users to seed user

This commit is contained in:
Ali BARIN
2024-05-07 15:39:22 +00:00
parent 717c81fa2b
commit b30f97db3e
9 changed files with 143 additions and 0 deletions

View File

@@ -13,6 +13,28 @@ class Config extends Base {
value: { type: 'object' },
},
};
static async isInstallationCompleted() {
const installationCompletedEntry = await this
.query()
.where({
key: 'installation.completed'
})
.first();
const installationCompleted = installationCompletedEntry?.value?.data === true;
return installationCompleted;
}
static async markInstallationCompleted() {
return await this.query().insert({
key: 'installation.completed',
value: {
data: true,
},
});
}
}
export default Config;

View File

@@ -45,6 +45,10 @@ class Role extends Base {
get isAdmin() {
return this.key === 'admin';
}
static async findAdmin() {
return await this.query().findOne({ key: 'admin' });
}
}
export default Role;

View File

@@ -373,6 +373,19 @@ class User extends Base {
return apps;
}
static async createAdminUser({ email, password, fullName }) {
const adminRole = await Role.findAdmin();
const adminUser = await this.query().insert({
email,
password,
fullName,
roleId: adminRole.id
});
return adminUser;
}
async $beforeInsert(queryContext) {
await super.$beforeInsert(queryContext);