Refactor: Fully migrated to direct PostgreSQL, implemented Public API v1, fixed Vercel deployment conflicts, and updated documentation
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { supabaseAdmin } from '@/lib/supabase-admin';
|
||||
import { db } from '@/lib/db';
|
||||
import { format } from 'date-fns';
|
||||
import { tr } from 'date-fns/locale';
|
||||
import {
|
||||
@@ -16,27 +16,20 @@ import { redirect } from 'next/navigation';
|
||||
async function getMerchantTransactions(identifier: string) {
|
||||
const isUUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(identifier);
|
||||
|
||||
const query = supabaseAdmin
|
||||
.from('merchants')
|
||||
.select('id')
|
||||
const mQueryText = isUUID
|
||||
? 'SELECT id FROM merchants WHERE id = $1 LIMIT 1'
|
||||
: 'SELECT id FROM merchants WHERE short_id = $1 LIMIT 1';
|
||||
|
||||
if (isUUID) {
|
||||
query.eq('id', identifier);
|
||||
} else {
|
||||
query.eq('short_id', identifier);
|
||||
}
|
||||
|
||||
const { data: merchant } = await query.single();
|
||||
const mResult = await db.query(mQueryText, [identifier]);
|
||||
const merchant = mResult.rows[0];
|
||||
if (!merchant) return null;
|
||||
|
||||
const { data, error } = await supabaseAdmin
|
||||
.from('transactions')
|
||||
.select('*')
|
||||
.eq('merchant_id', merchant.id)
|
||||
.order('created_at', { ascending: false });
|
||||
const tResult = await db.query(
|
||||
'SELECT * FROM transactions WHERE merchant_id = $1 ORDER BY created_at DESC',
|
||||
[merchant.id]
|
||||
);
|
||||
|
||||
if (error) return null;
|
||||
return data;
|
||||
return tResult.rows;
|
||||
}
|
||||
|
||||
export default async function MerchantTransactionsPage(props: {
|
||||
@@ -53,7 +46,8 @@ export default async function MerchantTransactionsPage(props: {
|
||||
const isUUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(identifier);
|
||||
let resolvedId = identifier;
|
||||
if (!isUUID) {
|
||||
const { data: merchant } = await supabaseAdmin.from('merchants').select('id').eq('short_id', identifier).single();
|
||||
const result = await db.query('SELECT id FROM merchants WHERE short_id = $1 LIMIT 1', [identifier]);
|
||||
const merchant = result.rows[0];
|
||||
if (merchant) resolvedId = merchant.id;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user