Skip to content

Commit

Permalink
Fix user creation...
Browse files Browse the repository at this point in the history
  • Loading branch information
RubberDuckShobe committed Nov 13, 2023
1 parent ddf2083 commit 3991d2f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 5 additions & 1 deletion routes/as1/accounts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FastifyInstance } from "fastify";
import { Prisma, User } from "@prisma/client";
import { prisma } from "../../util/db";
import { prisma, redis } from "../../util/db";
import * as SteamUtils from "../../util/steam";
import xml2js from "xml2js";
import SteamID from "steamid";
Expand Down Expand Up @@ -76,6 +76,10 @@ export default async function routes(fastify: FastifyInstance) {
},
});

//If user isn't stored in Redis yet, we add them to the leaderboard with 0 skill points.
const redisPoints = await redis.zscore("leaderboard", user.id);
if (!redisPoints) await redis.zadd("leaderboard", 0, user.id);

fastify.log.info("Game auth request for user %d", user.id);
return xmlBuilder.buildObject({
RESULT: {
Expand Down
10 changes: 4 additions & 6 deletions util/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ export const prisma = prismaOrig.$extends({
},
},
user: {
async upsert({ args, query }) {
const user = await prisma.user.findUnique({ where: args.where });
if (user) return query(args);
await redis.zadd("leaderboard", 0, user.id);
async delete({ args, query }) {
await redis.zrem("leaderboard", args.where.id);
return query(args);
},
},
}
}
},
/*
result: {
Expand Down

0 comments on commit 3991d2f

Please sign in to comment.