forked from syntaxbullet/aurorabot
feat: Introduce TimerKey enum and refactor timer key usage across services with new tests.
This commit is contained in:
@@ -4,7 +4,7 @@ import { config } from "@shared/lib/config";
|
||||
import { withTransaction } from "@/lib/db";
|
||||
import type { Transaction } from "@shared/lib/types";
|
||||
import { UserError } from "@shared/lib/errors";
|
||||
import { TimerType, TransactionType } from "@shared/lib/constants";
|
||||
import { TimerKey, TimerType, TransactionType } from "@shared/lib/constants";
|
||||
|
||||
export const economyService = {
|
||||
transfer: async (fromUserId: string, toUserId: string, amount: bigint, tx?: Transaction) => {
|
||||
@@ -82,7 +82,7 @@ export const economyService = {
|
||||
where: and(
|
||||
eq(userTimers.userId, BigInt(userId)),
|
||||
eq(userTimers.type, TimerType.COOLDOWN),
|
||||
eq(userTimers.key, 'daily')
|
||||
eq(userTimers.key, TimerKey.DAILY)
|
||||
),
|
||||
});
|
||||
|
||||
@@ -141,7 +141,7 @@ export const economyService = {
|
||||
.values({
|
||||
userId: BigInt(userId),
|
||||
type: TimerType.COOLDOWN,
|
||||
key: 'daily',
|
||||
key: TimerKey.DAILY,
|
||||
expiresAt: nextReadyAt,
|
||||
})
|
||||
.onConflictDoUpdate({
|
||||
|
||||
@@ -3,7 +3,7 @@ import { eq, sql, and } from "drizzle-orm";
|
||||
import { withTransaction } from "@/lib/db";
|
||||
import { config } from "@shared/lib/config";
|
||||
import type { Transaction } from "@shared/lib/types";
|
||||
import { TimerType } from "@shared/lib/constants";
|
||||
import { TimerKey, TimerType } from "@shared/lib/constants";
|
||||
|
||||
export const levelingService = {
|
||||
// Calculate total XP required to REACH a specific level (Cumulative)
|
||||
@@ -84,7 +84,7 @@ export const levelingService = {
|
||||
where: and(
|
||||
eq(userTimers.userId, BigInt(id)),
|
||||
eq(userTimers.type, TimerType.COOLDOWN),
|
||||
eq(userTimers.key, 'chat_xp')
|
||||
eq(userTimers.key, TimerKey.CHAT_XP)
|
||||
),
|
||||
});
|
||||
|
||||
@@ -120,7 +120,7 @@ export const levelingService = {
|
||||
.values({
|
||||
userId: BigInt(id),
|
||||
type: TimerType.COOLDOWN,
|
||||
key: 'chat_xp',
|
||||
key: TimerKey.CHAT_XP,
|
||||
expiresAt: nextReadyAt,
|
||||
})
|
||||
.onConflictDoUpdate({
|
||||
|
||||
Reference in New Issue
Block a user