refactor(core): Move some request DTOs to @n8n/api-types (no-changelog) (#10880)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-09-20 21:14:06 +02:00
committed by GitHub
parent 583d3a7acb
commit 769ddfdd1d
35 changed files with 648 additions and 316 deletions

View File

@@ -77,7 +77,7 @@
"vue-markdown-render": "catalog:frontend",
"vue-router": "catalog:frontend",
"vue3-touch-events": "^4.1.3",
"xss": "^1.0.14"
"xss": "catalog:"
},
"devDependencies": {
"@faker-js/faker": "^8.0.2",

View File

@@ -1,3 +1,8 @@
import type {
PasswordUpdateRequestDto,
SettingsUpdateRequestDto,
UserUpdateRequestDto,
} from '@n8n/api-types';
import type {
CurrentUserResponse,
IPersonalizationLatestVersion,
@@ -8,11 +13,6 @@ import type {
import type { IDataObject, IUserSettings } from 'n8n-workflow';
import { makeRestApiRequest } from '@/utils/apiUtils';
export interface IUpdateUserSettingsReqPayload {
allowSSOManualLogin?: boolean;
userActivated?: boolean;
}
export async function loginCurrentUser(
context: IRestApiContext,
): Promise<CurrentUserResponse | null> {
@@ -89,23 +89,16 @@ export async function changePassword(
await makeRestApiRequest(context, 'POST', '/change-password', params);
}
export type UpdateCurrentUserParams = {
firstName?: string;
lastName?: string;
email: string;
mfaCode?: string;
};
export async function updateCurrentUser(
context: IRestApiContext,
params: UpdateCurrentUserParams,
params: UserUpdateRequestDto,
): Promise<IUserResponse> {
return await makeRestApiRequest(context, 'PATCH', '/me', params);
}
export async function updateCurrentUserSettings(
context: IRestApiContext,
settings: IUpdateUserSettingsReqPayload,
settings: SettingsUpdateRequestDto,
): Promise<IUserSettings> {
return await makeRestApiRequest(context, 'PATCH', '/me/settings', settings);
}
@@ -113,20 +106,14 @@ export async function updateCurrentUserSettings(
export async function updateOtherUserSettings(
context: IRestApiContext,
userId: string,
settings: IUpdateUserSettingsReqPayload,
settings: SettingsUpdateRequestDto,
): Promise<IUserSettings> {
return await makeRestApiRequest(context, 'PATCH', `/users/${userId}/settings`, settings);
}
export type UpdateUserPasswordParams = {
newPassword: string;
currentPassword: string;
mfaCode?: string;
};
export async function updateCurrentUserPassword(
context: IRestApiContext,
params: UpdateUserPasswordParams,
params: PasswordUpdateRequestDto,
): Promise<void> {
return await makeRestApiRequest(context, 'PATCH', '/me/password', params);
}

View File

@@ -1,4 +1,9 @@
import type { IUpdateUserSettingsReqPayload, UpdateGlobalRolePayload } from '@/api/users';
import type {
PasswordUpdateRequestDto,
SettingsUpdateRequestDto,
UserUpdateRequestDto,
} from '@n8n/api-types';
import type { UpdateGlobalRolePayload } from '@/api/users';
import * as usersApi from '@/api/users';
import { BROWSER_ID_STORAGE_KEY, PERSONALIZATION_MODAL_KEY, STORES, ROLE } from '@/constants';
import type {
@@ -226,12 +231,12 @@ export const useUsersStore = defineStore(STORES.USERS, () => {
await usersApi.changePassword(rootStore.restApiContext, params);
};
const updateUser = async (params: usersApi.UpdateCurrentUserParams) => {
const updateUser = async (params: UserUpdateRequestDto) => {
const user = await usersApi.updateCurrentUser(rootStore.restApiContext, params);
addUsers([user]);
};
const updateUserSettings = async (settings: IUpdateUserSettingsReqPayload) => {
const updateUserSettings = async (settings: SettingsUpdateRequestDto) => {
const updatedSettings = await usersApi.updateCurrentUserSettings(
rootStore.restApiContext,
settings,
@@ -242,10 +247,7 @@ export const useUsersStore = defineStore(STORES.USERS, () => {
}
};
const updateOtherUserSettings = async (
userId: string,
settings: IUpdateUserSettingsReqPayload,
) => {
const updateOtherUserSettings = async (userId: string, settings: SettingsUpdateRequestDto) => {
const updatedSettings = await usersApi.updateOtherUserSettings(
rootStore.restApiContext,
userId,
@@ -255,7 +257,7 @@ export const useUsersStore = defineStore(STORES.USERS, () => {
addUsers([usersById.value[userId]]);
};
const updateCurrentUserPassword = async (params: usersApi.UpdateUserPasswordParams) => {
const updateCurrentUserPassword = async (params: PasswordUpdateRequestDto) => {
await usersApi.updateCurrentUserPassword(rootStore.restApiContext, params);
};