diff --git a/src/stores/employee.ts b/src/stores/employee.ts index a15d8ce..510088a 100644 --- a/src/stores/employee.ts +++ b/src/stores/employee.ts @@ -4,21 +4,17 @@ import { useUser } from './user' import { useNotifications } from './notifications' type ResultData = { - employee: { - id: number, - firstName: string, - lastName: string, - shorthand: string, - phone: string, - mobile: string, - email: string, - contractHours: number, - hasUser: boolean, - }, - user?: { - id?: number, - username?: string - } + id: number, + firstName: string, + lastName: string | undefined, + shorthand: string, + phone: string | undefined, + mobile: string | undefined, + email: string | undefined, + contractHours: number | undefined, + isActive: boolean, + username: string | undefined, + role: string } const user = useUser() @@ -39,14 +35,11 @@ export const useEmployee = defineStore({ mobile: '', email: '', contractHours: NaN, - hasUser: false - }, - user: { - id: NaN, + isActive: false, username: '', password: '', - passwordConfirm: '', - } + passwordConfirm: '' + }, }, employee: { @@ -58,15 +51,11 @@ export const useEmployee = defineStore({ mobile: '', email: '', contractHours: NaN, - hasUser: false - }, - - user: { - id: NaN, + isActive: false, username: '', password: '', passwordConfirm: '' - } + }, } }, @@ -75,15 +64,14 @@ export const useEmployee = defineStore({ try { const data : ResultData = await (await axios.get('employees/'+id, { - headers: { - 'Authorization': 'Bearer '+user.token - } + headers: user.header })).data - Object.assign(this.clean.employee, data.employee) - Object.assign(this.clean.user, data.user) - Object.assign(this.employee, data.employee), - Object.assign(this.user, data.user) + console.log(this.clean.employee) + console.log(data) + + Object.assign(this.clean.employee, data) + Object.assign(this.employee, data) } catch(err){ if(err instanceof Error) notifications.add('danger', err.message, -1) @@ -92,7 +80,6 @@ export const useEmployee = defineStore({ }, reset() { - Object.assign(this.user, this.clean.user) Object.assign(this.employee, this.clean.employee) }, @@ -101,30 +88,6 @@ export const useEmployee = defineStore({ try { let result - if(isNaN(this.user.id) && this.user.username.length > 0){ - result = await axios.post( - 'users', - { - username: this.user.username, - password: this.user.password - }, - { - headers: user.header - } - ) - } - else if (this.user.password.length > 0 && this.user.password === this.user.passwordConfirm){ - result = await axios.patch( - 'users/'+this.user.id, - { - password: this.user.password - }, - { - headers: user.header - } - ) - } - result = await axios.patch( 'employees/'+this.employee.id, this.employee, @@ -134,7 +97,6 @@ export const useEmployee = defineStore({ ) Object.assign(this.clean.employee, this.employee) - Object.assign(this.clean.user, this.user) notifications.add('success', result.statusText) } catch(error) { diff --git a/src/stores/user.ts b/src/stores/user.ts index b42080a..83926b7 100644 --- a/src/stores/user.ts +++ b/src/stores/user.ts @@ -33,11 +33,12 @@ export const useUser = defineStore({ }, actions: { - async login(username: string, password: string): Promise< - boolean | - 'E_INVALID_AUTH_PASSWORD: Password mis-match' | - 'E_INVALID_AUTH_UID: User not found' - > { + async login(username: string, password: string): + Promise< + boolean | + 'E_INVALID_AUTH_PASSWORD: Password mis-match' | + 'E_INVALID_AUTH_UID: User not found' + > { const notifications = useNotifications() diff --git a/src/views/EmployeesDetails.vue b/src/views/EmployeesDetails.vue index 2427fc0..463f833 100644 --- a/src/views/EmployeesDetails.vue +++ b/src/views/EmployeesDetails.vue @@ -3,10 +3,10 @@
Clean State
-{{ state.clean.user }} +{{ state.clean.employee }}
Dirty State
-{{ state.user }} +{{ state.employee }}
@@ -19,11 +19,11 @@ v-model.trim="state.employee.firstName" id="first-name" class="form-control" - :class="classIsInvalid(v$.employee.firstName)" + :class="classIsInvalid(v$.firstName)" :disabled="!editEmployee" >
{{error.$message}} @@ -38,10 +38,10 @@ v-model.trim="state.employee.shorthand" id="shorthand" class="form-control" - :class="classIsInvalid(v$.employee.shorthand)" + :class="classIsInvalid(v$.shorthand)" :disabled="!editEmployee" > -
+
{{ error.$message }}
@@ -57,10 +57,10 @@ v-model.trim="state.employee.email" id="email" class="form-control" - :class="classIsInvalid(v$.employee.email)" + :class="classIsInvalid(v$.email)" :disabled="!editEmployee" > -
+
{{error.$message}}
@@ -75,57 +75,57 @@ v-model.number="state.employee.contractHours" id="contract-hours" class="form-control" - :class="classIsInvalid(v$.employee.contractHours)" + :class="classIsInvalid(v$.contractHours)" :disabled="!editEmployee" > -
+
{{error.$message}}

Benutzerinformationen:

-