fix: remove old keys before inserting new ones

This commit is contained in:
MTG2000
2022-08-23 15:11:19 +03:00
parent 0d8828860b
commit b1ea5ae806

View File

@@ -37,19 +37,19 @@ const loginHandler = async (req, res) => {
if (existingKeys.length >= 3)
return res.status(400).json({ status: 'ERROR', reason: "Can only link up to 3 wallets" })
if (!existingKeys.includes(key))
await prisma.userKey.create({
data: {
key,
user_id,
}
});
// Remove old linking for this key if existing
await prisma.userKey.deleteMany({
where: { key }
})
await prisma.userKey.create({
data: {
key,
user_id,
}
});
return res
.status(200)
.json({ status: "OK" })