You've already forked immich
mirror of
https://github.com/immich-app/immich.git
synced 2025-06-26 05:01:05 +02:00
refactor(server): user endpoints (#9730)
* refactor(server): user endpoints * fix repos * fix unit tests --------- Co-authored-by: Daniel Dietzler <mail@ddietzler.dev> Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
cli/src
e2e/src
mobile
open-api
server/src
commands
controllers
cores
dtos
queries
repositories
services
auth.service.spec.tsauth.service.tscli.service.tsindex.tspartner.service.spec.tspartner.service.tsuser-admin.service.spec.tsuser-admin.service.tsuser.service.spec.tsuser.service.ts
validation.tsweb/src
lib
components
admin-page
album-page
forms
change-password-form.sveltecreate-user-form.svelteedit-user-form.sveltelibrary-user-picker-form.svelte
shared-components
navigation-bar
user-settings-page
stores
utils.tsutils
routes
(user)
partners
[userId]
[[photos=photos]]
[[assetId=id]]
admin
auth
change-password
test-data
factories
@ -14,7 +14,7 @@ const oazapfts = Oazapfts.runtime(defaults);
|
||||
export const servers = {
|
||||
server1: "/api"
|
||||
};
|
||||
export type UserDto = {
|
||||
export type UserResponseDto = {
|
||||
avatarColor: UserAvatarColor;
|
||||
email: string;
|
||||
id: string;
|
||||
@ -27,7 +27,7 @@ export type ActivityResponseDto = {
|
||||
createdAt: string;
|
||||
id: string;
|
||||
"type": Type;
|
||||
user: UserDto;
|
||||
user: UserResponseDto;
|
||||
};
|
||||
export type ActivityCreateDto = {
|
||||
albumId: string;
|
||||
@ -38,7 +38,7 @@ export type ActivityCreateDto = {
|
||||
export type ActivityStatisticsResponseDto = {
|
||||
comments: number;
|
||||
};
|
||||
export type UserResponseDto = {
|
||||
export type UserAdminResponseDto = {
|
||||
avatarColor: UserAvatarColor;
|
||||
createdAt: string;
|
||||
deletedAt: string | null;
|
||||
@ -56,6 +56,29 @@ export type UserResponseDto = {
|
||||
storageLabel: string | null;
|
||||
updatedAt: string;
|
||||
};
|
||||
export type UserAdminCreateDto = {
|
||||
email: string;
|
||||
memoriesEnabled?: boolean;
|
||||
name: string;
|
||||
notify?: boolean;
|
||||
password: string;
|
||||
quotaSizeInBytes?: number | null;
|
||||
shouldChangePassword?: boolean;
|
||||
storageLabel?: string | null;
|
||||
};
|
||||
export type UserAdminDeleteDto = {
|
||||
force?: boolean;
|
||||
};
|
||||
export type UserAdminUpdateDto = {
|
||||
avatarColor?: UserAvatarColor;
|
||||
email?: string;
|
||||
memoriesEnabled?: boolean;
|
||||
name?: string;
|
||||
password?: string;
|
||||
quotaSizeInBytes?: number | null;
|
||||
shouldChangePassword?: boolean;
|
||||
storageLabel?: string | null;
|
||||
};
|
||||
export type AlbumUserResponseDto = {
|
||||
role: AlbumUserRole;
|
||||
user: UserResponseDto;
|
||||
@ -517,22 +540,11 @@ export type OAuthCallbackDto = {
|
||||
};
|
||||
export type PartnerResponseDto = {
|
||||
avatarColor: UserAvatarColor;
|
||||
createdAt: string;
|
||||
deletedAt: string | null;
|
||||
email: string;
|
||||
id: string;
|
||||
inTimeline?: boolean;
|
||||
isAdmin: boolean;
|
||||
memoriesEnabled?: boolean;
|
||||
name: string;
|
||||
oauthId: string;
|
||||
profileImagePath: string;
|
||||
quotaSizeInBytes: number | null;
|
||||
quotaUsageInBytes: number | null;
|
||||
shouldChangePassword: boolean;
|
||||
status: UserStatus;
|
||||
storageLabel: string | null;
|
||||
updatedAt: string;
|
||||
};
|
||||
export type UpdatePartnerDto = {
|
||||
inTimeline: boolean;
|
||||
@ -1060,27 +1072,12 @@ export type TimeBucketResponseDto = {
|
||||
count: number;
|
||||
timeBucket: string;
|
||||
};
|
||||
export type CreateUserDto = {
|
||||
email: string;
|
||||
memoriesEnabled?: boolean;
|
||||
name: string;
|
||||
notify?: boolean;
|
||||
password: string;
|
||||
quotaSizeInBytes?: number | null;
|
||||
shouldChangePassword?: boolean;
|
||||
storageLabel?: string | null;
|
||||
};
|
||||
export type UpdateUserDto = {
|
||||
export type UserUpdateMeDto = {
|
||||
avatarColor?: UserAvatarColor;
|
||||
email?: string;
|
||||
id: string;
|
||||
isAdmin?: boolean;
|
||||
memoriesEnabled?: boolean;
|
||||
name?: string;
|
||||
password?: string;
|
||||
quotaSizeInBytes?: number | null;
|
||||
shouldChangePassword?: boolean;
|
||||
storageLabel?: string;
|
||||
};
|
||||
export type CreateProfileImageDto = {
|
||||
file: Blob;
|
||||
@ -1089,9 +1086,6 @@ export type CreateProfileImageResponseDto = {
|
||||
profileImagePath: string;
|
||||
userId: string;
|
||||
};
|
||||
export type DeleteUserDto = {
|
||||
force?: boolean;
|
||||
};
|
||||
export function getActivities({ albumId, assetId, level, $type, userId }: {
|
||||
albumId: string;
|
||||
assetId?: string;
|
||||
@ -1146,6 +1140,77 @@ export function deleteActivity({ id }: {
|
||||
method: "DELETE"
|
||||
}));
|
||||
}
|
||||
export function searchUsersAdmin({ withDeleted }: {
|
||||
withDeleted?: boolean;
|
||||
}, opts?: Oazapfts.RequestOpts) {
|
||||
return oazapfts.ok(oazapfts.fetchJson<{
|
||||
status: 200;
|
||||
data: UserAdminResponseDto[];
|
||||
}>(`/admin/users${QS.query(QS.explode({
|
||||
withDeleted
|
||||
}))}`, {
|
||||
...opts
|
||||
}));
|
||||
}
|
||||
export function createUserAdmin({ userAdminCreateDto }: {
|
||||
userAdminCreateDto: UserAdminCreateDto;
|
||||
}, opts?: Oazapfts.RequestOpts) {
|
||||
return oazapfts.ok(oazapfts.fetchJson<{
|
||||
status: 201;
|
||||
data: UserAdminResponseDto;
|
||||
}>("/admin/users", oazapfts.json({
|
||||
...opts,
|
||||
method: "POST",
|
||||
body: userAdminCreateDto
|
||||
})));
|
||||
}
|
||||
export function deleteUserAdmin({ id, userAdminDeleteDto }: {
|
||||
id: string;
|
||||
userAdminDeleteDto: UserAdminDeleteDto;
|
||||
}, opts?: Oazapfts.RequestOpts) {
|
||||
return oazapfts.ok(oazapfts.fetchJson<{
|
||||
status: 200;
|
||||
data: UserAdminResponseDto;
|
||||
}>(`/admin/users/${encodeURIComponent(id)}`, oazapfts.json({
|
||||
...opts,
|
||||
method: "DELETE",
|
||||
body: userAdminDeleteDto
|
||||
})));
|
||||
}
|
||||
export function getUserAdmin({ id }: {
|
||||
id: string;
|
||||
}, opts?: Oazapfts.RequestOpts) {
|
||||
return oazapfts.ok(oazapfts.fetchJson<{
|
||||
status: 200;
|
||||
data: UserAdminResponseDto;
|
||||
}>(`/admin/users/${encodeURIComponent(id)}`, {
|
||||
...opts
|
||||
}));
|
||||
}
|
||||
export function updateUserAdmin({ id, userAdminUpdateDto }: {
|
||||
id: string;
|
||||
userAdminUpdateDto: UserAdminUpdateDto;
|
||||
}, opts?: Oazapfts.RequestOpts) {
|
||||
return oazapfts.ok(oazapfts.fetchJson<{
|
||||
status: 200;
|
||||
data: UserAdminResponseDto;
|
||||
}>(`/admin/users/${encodeURIComponent(id)}`, oazapfts.json({
|
||||
...opts,
|
||||
method: "PUT",
|
||||
body: userAdminUpdateDto
|
||||
})));
|
||||
}
|
||||
export function restoreUserAdmin({ id }: {
|
||||
id: string;
|
||||
}, opts?: Oazapfts.RequestOpts) {
|
||||
return oazapfts.ok(oazapfts.fetchJson<{
|
||||
status: 201;
|
||||
data: UserAdminResponseDto;
|
||||
}>(`/admin/users/${encodeURIComponent(id)}/restore`, {
|
||||
...opts,
|
||||
method: "POST"
|
||||
}));
|
||||
}
|
||||
export function getAllAlbums({ assetId, shared }: {
|
||||
assetId?: string;
|
||||
shared?: boolean;
|
||||
@ -1589,7 +1654,7 @@ export function signUpAdmin({ signUpDto }: {
|
||||
}, opts?: Oazapfts.RequestOpts) {
|
||||
return oazapfts.ok(oazapfts.fetchJson<{
|
||||
status: 201;
|
||||
data: UserResponseDto;
|
||||
data: UserAdminResponseDto;
|
||||
}>("/auth/admin-sign-up", oazapfts.json({
|
||||
...opts,
|
||||
method: "POST",
|
||||
@ -1601,7 +1666,7 @@ export function changePassword({ changePasswordDto }: {
|
||||
}, opts?: Oazapfts.RequestOpts) {
|
||||
return oazapfts.ok(oazapfts.fetchJson<{
|
||||
status: 200;
|
||||
data: UserResponseDto;
|
||||
data: UserAdminResponseDto;
|
||||
}>("/auth/change-password", oazapfts.json({
|
||||
...opts,
|
||||
method: "POST",
|
||||
@ -1934,7 +1999,7 @@ export function linkOAuthAccount({ oAuthCallbackDto }: {
|
||||
}, opts?: Oazapfts.RequestOpts) {
|
||||
return oazapfts.ok(oazapfts.fetchJson<{
|
||||
status: 201;
|
||||
data: UserResponseDto;
|
||||
data: UserAdminResponseDto;
|
||||
}>("/oauth/link", oazapfts.json({
|
||||
...opts,
|
||||
method: "POST",
|
||||
@ -1949,7 +2014,7 @@ export function redirectOAuthToMobile(opts?: Oazapfts.RequestOpts) {
|
||||
export function unlinkOAuthAccount(opts?: Oazapfts.RequestOpts) {
|
||||
return oazapfts.ok(oazapfts.fetchJson<{
|
||||
status: 201;
|
||||
data: UserResponseDto;
|
||||
data: UserAdminResponseDto;
|
||||
}>("/oauth/unlink", {
|
||||
...opts,
|
||||
method: "POST"
|
||||
@ -2687,50 +2752,34 @@ export function restoreAssets({ bulkIdsDto }: {
|
||||
body: bulkIdsDto
|
||||
})));
|
||||
}
|
||||
export function getAllUsers({ isAll }: {
|
||||
isAll: boolean;
|
||||
}, opts?: Oazapfts.RequestOpts) {
|
||||
export function searchUsers(opts?: Oazapfts.RequestOpts) {
|
||||
return oazapfts.ok(oazapfts.fetchJson<{
|
||||
status: 200;
|
||||
data: UserResponseDto[];
|
||||
}>(`/users${QS.query(QS.explode({
|
||||
isAll
|
||||
}))}`, {
|
||||
}>("/users", {
|
||||
...opts
|
||||
}));
|
||||
}
|
||||
export function createUser({ createUserDto }: {
|
||||
createUserDto: CreateUserDto;
|
||||
}, opts?: Oazapfts.RequestOpts) {
|
||||
return oazapfts.ok(oazapfts.fetchJson<{
|
||||
status: 201;
|
||||
data: UserResponseDto;
|
||||
}>("/users", oazapfts.json({
|
||||
...opts,
|
||||
method: "POST",
|
||||
body: createUserDto
|
||||
})));
|
||||
}
|
||||
export function updateUser({ updateUserDto }: {
|
||||
updateUserDto: UpdateUserDto;
|
||||
}, opts?: Oazapfts.RequestOpts) {
|
||||
export function getMyUser(opts?: Oazapfts.RequestOpts) {
|
||||
return oazapfts.ok(oazapfts.fetchJson<{
|
||||
status: 200;
|
||||
data: UserResponseDto;
|
||||
}>("/users", oazapfts.json({
|
||||
...opts,
|
||||
method: "PUT",
|
||||
body: updateUserDto
|
||||
})));
|
||||
}
|
||||
export function getMyUserInfo(opts?: Oazapfts.RequestOpts) {
|
||||
return oazapfts.ok(oazapfts.fetchJson<{
|
||||
status: 200;
|
||||
data: UserResponseDto;
|
||||
data: UserAdminResponseDto;
|
||||
}>("/users/me", {
|
||||
...opts
|
||||
}));
|
||||
}
|
||||
export function updateMyUser({ userUpdateMeDto }: {
|
||||
userUpdateMeDto: UserUpdateMeDto;
|
||||
}, opts?: Oazapfts.RequestOpts) {
|
||||
return oazapfts.ok(oazapfts.fetchJson<{
|
||||
status: 200;
|
||||
data: UserAdminResponseDto;
|
||||
}>("/users/me", oazapfts.json({
|
||||
...opts,
|
||||
method: "PUT",
|
||||
body: userUpdateMeDto
|
||||
})));
|
||||
}
|
||||
export function deleteProfileImage(opts?: Oazapfts.RequestOpts) {
|
||||
return oazapfts.ok(oazapfts.fetchText("/users/profile-image", {
|
||||
...opts,
|
||||
@ -2749,20 +2798,7 @@ export function createProfileImage({ createProfileImageDto }: {
|
||||
body: createProfileImageDto
|
||||
})));
|
||||
}
|
||||
export function deleteUser({ id, deleteUserDto }: {
|
||||
id: string;
|
||||
deleteUserDto: DeleteUserDto;
|
||||
}, opts?: Oazapfts.RequestOpts) {
|
||||
return oazapfts.ok(oazapfts.fetchJson<{
|
||||
status: 200;
|
||||
data: UserResponseDto;
|
||||
}>(`/users/${encodeURIComponent(id)}`, oazapfts.json({
|
||||
...opts,
|
||||
method: "DELETE",
|
||||
body: deleteUserDto
|
||||
})));
|
||||
}
|
||||
export function getUserById({ id }: {
|
||||
export function getUser({ id }: {
|
||||
id: string;
|
||||
}, opts?: Oazapfts.RequestOpts) {
|
||||
return oazapfts.ok(oazapfts.fetchJson<{
|
||||
@ -2782,17 +2818,6 @@ export function getProfileImage({ id }: {
|
||||
...opts
|
||||
}));
|
||||
}
|
||||
export function restoreUser({ id }: {
|
||||
id: string;
|
||||
}, opts?: Oazapfts.RequestOpts) {
|
||||
return oazapfts.ok(oazapfts.fetchJson<{
|
||||
status: 201;
|
||||
data: UserResponseDto;
|
||||
}>(`/users/${encodeURIComponent(id)}/restore`, {
|
||||
...opts,
|
||||
method: "POST"
|
||||
}));
|
||||
}
|
||||
export enum ReactionLevel {
|
||||
Album = "album",
|
||||
Asset = "asset"
|
||||
@ -2817,15 +2842,15 @@ export enum UserAvatarColor {
|
||||
Gray = "gray",
|
||||
Amber = "amber"
|
||||
}
|
||||
export enum AlbumUserRole {
|
||||
Editor = "editor",
|
||||
Viewer = "viewer"
|
||||
}
|
||||
export enum UserStatus {
|
||||
Active = "active",
|
||||
Removing = "removing",
|
||||
Deleted = "deleted"
|
||||
}
|
||||
export enum AlbumUserRole {
|
||||
Editor = "editor",
|
||||
Viewer = "viewer"
|
||||
}
|
||||
export enum TagTypeEnum {
|
||||
Object = "OBJECT",
|
||||
Face = "FACE",
|
||||
|
Reference in New Issue
Block a user