17 lines
533 B
TypeScript
17 lines
533 B
TypeScript
import { eq } from "drizzle-orm";
|
|
import type { Database } from "../client.js";
|
|
import { usersCurrency } from "../schema/users-currency.js";
|
|
|
|
export function makeCurrencyRepo(db: Database) {
|
|
return {
|
|
// Returns a map of currency type -> amount for one user.
|
|
forUser: async (userId: number): Promise<Map<number, number>> => {
|
|
const rows = await db
|
|
.select()
|
|
.from(usersCurrency)
|
|
.where(eq(usersCurrency.userId, userId));
|
|
return new Map(rows.map((r) => [r.type, r.amount]));
|
|
},
|
|
};
|
|
}
|