feat: centralized constants and enums for project-wide use
This commit is contained in:
@@ -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})`,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user