Is it possible to use duplicate code as a restriction (use for custom log in)?

Hi I’m new here and also new in wix.

I just want to ask help regarding with my code.
I create a custom log in that use the code that I provide. Here’s the code that I create and I don’t know how to fix it or if it’s correct.

By the way this code is base on duplicates.

import wixData from ‘wix-data’;

export function seacrhforduplicate (collection, field, item) {
return wixData.query(‘SellersDatabase’).eq(field, item[field]).find().then((results) => {
return results.items.length
}). catch ((err) => {
let errMsg = err
console.log(err)
})
}
export function SellersDatabase_beforeInsert(item, context) {
return seacrhforduplicate(context.collectionName, “sellersCode”, item).then((res) => {
if (res < 0) {
return Promise.reject(‘This Item not exist!’)
}
else (res > 0) {
goto wixLocation.to(‘/admin’);
}
return item
})
}

Thank you in advance.