Included user-information in employee Model.

This commit is contained in:
Sockenklaus
2021-11-04 14:00:13 +01:00
parent 63c1407643
commit 3d2e551a8e
13 changed files with 171 additions and 217 deletions

View File

@@ -18,11 +18,15 @@ export default class Employees extends BaseSchema {
table.string('email')
table.string('phone')
table.string('mobile')
table.string('username').unique()
table.string('password')
table.string('role')
.defaultTo('employee')
.notNullable()
table.boolean('is_active')
.defaultTo(false)
.notNullable()
table.decimal('contract_hours', 2, 2)
table
.integer('user_id')
.unsigned()
.references('users.id')
})
}

View File

@@ -1,25 +0,0 @@
import BaseSchema from '@ioc:Adonis/Lucid/Schema'
export default class Users extends BaseSchema {
protected tableName = 'users'
public async up () {
this.schema.createTable(this.tableName, (table) => {
table.increments('id')
/**
* Uses timestamptz for PostgreSQL and DATETIME2 for MSSQL
*/
table.timestamp('created_at', { useTz: true })
table.timestamp('updated_at', { useTz: true })
table.string('username').notNullable().unique()
table.string('email').notNullable().unique()
table.string('password').notNullable()
})
}
public async down () {
this.schema.dropTable(this.tableName)
}
}

View File

@@ -1,23 +0,0 @@
import Hash from '@ioc:Adonis/Core/Hash'
import BaseSchema from '@ioc:Adonis/Lucid/Schema'
import User from 'App/Models/User'
export default class Users extends BaseSchema {
protected tableName = 'users'
public async up () {
this.schema.alterTable(this.tableName, (table) => {
table.boolean('is_active').defaultTo(false)
table.string('role')
.defaultTo('employee')
.notNullable()
})
}
public async down () {
this.schema.alterTable(this.tableName, (table) => {
table.dropColumn('is_active')
table.dropColumn('role')
})
}
}

View File

@@ -6,7 +6,7 @@ export default class ApiTokens extends BaseSchema {
public async up() {
this.schema.createTable(this.tableName, (table) => {
table.increments('id').primary()
table.integer('user_id').unsigned().references('id').inTable('users').onDelete('CASCADE')
table.integer('user_id').unsigned().references('id').inTable('employee').onDelete('CASCADE')
table.string('name').notNullable()
table.string('type').notNullable()
table.string('token', 64).notNullable().unique()

View File

@@ -11,18 +11,26 @@ export default class EmployeeSeeder extends BaseSeeder {
firstName: 'Max',
lastName: 'Mustermann',
shorthand: 'MM',
userId: 1
username: 'admin',
password: 'admin',
isActive: true,
role: 'admin'
},
{
firstName: 'Jane',
lastName: 'Doe',
shorthand: 'JD',
userId: 2
username: 'user',
password: 'user',
isActive: true,
role: 'employee'
},
{
firstName: 'Bingo',
lastName: 'Bongo',
shorthand: 'BB'
shorthand: 'BB',
isActive: false,
role: 'employee'
}
])
} catch (error) {

View File

@@ -1,28 +0,0 @@
import BaseSeeder from '@ioc:Adonis/Lucid/Seeder'
import User from 'App/Models/User'
import Logger from '@ioc:Adonis/Core/Logger'
export default class UserSeeder extends BaseSeeder {
public async run () {
try {
await User.create({
username: 'admin',
password: 'admin',
role: 'admin',
email: 'test@test.de',
isActive: true
})
await User.create({
username: 'user',
password: 'user',
role: 'employee',
email: 'user@test.de',
isActive: true
})
}
catch(error) {
Logger.error(error.message)
}
}
}