Skip to content

Commit a712e99

Browse files
committed
devdemo improvements
1 parent 96abe39 commit a712e99

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

dev-demo/.env.local

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ KEYCLOAK_URL=http://localhost:8080
22

33
ADMINFORTH_SECRET=123
44
NODE_ENV=development
5-
DATABASE_URL=sqlite://.db.sqlite
6-
PRISMA_DATABASE_URL=file:.db.sqlite
5+
DATABASE_URL=sqlite://./.db.sqlite
6+
DATABASE_FILE_URL=file:.db.sqlite

dev-demo/index.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import betterSqlite3 from 'better-sqlite3';
22
import express from 'express';
33
import AdminForth, { AdminUser, Filters } from '../adminforth/index.js';
44

5-
import AuditLogPlugin from '../plugins/adminforth-audit-log/index.js';
65
import clicksResource from './resources/clicks.js';
76
import apartmentsResource from './resources/apartments.js';
87
import apartmentBuyersResource from './resources/apartment_buyers.js';
@@ -18,15 +17,24 @@ import providersResource from './resources/providers.js';
1817
import apiKeysResource from './resources/api_keys.js';
1918
import CompletionAdapterOpenAIChatGPT from '../adapters/adminforth-completion-adapter-open-ai-chat-gpt/index.js';
2019
import pkg from 'pg';
20+
import I18nPlugin from '../plugins/adminforth-i18n/index.js';
2121
const { Client } = pkg;
2222

23+
24+
declare global {
25+
namespace NodeJS {
26+
interface ProcessEnv {
27+
NODE_ENV: string;
28+
DATABASE_URL: string;
29+
OPENAI_API_KEY: string;
30+
PORT: string;
31+
}
32+
}
33+
}
34+
2335
// const ADMIN_BASE_URL = '/portal';
2436
const ADMIN_BASE_URL = '';
2537

26-
// create test1.db
27-
const dbPath = 'db.sqlite';
28-
const db = betterSqlite3(dbPath)
29-
3038
async function seedDatabase() {
3139

3240
const adapter = new CompletionAdapterOpenAIChatGPT({
@@ -182,7 +190,7 @@ export const admin = new AdminForth({
182190
dataSources: [
183191
{
184192
id: 'maindb',
185-
url: `sqlite://${dbPath}`
193+
url: process.env.DATABASE_URL,
186194
},
187195
{
188196
id: 'pg',
@@ -353,7 +361,7 @@ app.get(`${ADMIN_BASE_URL}/api/dashboard/`,
353361
admin.express.translatable(
354362
async (req: any, res: express.Response) => {
355363
const days = req.body.days || 7;
356-
const apartsByDays = await db.prepare(
364+
const apartsByDays = await admin.resource('aparts').dataConnector.client.prepare(
357365
`SELECT
358366
strftime('%Y-%m-%d', created_at) as day,
359367
COUNT(*) as count
@@ -367,7 +375,7 @@ app.get(`${ADMIN_BASE_URL}/api/dashboard/`,
367375
const totalAparts = apartsByDays.reduce((acc: number, { count }: { count:number }) => acc + count, 0);
368376

369377
// add listed, unlisted, listedPrice, unlistedPrice
370-
const listedVsUnlistedByDays = await db.prepare(
378+
const listedVsUnlistedByDays = await admin.resource('aparts').dataConnector.client.prepare(
371379
`SELECT
372380
strftime('%Y-%m-%d', created_at) as day,
373381
SUM(listed) as listed,
@@ -381,7 +389,7 @@ app.get(`${ADMIN_BASE_URL}/api/dashboard/`,
381389
`
382390
).all(days);
383391

384-
const apartsCountsByRooms = await db.prepare(
392+
const apartsCountsByRooms = await admin.resource('aparts').dataConnector.client.prepare(
385393
`SELECT
386394
number_of_rooms,
387395
COUNT(*) as count
@@ -391,7 +399,7 @@ app.get(`${ADMIN_BASE_URL}/api/dashboard/`,
391399
`
392400
).all();
393401

394-
const topCountries = await db.prepare(
402+
const topCountries = await admin.resource('aparts').dataConnector.client.prepare(
395403
`SELECT
396404
country,
397405
COUNT(*) as count
@@ -402,14 +410,14 @@ app.get(`${ADMIN_BASE_URL}/api/dashboard/`,
402410
`
403411
).all();
404412

405-
const totalSquare = await db.prepare(
413+
const totalSquare = await admin.resource('aparts').dataConnector.client.prepare(
406414
`SELECT
407415
SUM(square_meter) as totalSquare
408416
FROM apartments;
409417
`
410418
).get();
411419

412-
const listedVsUnlistedPriceByDays = await db.prepare(
420+
const listedVsUnlistedPriceByDays = await admin.resource('aparts').dataConnector.client.prepare(
413421
`SELECT
414422
strftime('%Y-%m-%d', created_at) as day,
415423
SUM(listed * price) as listedPrice,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "apartments" ADD COLUMN "apartment_source" TEXT;

dev-demo/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ model apartments {
3434
realtor_id String?
3535
user_id String?
3636
apartment_image String?
37+
apartment_source String?
3738
}
3839

3940
model audit_log {

0 commit comments

Comments
 (0)