add update function

This commit is contained in:
jane 2022-04-11 12:50:50 -04:00
parent 6e58f59274
commit 49904865eb
1 changed files with 29 additions and 1 deletions

View File

@ -33,11 +33,39 @@ export const getUserBorders = async (req) => {
return result;
};
export const setUserBorder = async (req, borderId) => {
const session = await getSession({ req });
if (!session) {
return undefined;
}
const accountData = await prisma.account.findFirst({
where: {
userId: session.user.id,
},
});
const updateData = await prisma.applicationUserData.upsert({
create: {
userId: session.user.id,
discordId: accountData.providerAccountId,
borderId,
},
data: {
borderId,
},
where: {
userId: session.user.id,
},
});
return updateData;
};
export const getByDiscordId = async (id) => {
const userData = await prisma.applicationUserData.findUnique({
where: {
discordId: id,
},
});
return userData ? `${userData.borderId}` : undefined;
return userData?.borderId ? `${userData.borderId}` : undefined;
};