Skip to content

Commit

Permalink
Change: fix mongo atomic operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Voktor Stolenets committed Jan 21, 2025
1 parent 0b09a5e commit 4280510
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ const startServer = async () => {
};
address = address.toLowerCase();
const secret = mapSecret.get(address);

if (!signature || !address || !secret) {
return reply.status(400).send({
error: "Missing address or signature in headers",
Expand Down Expand Up @@ -132,9 +131,11 @@ async function checkTokenExist(
await request.server.mongo.db?.collection("token").updateOne(
{ tokenAddress },
{
tokenAddress,
like: 0,
timestamp: new Date(),
$set: {
tokenAddress,
like: 0,
timestamp: new Date(),
},
},
{ upsert: true },
);
Expand Down Expand Up @@ -202,10 +203,12 @@ async function addOrUpdateUser(request: FastifyRequest, reply: FastifyReply) {
await request.server.mongo.db?.collection("user").updateOne(
{ address },
{
address,
userName,
image,
timestamp: new Date(),
$set: {
address,
userName,
image,
timestamp: new Date(),
},
},
{ upsert: true },
);
Expand Down Expand Up @@ -244,9 +247,11 @@ async function addOrDeleteLike(request: FastifyRequest, reply: FastifyReply) {
.updateOne(
{ address, tokenAddress },
{
address,
tokenAddress,
timestamp: new Date(),
$set: {
address,
tokenAddress,
timestamp: new Date(),
},
},
{ upsert: true },
);
Expand Down Expand Up @@ -458,8 +463,10 @@ async function addfollow(request: FastifyRequest, reply: FastifyReply) {
await request.server.mongo.db?.collection("followers").updateOne(
{ address, userAddress },
{
address,
userAddress,
$set: {
address,
userAddress,
},
},
{ upsert: true },
);
Expand Down

0 comments on commit 4280510

Please sign in to comment.