feat: centralized constants and enums for project-wide use

This commit is contained in:
syntaxbullet
2026-01-06 18:15:52 +01:00
parent c807fd4fd0
commit 34347f0c63
17 changed files with 144 additions and 63 deletions

View File

@@ -4,6 +4,7 @@ import { config } from "@/lib/config";
import { withTransaction } from "@/lib/db";
import type { Transaction } from "@/lib/types";
import { UserError } from "@/lib/errors";
import { TimerType, TransactionType } from "@/lib/constants";
export const economyService = {
transfer: async (fromUserId: string, toUserId: string, amount: bigint, tx?: Transaction) => {
@@ -48,7 +49,7 @@ export const economyService = {
await txFn.insert(transactions).values({
userId: BigInt(fromUserId),
amount: -amount,
type: 'TRANSFER_OUT',
type: TransactionType.TRANSFER_OUT,
description: `Transfer to ${toUserId}`,
});
@@ -56,7 +57,7 @@ export const economyService = {
await txFn.insert(transactions).values({
userId: BigInt(toUserId),
amount: amount,
type: 'TRANSFER_IN',
type: TransactionType.TRANSFER_IN,
description: `Transfer from ${fromUserId}`,
});
@@ -74,7 +75,7 @@ export const economyService = {
const cooldown = await txFn.query.userTimers.findFirst({
where: and(
eq(userTimers.userId, BigInt(userId)),
eq(userTimers.type, 'COOLDOWN'),
eq(userTimers.type, TimerType.COOLDOWN),
eq(userTimers.key, 'daily')
),
});
@@ -127,7 +128,7 @@ export const economyService = {
await txFn.insert(userTimers)
.values({
userId: BigInt(userId),
type: 'COOLDOWN',
type: TimerType.COOLDOWN,
key: 'daily',
expiresAt: nextReadyAt,
})
@@ -140,7 +141,7 @@ export const economyService = {
await txFn.insert(transactions).values({
userId: BigInt(userId),
amount: totalReward,
type: 'DAILY_REWARD',
type: TransactionType.DAILY_REWARD,
description: `Daily reward (Streak: ${streak})`,
});