Skip to content

Commit

Permalink
feat: use correct user model attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
tboerger committed Jun 20, 2024
1 parent 21e30e2 commit c945bc5
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 57 deletions.
4 changes: 2 additions & 2 deletions src/pages/teams/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import { useTeamStore } from "../../store/teams";
import { useI18n } from "vue-i18n";
import type { general_error } from "../../client/models/general_error";
import type { notification } from "../../client/models/notification";
import type { team } from "../../client/models/team";
const router = useRouter();
Expand All @@ -72,7 +72,7 @@ const { t } = useI18n({
async function submit(data: team) {
return store
.createTeam(data)
.then((resp: void | general_error | team) => {
.then((resp: void | notification | team) => {
const val = <team>resp;
reset("create");
router.push({ name: "showTeam", params: { teamId: val.slug } });
Expand Down
4 changes: 2 additions & 2 deletions src/pages/teams/Update.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import { useTeamStore } from "../../store/teams";
import { useI18n } from "vue-i18n";
import type { general_error } from "../../client/models/general_error";
import type { notification } from "../../client/models/notification";
import type { team } from "../../client/models/team";
const store = useTeamStore();
Expand All @@ -92,7 +92,7 @@ const record = computed(() => {
function submit(data: team) {
return store
.updateTeam(<string>record.value.slug, data)
.then((resp: void | general_error | team) => {
.then((resp: void | notification | team) => {
const val = <team>resp;
reset("update", val);
router.push({ name: "showTeam", params: { teamId: val.slug } });
Expand Down
30 changes: 19 additions & 11 deletions src/pages/users/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@

<div class="m-5">
<FormKit id="create" type="form" submit-label="Create" @submit="submit">
<FormKit
id="slug"
type="text"
name="slug"
validation="length:3,64"
label="Slug"
help="Slug of your user"
/>
<FormKit
id="username"
type="text"
Expand All @@ -39,6 +31,14 @@
label="Username"
help="Username of your user"
/>
<FormKit
id="password"
type="text"
name="password"
validation="required|length:3,64"
label="Password"
help="Password of your user"
/>
<FormKit
id="email"
type="text"
Expand All @@ -47,6 +47,14 @@
label="Email"
help="Email of your user"
/>
<FormKit
id="fullname"
type="text"
name="fullname"
validation=""
label="Fullname"
help="Fullname of your user"
/>
<FormKit
id="admin"
type="checkbox"
Expand Down Expand Up @@ -77,7 +85,7 @@ import { useUserStore } from "../../store/users";
import { useI18n } from "vue-i18n";
import type { general_error } from "../../client/models/general_error";
import type { notification } from "../../client/models/notification";
import type { user } from "../../client/models/user";
const router = useRouter();
Expand All @@ -90,10 +98,10 @@ const { t } = useI18n({
async function submit(data: user) {
return store
.createUser(data)
.then((resp: void | general_error | user) => {
.then((resp: void | notification | user) => {
const val = <user>resp;
reset("create");
router.push({ name: "showUser", params: { userId: val.slug } });
router.push({ name: "showUser", params: { userId: val.username } });
})
.catch((e) => {
console.log(e);
Expand Down
14 changes: 7 additions & 7 deletions src/pages/users/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

<fwb-table v-if="getUsers.length > 0" class="m-5" hoverable>
<fwb-table-head>
<fwb-table-head-cell>{{ t("common.slug") }}</fwb-table-head-cell>
<fwb-table-head-cell>{{ t("users.username") }}</fwb-table-head-cell>
<fwb-table-head-cell>{{ t("users.email") }}</fwb-table-head-cell>
<fwb-table-head-cell>{{ t("users.fullname") }}</fwb-table-head-cell>
<fwb-table-head-cell>{{ t("users.admin") }}</fwb-table-head-cell>
<fwb-table-head-cell>{{ t("users.active") }}</fwb-table-head-cell>
<fwb-table-head-cell class="w-80"
Expand All @@ -31,22 +31,22 @@
</fwb-table-head>
<fwb-table-body>
<fwb-table-row v-for="row in getUsers" :key="row.id">
<fwb-table-cell>{{ row.slug }}</fwb-table-cell>
<fwb-table-cell>{{ row.username }}</fwb-table-cell>
<fwb-table-cell>{{ row.email }}</fwb-table-cell>
<fwb-table-cell>{{ row.fullname }}</fwb-table-cell>
<fwb-table-cell>{{ row.admin }}</fwb-table-cell>
<fwb-table-cell>{{ row.active }}</fwb-table-cell>
<fwb-table-cell>
<ShowAction
:to="{ name: 'showUser', params: { userId: row.slug } }"
:to="{ name: 'showUser', params: { userId: row.username } }"
tag="link"
/>
<UpdateAction
:to="{ name: 'updateUser', params: { userId: row.slug } }"
:to="{ name: 'updateUser', params: { userId: row.username } }"
tag="link"
/>
<DeleteAction
:handler="deleteRecord(<string>row.slug)"
:handler="deleteRecord(<string>row.username)"
:element="<string>row.username"
tag="link"
/>
Expand Down Expand Up @@ -114,10 +114,10 @@ const getUsers = computed(() => {
return store.users as user[];
});
function deleteRecord(slug: string) {
function deleteRecord(username: string) {
return () => {
store
.deleteUser(slug)
.deleteUser(username)
.then(() => {
store.fetchUsers();
})
Expand Down
22 changes: 11 additions & 11 deletions src/pages/users/Show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</router-link>
<router-link
v-slot="{ href }"
:to="{ name: 'showUser', params: { userId: record.slug } }"
:to="{ name: 'showUser', params: { userId: record.username } }"
custom
>
<fwb-breadcrumb-item :href="href">
Expand All @@ -23,10 +23,10 @@

<ContentHeader :title="t('users.title.show', [record.username])">
<UpdateAction
:to="{ name: 'updateUser', params: { userId: record.slug } }"
:to="{ name: 'updateUser', params: { userId: record.username } }"
/>
<DeleteAction
:handler="deleteRecord(<string>record.slug)"
:handler="deleteRecord(<string>record.username)"
:element="<string>record.username"
/>
</ContentHeader>
Expand All @@ -39,12 +39,6 @@
}}</fwb-table-head-cell>
<fwb-table-cell>{{ record.id }}</fwb-table-cell>
</fwb-table-row>
<fwb-table-row>
<fwb-table-head-cell class="text-right">{{
t("common.slug")
}}</fwb-table-head-cell>
<fwb-table-cell>{{ record.slug }}</fwb-table-cell>
</fwb-table-row>
<fwb-table-row>
<fwb-table-head-cell class="text-right">{{
t("users.username")
Expand All @@ -57,6 +51,12 @@
}}</fwb-table-head-cell>
<fwb-table-cell>{{ record.email }}</fwb-table-cell>
</fwb-table-row>
<fwb-table-row>
<fwb-table-head-cell class="text-right">{{
t("users.fullname")
}}</fwb-table-head-cell>
<fwb-table-cell>{{ record.fullname }}</fwb-table-cell>
</fwb-table-row>
<fwb-table-row>
<fwb-table-head-cell class="text-right">{{
t("users.admin")
Expand Down Expand Up @@ -104,10 +104,10 @@ const record = computed(() => {
return store.currentUser;
});
function deleteRecord(slug: string) {
function deleteRecord(username: string) {
return () => {
store
.deleteUser(slug)
.deleteUser(username)
.then(() => {
router.push({ name: "users" });
})
Expand Down
36 changes: 22 additions & 14 deletions src/pages/users/Update.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</router-link>
<router-link
v-slot="{ href }"
:to="{ name: 'showUser', params: { userId: record.slug } }"
:to="{ name: 'showUser', params: { userId: record.username } }"
custom
>
<fwb-breadcrumb-item :href="href">
Expand All @@ -21,7 +21,7 @@
</router-link>
<router-link
v-slot="{ href }"
:to="{ name: 'updateUser', params: { userId: record.slug } }"
:to="{ name: 'updateUser', params: { userId: record.username } }"
custom
>
<fwb-breadcrumb-item :href="href">{{
Expand All @@ -42,14 +42,6 @@
name="updateUser"
@submit="submit"
>
<FormKit
id="slug"
type="text"
name="slug"
validation="length:3,64"
label="Slug"
help="Slug of your user"
/>
<FormKit
id="username"
type="text"
Expand All @@ -58,6 +50,14 @@
label="Username"
help="Username of your user"
/>
<FormKit
id="password"
type="text"
name="password"
validation=""
label="Password"
help="Password of your user"
/>
<FormKit
id="email"
type="text"
Expand All @@ -66,6 +66,14 @@
label="Email"
help="Email of your user"
/>
<FormKit
id="fullname"
type="text"
name="fullname"
validation=""
label="Fullname"
help="Fullname of your user"
/>
<FormKit
id="admin"
type="checkbox"
Expand Down Expand Up @@ -98,7 +106,7 @@ import { useUserStore } from "../../store/users";
import { useI18n } from "vue-i18n";
import type { general_error } from "../../client/models/general_error";
import type { notification } from "../../client/models/notification";
import type { user } from "../../client/models/user";
const store = useUserStore();
Expand All @@ -115,11 +123,11 @@ const record = computed(() => {
function submit(data: user) {
return store
.updateUser(<string>record.value.slug, data)
.then((resp: void | general_error | user) => {
.updateUser(<string>record.value.username, data)
.then((resp: void | notification | user) => {
const val = <user>resp;
reset("update", val);
router.push({ name: "showUser", params: { userId: val.slug } });
router.push({ name: "showUser", params: { userId: val.username } });
})
.catch((e) => {
console.log(e);
Expand Down
6 changes: 3 additions & 3 deletions src/store/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineStore } from "pinia";
import { pick } from "./helpers";
import { Kleister } from "../client";

import type { general_error } from "../client/models/general_error";
import type { notification } from "../client/models/notification";
import type { teams } from "../client/models/teams";
import type { team } from "../client/models/team";

Expand All @@ -20,7 +20,7 @@ export const useTeamStore = defineStore("team", {
async fetchTeams() {
return client.team
.listTeams()
.then((resp: general_error | teams) => {
.then((resp: notification | teams) => {
const val = <teams>resp;
this.teams = <team[]>val.teams;
})
Expand All @@ -31,7 +31,7 @@ export const useTeamStore = defineStore("team", {
async fetchTeam(teamId: string) {
return client.team
.showTeam(teamId)
.then((resp: general_error | team) => {
.then((resp: notification | team) => {
const val = <team>resp;
this.currentTeam = val;
})
Expand Down
12 changes: 5 additions & 7 deletions src/store/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineStore } from "pinia";
import { pick } from "./helpers";
import { Kleister } from "../client";

import type { general_error } from "../client/models/general_error";
import type { notification } from "../client/models/notification";
import type { users } from "../client/models/users";
import type { user } from "../client/models/user";

Expand All @@ -20,7 +20,7 @@ export const useUserStore = defineStore("user", {
async fetchUsers() {
return client.user
.listUsers()
.then((resp: general_error | users) => {
.then((resp: notification | users) => {
const val = <users>resp;
this.users = <user[]>val.users;
})
Expand All @@ -31,7 +31,7 @@ export const useUserStore = defineStore("user", {
async fetchUser(userId: string) {
return client.user
.showUser(userId)
.then((resp: general_error | user) => {
.then((resp: notification | user) => {
const val = <user>resp;
this.currentUser = val;
})
Expand All @@ -49,10 +49,9 @@ export const useUserStore = defineStore("user", {
.createUser(
pick(
data,
"slug",
"email",
"username",
"password",
"email",
"fullname",
"admin",
"active",
Expand All @@ -68,10 +67,9 @@ export const useUserStore = defineStore("user", {
userId,
pick(
data,
"slug",
"email",
"username",
"password",
"email",
"fullname",
"admin",
"active",
Expand Down

0 comments on commit c945bc5

Please sign in to comment.