added update account functionality

This commit is contained in:
Daniel
2023-05-20 22:55:00 +03:30
parent e3862188de
commit 0ce97f0b64
13 changed files with 345 additions and 61 deletions
+10 -12
View File
@@ -12,21 +12,19 @@ export default async function (lookupEmail: string, isSelf: boolean) {
},
});
if (!user) return { response: "User not found." || null, status: 404 };
const { password, ...unsensitiveInfo } = user;
const data = isSelf
? {
// If user is requesting its data
id: user?.id,
name: user?.name,
email: user?.email,
}
? // If user is requesting its own data
unsensitiveInfo
: {
// If user is requesting someone elses data
id: user?.id,
name: user?.name,
email: user?.email,
id: unsensitiveInfo.id,
name: unsensitiveInfo.name,
email: unsensitiveInfo.email,
};
const statusCode = user?.id ? 200 : 404;
return { response: data || null, status: statusCode };
return { response: data || null, status: 200 };
}
+31
View File
@@ -0,0 +1,31 @@
// Copyright (C) 2022-present Daniel31x13 <daniel31x13@gmail.com>
// This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
import { prisma } from "@/lib/api/db";
import { AccountSettings } from "@/types/global";
export default async function (user: AccountSettings, userId: number) {
console.log(typeof user);
const updatedUser = await prisma.user.update({
where: {
id: userId,
},
data: {
name: user.name,
email: user.email,
collectionProtection: user.collectionProtection,
whitelistedUsers: user.whitelistedUsers,
},
select: {
name: true,
email: true,
collectionProtection: true,
whitelistedUsers: true,
},
});
return { response: updatedUser, status: 200 };
}