refactor(db): migrate staff and app actions from Prisma facade to Drizzle
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
9854719cfd
commit
ed9c23c702
85 files changed
+2612
-1832
No files matched your search
@@ -1,3 +1,5 @@
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import { db, User, UsersCurrency } from "@/lib/db";
|
||||
import type { RconClient } from "@/lib/services/rcon";
|
||||
|
||||
export type CurrencyName = "credits" | "duckets" | "diamonds" | "points";
|
||||
@@ -25,6 +27,32 @@ export interface CurrencyDb {
|
||||
};
|
||||
}
|
||||
|
||||
/** Drizzle-backed CurrencyDb used by shop / voucher / referral (and callers). */
|
||||
export const currencyDb: CurrencyDb = {
|
||||
user: {
|
||||
async update({ where, data }) {
|
||||
await db
|
||||
.update(User)
|
||||
.set({
|
||||
credits: sql`${User.credits} + ${data.credits.increment}`,
|
||||
})
|
||||
.where(eq(User.id, where.id));
|
||||
},
|
||||
},
|
||||
usersCurrency: {
|
||||
async upsert({ update, create }) {
|
||||
await db
|
||||
.insert(UsersCurrency)
|
||||
.values(create)
|
||||
.onDuplicateKeyUpdate({
|
||||
set: {
|
||||
amount: sql`${UsersCurrency.amount} + ${update.amount.increment}`,
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export interface SendCurrencyDeps {
|
||||
rcon: Pick<
|
||||
RconClient,
|
||||
|
||||
Reference in new issue
Block a user