8000 duplicate lead check · vishal-coder/CRM_backend@1a1ce74 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1a1ce74

Browse files
committed
duplicate lead check
1 parent 7079940 commit 1a1ce74

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

controllers/LeadController.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { insertContact } from "../models/ContactModel.js";
22
import {
33
deleteLeadById,
44
fetchLeads,
5+
getLeadByEmail,
56
getLeadById,
67
getManagerLeads,
78
insertLead,
@@ -23,6 +24,14 @@ export const createLead = async (req, res) => {
2324
createdOn: new Date(),
2425
};
2526
console.log("inside createLead--", data);
27+
const dBLeadByEmail = await getLeadByEmail({ email: email });
28+
console.log("dBLeadByEmail response is---", dBLeadByEmail);
29+
30+
if (dBLeadByEmail) {
31+
return res
32+
.status(401)
33+
.send({ message: "Lead By same Email Already Exists" });
34+
}
2635
const response = await insertLead(data);
2736
console.log("createLead response is---", response);
2837
res.status(200).send({

models/LeadModel.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,7 @@ export function getLeadById(id) {
7676
.collection("leads")
7777
.findOne({ _id: ObjectId(id) });
7878
}
79+
80+
export async function getLeadByEmail(data) {
81+
return client.db("CRM").collection("leads").findOne(data);
82+
}

0 commit comments

Comments
 (0)
0