form state rewrite

This commit is contained in:
Julian Krauser 2024-09-15 13:52:54 +02:00
parent 5e50b85631
commit b0ea9d13e7
40 changed files with 1123 additions and 1070 deletions

View file

@ -1,92 +1,49 @@
import { defineStore } from "pinia";
import type { CreateOrUpdateAwardViewModel, AwardViewModel } from "../../viewmodels/admin/award.models";
import type { CreateAwardViewModel, UpdateAwardViewModel, AwardViewModel } from "../../viewmodels/admin/award.models";
import { http } from "../../serverCom";
import type { AxiosResponse } from "axios";
export const useAwardStore = defineStore("award", {
state: () => {
return {
awards: [] as Array<AwardViewModel>,
award: null as null | AwardViewModel,
loadingAll: "loading" as "loading" | "fetched" | "failed",
loadingSingle: "loading" as "loading" | "fetched" | "failed",
createStatus: null as null | "loading" | { status: "success" | "failed"; reason?: string },
updateStatus: null as null | "loading" | { status: "success" | "failed"; reason?: string },
deleteStatus: null as null | "loading" | { status: "success" | "failed"; reason?: string },
loading: "loading" as "loading" | "fetched" | "failed",
};
},
actions: {
resetStatus() {
this.createStatus = null;
this.updateStatus = null;
this.deleteStatus = null;
},
fetchAwards() {
this.loadingAll = "loading";
this.loading = "loading";
http
.get("/admin/award")
.then((result) => {
this.awards = result.data;
this.loadingAll = "fetched";
this.loading = "fetched";
})
.catch((err) => {
this.loadingAll = "failed";
this.loading = "failed";
});
},
fetchAwardById(id: number) {
this.award = null;
this.loadingSingle = "loading";
http
.get(`/admin/award/${id}`)
.then((result) => {
this.award = result.data;
this.loadingSingle = "fetched";
})
.catch((err) => {
this.loadingSingle = "failed";
});
fetchAwardById(id: number): Promise<AxiosResponse<any, any>> {
return http.get(`/admin/award/${id}`);
},
createAward(award: CreateOrUpdateAwardViewModel) {
this.createStatus = "loading";
http
.post(`/admin/award`, {
award: award.award,
})
.then((result) => {
this.createStatus = { status: "success" };
this.fetchAwards();
})
.catch((err) => {
this.createStatus = { status: "failed" };
});
async createAward(award: CreateAwardViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.post(`/admin/award`, {
award: award.award,
});
this.fetchAwards();
return result;
},
updateActiveAward(award: CreateOrUpdateAwardViewModel) {
if (this.award == null) return;
let id = this.award.id;
this.updateStatus = "loading";
http
.patch(`/admin/award/${id}`, {
award: award.award,
})
.then((result) => {
this.updateStatus = { status: "success" };
this.fetchAwardById(id);
this.fetchAwards();
})
.catch((err) => {
this.updateStatus = { status: "failed" };
});
async updateActiveAward(award: UpdateAwardViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/award/${award.id}`, {
award: award.award,
});
this.fetchAwards();
return result;
},
deleteAward(award: number) {
this.deleteStatus = "loading";
http
.delete(`/admin/award/${award}`)
.then((res) => {
this.deleteStatus = { status: "success" };
this.fetchAwards();
})
.catch((err) => {
this.deleteStatus = { status: "failed", reason: err.data };
});
async deleteAward(award: number): Promise<AxiosResponse<any, any>> {
const result = await http.delete(`/admin/award/${award}`);
this.fetchAwards();
return result;
},
},
});

View file

@ -1,54 +1,36 @@
import { defineStore } from "pinia";
import type {
CreateOrUpdateCommunicationTypeViewModel,
CreateCommunicationTypeViewModel,
UpdateCommunicationTypeViewModel,
CommunicationTypeViewModel,
} from "../../viewmodels/admin/communicationType.models";
import { http } from "../../serverCom";
import type { AxiosResponse } from "axios";
export const useCommunicationTypeStore = defineStore("communicationType", {
state: () => {
return {
communicationTypes: [] as Array<CommunicationTypeViewModel>,
communicationType: null as null | CommunicationTypeViewModel,
availableFields: [] as Array<string>,
loadingAll: "loading" as "loading" | "fetched" | "failed",
loadingSingle: "loading" as "loading" | "fetched" | "failed",
loading: "loading" as "loading" | "fetched" | "failed",
loadingFields: "loading" as "loading" | "fetched" | "failed",
createStatus: null as null | "loading" | { status: "success" | "failed"; reason?: string },
updateStatus: null as null | "loading" | { status: "success" | "failed"; reason?: string },
deleteStatus: null as null | "loading" | { status: "success" | "failed"; reason?: string },
};
},
actions: {
resetStatus() {
this.createStatus = null;
this.updateStatus = null;
this.deleteStatus = null;
},
fetchCommunicationTypes() {
this.loadingAll = "loading";
this.loading = "loading";
http
.get("/admin/communicationType")
.then((result) => {
this.communicationTypes = result.data;
this.loadingAll = "fetched";
this.loading = "fetched";
})
.catch((err) => {
this.loadingAll = "failed";
this.loading = "failed";
});
},
fetchCommunicationTypeById(id: number) {
this.communicationType = null;
this.loadingSingle = "loading";
http
.get(`/admin/communicationType/${id}`)
.then((result) => {
this.communicationType = result.data;
this.loadingSingle = "fetched";
})
.catch((err) => {
this.loadingSingle = "failed";
});
fetchCommunicationTypeById(id: number): Promise<AxiosResponse<any, any>> {
return http.get(`/admin/communicationType/${id}`);
},
fetchAvailableFields() {
this.loadingFields = "loading";
@ -62,50 +44,30 @@ export const useCommunicationTypeStore = defineStore("communicationType", {
this.loadingFields = "failed";
});
},
createCommunicationType(communicationType: CreateOrUpdateCommunicationTypeViewModel) {
this.createStatus = "loading";
http
.post(`/admin/communicationType`, {
communicationType: communicationType.type,
fields: communicationType.fields,
})
.then((result) => {
this.createStatus = { status: "success" };
this.fetchCommunicationTypes();
})
.catch((err) => {
this.createStatus = { status: "failed" };
});
async createCommunicationType(
communicationType: CreateCommunicationTypeViewModel
): Promise<AxiosResponse<any, any>> {
const result = await http.post(`/admin/communicationType`, {
communicationType: communicationType.type,
fields: communicationType.fields,
});
this.fetchCommunicationTypes();
return result;
},
updateActiveCommunicationType(communicationType: CreateOrUpdateCommunicationTypeViewModel) {
if (this.communicationType == null) return;
let id = this.communicationType.id;
this.updateStatus = "loading";
http
.patch(`/admin/communicationType/${id}`, {
communicationType: communicationType.type,
fields: communicationType.fields,
})
.then((result) => {
this.updateStatus = { status: "success" };
this.fetchCommunicationTypeById(id);
this.fetchCommunicationTypes();
})
.catch((err) => {
this.updateStatus = { status: "failed" };
});
async updateActiveCommunicationType(
communicationType: UpdateCommunicationTypeViewModel
): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/communicationType/${communicationType.id}`, {
communicationType: communicationType.type,
fields: communicationType.fields,
});
this.fetchCommunicationTypes();
return result;
},
deleteCommunicationType(communicationType: number) {
this.deleteStatus = "loading";
http
.delete(`/admin/communicationType/${communicationType}`)
.then((res) => {
this.deleteStatus = { status: "success" };
this.fetchCommunicationTypes();
})
.catch((err) => {
this.deleteStatus = { status: "failed", reason: err.data };
});
async deleteCommunicationType(communicationType: number): Promise<AxiosResponse<any, any>> {
const result = await http.delete(`/admin/communicationType/${communicationType}`);
this.fetchCommunicationTypes();
return result;
},
},
});

View file

@ -1,95 +1,55 @@
import { defineStore } from "pinia";
import type {
CreateOrUpdateExecutivePositionViewModel,
CreateExecutivePositionViewModel,
UpdateExecutivePositionViewModel,
ExecutivePositionViewModel,
} from "../../viewmodels/admin/executivePosition.models";
import { http } from "../../serverCom";
import type { AxiosResponse } from "axios";
export const useExecutivePositionStore = defineStore("executivePosition", {
state: () => {
return {
executivePositions: [] as Array<ExecutivePositionViewModel>,
executivePosition: null as null | ExecutivePositionViewModel,
loadingAll: "loading" as "loading" | "fetched" | "failed",
loadingSingle: "loading" as "loading" | "fetched" | "failed",
createStatus: null as null | "loading" | { status: "success" | "failed"; reason?: string },
updateStatus: null as null | "loading" | { status: "success" | "failed"; reason?: string },
deleteStatus: null as null | "loading" | { status: "success" | "failed"; reason?: string },
loading: "loading" as "loading" | "fetched" | "failed",
};
},
actions: {
resetStatus() {
this.createStatus = null;
this.updateStatus = null;
this.deleteStatus = null;
},
fetchExecutivePositions() {
this.loadingAll = "loading";
this.loading = "loading";
http
.get("/admin/executivePosition")
.then((result) => {
this.executivePositions = result.data;
this.loadingAll = "fetched";
this.loading = "fetched";
})
.catch((err) => {
this.loadingAll = "failed";
this.loading = "failed";
});
},
fetchExecutivePositionById(id: number) {
this.executivePosition = null;
this.loadingSingle = "loading";
http
.get(`/admin/executivePosition/${id}`)
.then((result) => {
this.executivePosition = result.data;
this.loadingSingle = "fetched";
})
.catch((err) => {
this.loadingSingle = "failed";
});
fetchExecutivePositionById(id: number): Promise<AxiosResponse<any, any>> {
return http.get(`/admin/executivePosition/${id}`);
},
createExecutivePosition(executivePosition: CreateOrUpdateExecutivePositionViewModel) {
this.createStatus = "loading";
http
.post(`/admin/executivePosition`, {
executivePosition: executivePosition.position,
})
.then((result) => {
this.createStatus = { status: "success" };
this.fetchExecutivePositions();
})
.catch((err) => {
this.createStatus = { status: "failed" };
});
async createExecutivePosition(executivePosition: CreateExecutivePositionViewModel) {
const result = await http.post(`/admin/executivePosition`, {
executivePosition: executivePosition.position,
});
this.fetchExecutivePositions();
return result;
},
updateActiveExecutivePosition(executivePosition: CreateOrUpdateExecutivePositionViewModel) {
if (this.executivePosition == null) return;
let id = this.executivePosition.id;
this.updateStatus = "loading";
http
.patch(`/admin/executivePosition/${id}`, {
executivePosition: executivePosition.position,
})
.then((result) => {
this.updateStatus = { status: "success" };
this.fetchExecutivePositionById(id);
this.fetchExecutivePositions();
})
.catch((err) => {
this.updateStatus = { status: "failed" };
});
async updateActiveExecutivePosition(
executivePosition: UpdateExecutivePositionViewModel
): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/executivePosition/${executivePosition.id}`, {
executivePosition: executivePosition.position,
});
this.fetchExecutivePositions();
return result;
},
deleteExecutivePosition(executivePosition: number) {
this.deleteStatus = "loading";
http
.delete(`/admin/executivePosition/${executivePosition}`)
.then((res) => {
this.deleteStatus = { status: "success" };
this.fetchExecutivePositions();
})
.catch((err) => {
this.deleteStatus = { status: "failed", reason: err.data };
});
async deleteExecutivePosition(executivePosition: number) {
const result = await http.delete(`/admin/executivePosition/${executivePosition}`);
this.fetchExecutivePositions();
return result;
},
},
});

View file

@ -1,95 +1,55 @@
import { defineStore } from "pinia";
import type {
CreateOrUpdateMembershipStatusViewModel,
CreateMembershipStatusViewModel,
UpdateMembershipStatusViewModel,
MembershipStatusViewModel,
} from "../../viewmodels/admin/membershipStatus.models";
import { http } from "../../serverCom";
import type { AxiosResponse } from "axios";
export const useMembershipStatusStore = defineStore("membershipStatus", {
state: () => {
return {
membershipStatuss: [] as Array<MembershipStatusViewModel>,
membershipStatus: null as null | MembershipStatusViewModel,
loadingAll: "loading" as "loading" | "fetched" | "failed",
loadingSingle: "loading" as "loading" | "fetched" | "failed",
createStatus: null as null | "loading" | { status: "success" | "failed"; reason?: string },
updateStatus: null as null | "loading" | { status: "success" | "failed"; reason?: string },
deleteStatus: null as null | "loading" | { status: "success" | "failed"; reason?: string },
membershipStatus: [] as Array<MembershipStatusViewModel>,
loading: "loading" as "loading" | "fetched" | "failed",
};
},
actions: {
resetStatus() {
this.createStatus = null;
this.updateStatus = null;
this.deleteStatus = null;
},
fetchMembershipStatuss() {
this.loadingAll = "loading";
fetchMembershipStatus() {
this.loading = "loading";
http
.get("/admin/membershipStatus")
.then((result) => {
this.membershipStatuss = result.data;
this.loadingAll = "fetched";
})
.catch((err) => {
this.loadingAll = "failed";
});
},
fetchMembershipStatusById(id: number) {
this.membershipStatus = null;
this.loadingSingle = "loading";
http
.get(`/admin/membershipStatus/${id}`)
.then((result) => {
this.membershipStatus = result.data;
this.loadingSingle = "fetched";
this.loading = "fetched";
})
.catch((err) => {
this.loadingSingle = "failed";
this.loading = "failed";
});
},
createMembershipStatus(membershipStatus: CreateOrUpdateMembershipStatusViewModel) {
this.createStatus = "loading";
http
.post(`/admin/membershipStatus`, {
membershipStatus: membershipStatus.status,
})
.then((result) => {
this.createStatus = { status: "success" };
this.fetchMembershipStatuss();
})
.catch((err) => {
this.createStatus = { status: "failed" };
});
fetchMembershipStatusById(id: number): Promise<AxiosResponse<any, any>> {
return http.get(`/admin/membershipStatus/${id}`);
},
updateActiveMembershipStatus(membershipStatus: CreateOrUpdateMembershipStatusViewModel) {
if (this.membershipStatus == null) return;
let id = this.membershipStatus.id;
this.updateStatus = "loading";
http
.patch(`/admin/membershipStatus/${id}`, {
membershipStatus: membershipStatus.status,
})
.then((result) => {
this.updateStatus = { status: "success" };
this.fetchMembershipStatusById(id);
this.fetchMembershipStatuss();
})
.catch((err) => {
this.updateStatus = { status: "failed" };
});
async createMembershipStatus(membershipStatus: CreateMembershipStatusViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.post(`/admin/membershipStatus`, {
membershipStatus: membershipStatus.status,
});
this.fetchMembershipStatus();
return result;
},
deleteMembershipStatus(membershipStatus: number) {
this.deleteStatus = "loading";
http
.delete(`/admin/membershipStatus/${membershipStatus}`)
.then((res) => {
this.deleteStatus = { status: "success" };
this.fetchMembershipStatuss();
})
.catch((err) => {
this.deleteStatus = { status: "failed", reason: err.data };
});
async updateActiveMembershipStatus(
membershipStatus: UpdateMembershipStatusViewModel
): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/membershipStatus/${membershipStatus.id}`, {
membershipStatus: membershipStatus.status,
});
this.fetchMembershipStatus();
return result;
},
async deleteMembershipStatus(membershipStatus: number): Promise<AxiosResponse<any, any>> {
const result = await http.delete(`/admin/membershipStatus/${membershipStatus}`);
this.fetchMembershipStatus();
return result;
},
},
});

View file

@ -1,97 +1,55 @@
import { defineStore } from "pinia";
import type {
CreateOrUpdateQualificationViewModel,
CreateQualificationViewModel,
UpdateQualificationViewModel,
QualificationViewModel,
} from "../../viewmodels/admin/qualification.models";
import { http } from "../../serverCom";
import type { AxiosResponse } from "axios";
export const useQualificationStore = defineStore("qualification", {
state: () => {
return {
qualifications: [] as Array<QualificationViewModel>,
qualification: null as null | QualificationViewModel,
loadingAll: "loading" as "loading" | "fetched" | "failed",
loadingSingle: "loading" as "loading" | "fetched" | "failed",
createStatus: null as null | "loading" | { status: "success" | "failed"; reason?: string },
updateStatus: null as null | "loading" | { status: "success" | "failed"; reason?: string },
deleteStatus: null as null | "loading" | { status: "success" | "failed"; reason?: string },
loading: "loading" as "loading" | "fetched" | "failed",
};
},
actions: {
resetStatus() {
this.createStatus = null;
this.updateStatus = null;
this.deleteStatus = null;
},
fetchQualifications() {
this.loadingAll = "loading";
this.loading = "loading";
http
.get("/admin/qualification")
.then((result) => {
this.qualifications = result.data;
this.loadingAll = "fetched";
this.loading = "fetched";
})
.catch((err) => {
this.loadingAll = "failed";
this.loading = "failed";
});
},
fetchQualificationById(id: number) {
this.qualification = null;
this.loadingSingle = "loading";
http
.get(`/admin/qualification/${id}`)
.then((result) => {
this.qualification = result.data;
this.loadingSingle = "fetched";
})
.catch((err) => {
this.loadingSingle = "failed";
});
fetchQualificationById(id: number): Promise<AxiosResponse<any, any>> {
return http.get(`/admin/qualification/${id}`);
},
createQualification(qualification: CreateOrUpdateQualificationViewModel) {
this.createStatus = "loading";
http
.post(`/admin/qualification`, {
qualification: qualification.qualification,
description: qualification.description,
})
.then((result) => {
this.createStatus = { status: "success" };
this.fetchQualifications();
})
.catch((err) => {
this.createStatus = { status: "failed" };
});
async createQualification(qualification: CreateQualificationViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.post(`/admin/qualification`, {
qualification: qualification.qualification,
description: qualification.description,
});
this.fetchQualifications();
return result;
},
updateActiveQualification(qualification: CreateOrUpdateQualificationViewModel) {
if (this.qualification == null) return;
let id = this.qualification.id;
this.updateStatus = "loading";
http
.patch(`/admin/qualification/${id}`, {
qualification: qualification.qualification,
description: qualification.description,
})
.then((result) => {
this.updateStatus = { status: "success" };
this.fetchQualificationById(id);
this.fetchQualifications();
})
.catch((err) => {
this.updateStatus = { status: "failed" };
});
async updateActiveQualification(qualification: UpdateQualificationViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/qualification/${qualification.id}`, {
qualification: qualification.qualification,
description: qualification.description,
});
this.fetchQualifications();
return result;
},
deleteQualification(qualification: number) {
this.deleteStatus = "loading";
http
.delete(`/admin/qualification/${qualification}`)
.then((res) => {
this.deleteStatus = { status: "success" };
this.fetchQualifications();
})
.catch((err) => {
this.deleteStatus = { status: "failed", reason: err.data };
});
async deleteQualification(qualification: number): Promise<AxiosResponse<any, any>> {
const result = await http.delete(`/admin/qualification/${qualification}`);
this.fetchQualifications();
return result;
},
},
});

View file

@ -2,109 +2,56 @@ import { defineStore } from "pinia";
import type { RoleViewModel } from "../../viewmodels/admin/role.models";
import { http } from "../../serverCom";
import type { PermissionObject } from "../../types/permissionTypes";
import type { AxiosResponse } from "axios";
export const useRoleStore = defineStore("role", {
state: () => {
return {
roles: [] as Array<RoleViewModel>,
role: null as null | RoleViewModel,
loadingAll: null as null | "loading" | "success" | "failed",
loadingSingle: null as null | "loading" | "success" | "failed",
createStatus: null as null | "loading" | { status: "success" | "failed"; reason?: string },
updateStatus: null as null | "loading" | { status: "success" | "failed"; reason?: string },
deleteStatus: null as null | "loading" | { status: "success" | "failed"; reason?: string },
loading: null as null | "loading" | "success" | "failed",
};
},
actions: {
resetStatus() {
this.createStatus = null;
this.updateStatus = null;
this.deleteStatus = null;
},
fetchRoles() {
this.loadingAll = "loading";
this.loading = "loading";
http
.get("/admin/role")
.then((result) => {
this.roles = result.data;
this.loadingAll = "success";
this.loading = "success";
})
.catch((err) => {
this.loadingAll = "failed";
this.loading = "failed";
});
},
fetchRoleById(id: number) {
this.role = null;
this.loadingSingle = "loading";
http
.get(`/admin/role/${id}`)
.then((result) => {
this.role = result.data;
this.loadingSingle = "success";
})
.catch((err) => {
this.loadingSingle = "failed";
});
fetchRoleById(id: number): Promise<AxiosResponse<any, any>> {
return http.get(`/admin/role/${id}`);
},
createRole(role: string) {
this.createStatus = "loading";
http
.post("/admin/role", {
role: role,
})
.then((res) => {
this.createStatus = { status: "success" };
this.fetchRoles();
})
.catch((err) => {
this.createStatus = { status: "failed", reason: err.data };
});
async createRole(role: string): Promise<AxiosResponse<any, any>> {
const result = await http.post("/admin/role", {
role: role,
});
this.fetchRoles();
return result;
},
updateActiveRole(role: string) {
if (this.role == null) return;
let id = this.role.id;
this.updateStatus = "loading";
http
.patch(`/admin/role/${id}`, {
role: role,
})
.then((result) => {
this.updateStatus = { status: "success" };
this.fetchRoleById(id);
this.fetchRoles();
})
.catch((err) => {
this.updateStatus = { status: "failed" };
});
async updateActiveRole(id: number, role: string): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/role/${id}`, {
role: role,
});
this.fetchRoles();
return result;
},
updateActiveRolePermissions(permission: PermissionObject) {
if (this.role == null) return;
let id = this.role.id;
this.updateStatus = "loading";
http
.patch(`/admin/role/${id}/permissions`, {
permissions: permission,
})
.then((result) => {
this.updateStatus = { status: "success" };
this.fetchRoleById(id);
this.fetchRoles();
})
.catch((err) => {
this.updateStatus = { status: "failed" };
});
async updateActiveRolePermissions(role: number, permission: PermissionObject): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/role/${role}/permissions`, {
permissions: permission,
});
this.fetchRoles();
return result;
},
deleteRole(role: number) {
this.deleteStatus = "loading";
http
.delete(`/admin/role/${role}`)
.then((res) => {
this.deleteStatus = { status: "success" };
this.fetchRoles();
})
.catch((err) => {
this.deleteStatus = { status: "failed", reason: err.data };
});
async deleteRole(role: number): Promise<AxiosResponse<any, any>> {
const result = await http.delete(`/admin/role/${role}`);
this.fetchRoles();
return result;
},
},
});

View file

@ -1,116 +1,70 @@
import { defineStore } from "pinia";
import type { CreateOrUpdateUserViewModel, UserViewModel } from "../../viewmodels/admin/user.models";
import type { UpdateUserViewModel, UserViewModel } from "../../viewmodels/admin/user.models";
import { http } from "../../serverCom";
import type { PermissionObject } from "../../types/permissionTypes";
import type { AxiosResponse } from "axios";
export const useUserStore = defineStore("user", {
state: () => {
return {
users: [] as Array<UserViewModel>,
user: null as null | UserViewModel,
loadingAll: "loading" as "loading" | "fetched" | "failed",
loadingSingle: "loading" as "loading" | "fetched" | "failed",
createStatus: null as null | "loading" | { status: "success" | "failed"; reason?: string },
updateStatus: null as null | "loading" | { status: "success" | "failed"; reason?: string },
deleteStatus: null as null | "loading" | { status: "success" | "failed"; reason?: string },
loading: "loading" as "loading" | "fetched" | "failed",
};
},
actions: {
resetStatus() {
this.createStatus = null;
this.updateStatus = null;
this.deleteStatus = null;
},
fetchUsers() {
this.loadingAll = "loading";
this.loading = "loading";
http
.get("/admin/user")
.then((result) => {
this.users = result.data;
this.loadingAll = "fetched";
this.loading = "fetched";
})
.catch((err) => {
this.loadingAll = "failed";
this.loading = "failed";
});
},
fetchUserById(id: number) {
this.user = null;
this.loadingSingle = "loading";
http
.get(`/admin/user/${id}`)
.then((result) => {
this.user = result.data;
this.loadingSingle = "fetched";
})
.catch((err) => {
this.loadingSingle = "failed";
});
fetchUserById(id: number): Promise<AxiosResponse<any, any>> {
return http.get(`/admin/user/${id}`);
},
updateActiveUser(user: CreateOrUpdateUserViewModel) {
if (this.user == null) return;
let id = this.user.id;
this.updateStatus = "loading";
http
.patch(`/admin/user/${id}`, {
updateActiveUser(user: UpdateUserViewModel): Promise<AxiosResponse<any, any>> {
return http
.patch(`/admin/user/${user.id}`, {
username: user.username,
firstname: user.firstname,
lastname: user.lastname,
mail: user.mail,
})
.then((result) => {
this.updateStatus = { status: "success" };
this.fetchUserById(id);
this.fetchUsers();
})
.catch((err) => {
this.updateStatus = { status: "failed" };
return result;
});
},
updateActiveUserPermissions(permission: PermissionObject) {
if (this.user == null) return;
let id = this.user.id;
this.updateStatus = "loading";
http
.patch(`/admin/user/${id}/permissions`, {
updateActiveUserPermissions(user: number, permission: PermissionObject): Promise<AxiosResponse<any, any>> {
return http
.patch(`/admin/user/${user}/permissions`, {
permissions: permission,
})
.then((result) => {
this.updateStatus = { status: "success" };
this.fetchUserById(id);
this.fetchUsers();
})
.catch((err) => {
this.updateStatus = { status: "failed" };
return result;
});
},
updateActiveUserRoles(roles: Array<number>) {
if (this.user == null) return;
let id = this.user.id;
this.updateStatus = "loading";
http
.patch(`/admin/user/${id}/roles`, {
updateActiveUserRoles(user: number, roles: Array<number>): Promise<AxiosResponse<any, any>> {
return http
.patch(`/admin/user/${user}/roles`, {
roleIds: roles,
})
.then((result) => {
this.updateStatus = { status: "success" };
this.fetchUserById(id);
this.fetchUsers();
})
.catch((err) => {
this.updateStatus = { status: "failed" };
return result;
});
},
deleteUser(user: number) {
this.deleteStatus = "loading";
http
.delete(`/admin/user/${user}`)
.then((res) => {
this.deleteStatus = { status: "success" };
this.fetchUsers();
})
.catch((err) => {
this.deleteStatus = { status: "failed", reason: err.data };
});
deleteUser(user: number): Promise<AxiosResponse<any, any>> {
return http.delete(`/admin/user/${user}`).then((result) => {
this.fetchUsers();
return result;
});
},
},
});