25 lines
798 B
JavaScript
25 lines
798 B
JavaScript
|
|
// Debug: try to fetch invoices exactly like /invoices page does
|
||
|
|
import { default as PocketBase } from 'pocketbase';
|
||
|
|
import fs from 'fs';
|
||
|
|
const envFile = fs.readFileSync('.env.local', 'utf8');
|
||
|
|
const token = envFile.match(/PB_TOKEN=(.+)/)[1].trim();
|
||
|
|
const url = envFile.match(/PB_URL=(.+)/)[1].trim();
|
||
|
|
process.env.PB_TOKEN = token;
|
||
|
|
process.env.NEXT_PUBLIC_PB_URL = url;
|
||
|
|
|
||
|
|
const pb = new PocketBase(url);
|
||
|
|
pb.authStore.save(token);
|
||
|
|
|
||
|
|
(async () => {
|
||
|
|
try {
|
||
|
|
const r = await pb.collection('JEI_invoices').getList(1, 200, {
|
||
|
|
sort: '-invoice_date',
|
||
|
|
});
|
||
|
|
console.log('OK items=' + r.items.length + ' total=' + r.totalItems);
|
||
|
|
} catch (e) {
|
||
|
|
console.log('ERR ' + e.status + ': ' + e.message);
|
||
|
|
console.log('data: ' + JSON.stringify(e.data));
|
||
|
|
console.log('url: ' + e.url);
|
||
|
|
}
|
||
|
|
})();
|