Reformat point ledger repository
- 동작 변경 없는 들여쓰기·줄바꿈 정리
This commit is contained in:
parent
1c60607683
commit
12c43e6e9c
@ -3,10 +3,22 @@ import { firestore } from "../firebase";
|
|||||||
import type {PointLedgerEntry} from "../types/points";
|
import type {PointLedgerEntry} from "../types/points";
|
||||||
|
|
||||||
function col(uid: string) { return firestore.collection(`users/${uid}/pointLedger`); }
|
function col(uid: string) { return firestore.collection(`users/${uid}/pointLedger`); }
|
||||||
export function createLedgerEntryTx(tx: Transaction, uid: string, entry: PointLedgerEntry) { const ref = col(uid).doc(entry.txId); tx.create(ref, entry); return ref; }
|
|
||||||
|
export function createLedgerEntryTx(tx: Transaction, uid: string, entry: PointLedgerEntry) {
|
||||||
|
const ref = col(uid).doc(entry.txId);
|
||||||
|
tx.create(ref, entry);
|
||||||
|
return ref;
|
||||||
|
}
|
||||||
|
|
||||||
export async function listLedger(uid: string, limit = 20, cursor?: string) {
|
export async function listLedger(uid: string, limit = 20, cursor?: string) {
|
||||||
let q = col(uid).orderBy("createdAt", "desc").limit(Math.min(Math.max(limit, 1), 100));
|
let q = col(uid).orderBy("createdAt", "desc").limit(Math.min(Math.max(limit, 1), 100));
|
||||||
if (cursor) { const snap = await col(uid).doc(cursor).get(); if (snap.exists) q = q.startAfter(snap) as typeof q; }
|
if (cursor) {
|
||||||
const snap = await q.get();
|
const snap = await col(uid).doc(cursor).get();
|
||||||
return { items: snap.docs.map((d) => ({ id: d.id, ...(d.data() as PointLedgerEntry) })), cursor: snap.docs.length ? snap.docs[snap.docs.length - 1].id : null };
|
if (snap.exists) q = q.startAfter(snap) as typeof q;
|
||||||
|
}
|
||||||
|
const snap = await q.get();
|
||||||
|
return {
|
||||||
|
items: snap.docs.map((d) => ({id: d.id, ...(d.data() as PointLedgerEntry)})),
|
||||||
|
cursor: snap.docs.length ? snap.docs[snap.docs.length - 1].id : null
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user