-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d20cbf
commit f386052
Showing
3 changed files
with
60 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
const visitsBadgeSchema = require('./schema.js'); | ||
|
||
module.exports.visitsBadge = async function (uniqueID) { | ||
const badge = await visitsBadgeSchema.findOneAndUpdate( | ||
{ uniqueID: uniqueID }, | ||
{ | ||
$setOnInsert: { | ||
uniqueID: uniqueID, | ||
}, | ||
$inc: { visitsCount: 1 }, | ||
}, | ||
{ new: true, upsert: true } | ||
).select({ visitsCount: 1 }); | ||
return badge.visitsCount; | ||
} | ||
const visitsBadgeSchema = require("./schema.js"); | ||
|
||
module.exports.visitsBadge = async function (uniqueID, setIDCount, passKey) { | ||
try { | ||
const filter = { uniqueID: uniqueID }; | ||
let existingDocument = await visitsBadgeSchema.findOne({ uniqueID: uniqueID }); | ||
const update = { | ||
$setOnInsert: { uniqueID: uniqueID, passKey: passKey }, | ||
$set: setIDCount !== "0" && passKey === existingDocument?.passKey ? { visitsCount: parseInt(setIDCount) } : {}, | ||
$inc: setIDCount === "0" || passKey !== existingDocument?.passKey ? { visitsCount: 1 } : {}, | ||
}; | ||
|
||
const options = { new: true, upsert: true }; | ||
|
||
const updatedDocument = await visitsBadgeSchema.findOneAndUpdate(filter, update, options).select({ visitsCount: 1 }); | ||
|
||
return updatedDocument.visitsCount; | ||
} catch (error) { | ||
console.error("Error in visitsBadge:", error); | ||
throw error; | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters