Loading .env +1 −4 Original line number Diff line number Diff line Loading @@ -5,8 +5,5 @@ DB_PASSWORD=xoxo2002! DB_HOST=localhost DB_PORT=5432 # Connect to Supabase via connection pooling with Supavisor. DATABASE_URL="postgresql://postgres.wrwwvdgppriodcdoyohp:Xoxo2002!qwe@aws-0-eu-central-1.pooler.supabase.com:6543/postgres?pgbouncer=true" DATABASE_URL="postgresql://postgres:xoxo2002!@localhost:5432/Shelf_note" # Direct connection to the database. Used for migrations. DIRECT_URL="postgresql://postgres.wrwwvdgppriodcdoyohp:Xoxo2002!qwe@aws-0-eu-central-1.pooler.supabase.com:5432/postgres" No newline at end of file controllers/homeController.js +16 −1 Original line number Diff line number Diff line import HomeService from "../services/homeService.js"; import HomeService from '../services/homeService.js'; class HomeController { async getEntities() { Loading @@ -9,6 +9,14 @@ class HomeController { return error; } } async getHomeBackgroundUrl() { try { return await HomeService.getHomeBackgroundUrl(); } catch (error) { console.log(error); return error; } } async createEntity(req) { try { return await HomeService.createEntity(req.body); Loading Loading @@ -37,6 +45,13 @@ class HomeController { console.log(error); } } async changeHomeBackgroundUrl(req) { try { return await HomeService.changeHomeBackgroundUrl(req.body); } catch (error) { console.log(error); } } } export default new HomeController(); index.js +22 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,17 @@ wss.on('connection', (ws) => { ); }); break; case 'getHomeBackgroundUrl': const homeBackgroundUrl = await HomeController.getHomeBackgroundUrl(); wss.clients.forEach((client) => { client.send( JSON.stringify({ event: 'getHomeBackgroundUrl', data: homeBackgroundUrl }) ); }); break; case 'createHomeEntity': const createdHomeEntity = await HomeController.createEntity(req); wss.clients.forEach((client) => { Loading Loading @@ -74,6 +85,17 @@ wss.on('connection', (ws) => { ); }); break; case 'changeHomeBackgroundUrl': await HomeController.changeHomeBackgroundUrl(req); wss.clients.forEach((client) => { client.send( JSON.stringify({ event: 'changeHomeBackgroundUrl', data: { ...req.body } }) ); }); break; } }); }); prisma/schema.prisma +10 −2 Original line number Diff line number Diff line Loading @@ -12,7 +12,6 @@ generator client { datasource db { provider = "postgresql" url = env("DATABASE_URL") directUrl = env("DIRECT_URL") } model User { Loading @@ -35,10 +34,19 @@ model Home_entity { entity_type String title String? text String? @db.Text image_data String? @db.Text text_size String? paragraph_size String? text_position String? image_url String? @db.Text image_width Int? image_height Int? image_position String? image_scale String? table_columns Json? table_data Json? } model Setting { setting_name String @unique setting_value String } services/homeService.js +23 −5 Original line number Diff line number Diff line Loading @@ -8,8 +8,14 @@ class HomeService { orderBy: [{ entity_order: 'asc' }] }); } async getHomeBackgroundUrl() { return prisma.setting.findFirst({ where: { setting_name: 'homeBackgroundUrl' } }); } async createEntity(body) { console.log('body: ', body); return prisma.home_entity.create({ data: body }); } async editEntity(body) { Loading Loading @@ -38,12 +44,10 @@ class HomeService { orderBy: [{ entity_order: 'asc' }] }); const currentEntity = allEntities.find((entity) => entity.entity_uuid === body.entity_uuid); console.log('currentEntity: ', currentEntity); const nextEntity = body.direction === 'up' ? allEntities.reverse().find((entity) => entity.entity_order < currentEntity.entity_order) : allEntities.find((entity) => entity.entity_order > currentEntity.entity_order); console.log('nextEntity: ', nextEntity); await prisma.home_entity.update({ where: { entity_uuid: currentEntity.entity_uuid Loading @@ -52,7 +56,6 @@ class HomeService { entity_order: nextEntity.entity_order } }); // await Home_entity.upsert({...currentEntity, entity_order: nextEntity.entity_order}); await prisma.home_entity.update({ where: { entity_uuid: nextEntity.entity_uuid Loading @@ -61,9 +64,24 @@ class HomeService { entity_order: currentEntity.entity_order } }); // await Home_entity.upsert({...nextEntity, entity_order: currentEntity.entity_order}); return body; } async changeHomeBackgroundUrl(body) { const homeBackgroundUrl = await prisma.setting.findFirst({ where: { setting_name: 'homeBackgroundUrl' } }); if (homeBackgroundUrl) { return prisma.setting.update({ where: { setting_name: 'homeBackgroundUrl' }, data: { ...body } }); } return prisma.setting.create({ data: { ...body } }); } } export default new HomeService(); Loading
.env +1 −4 Original line number Diff line number Diff line Loading @@ -5,8 +5,5 @@ DB_PASSWORD=xoxo2002! DB_HOST=localhost DB_PORT=5432 # Connect to Supabase via connection pooling with Supavisor. DATABASE_URL="postgresql://postgres.wrwwvdgppriodcdoyohp:Xoxo2002!qwe@aws-0-eu-central-1.pooler.supabase.com:6543/postgres?pgbouncer=true" DATABASE_URL="postgresql://postgres:xoxo2002!@localhost:5432/Shelf_note" # Direct connection to the database. Used for migrations. DIRECT_URL="postgresql://postgres.wrwwvdgppriodcdoyohp:Xoxo2002!qwe@aws-0-eu-central-1.pooler.supabase.com:5432/postgres" No newline at end of file
controllers/homeController.js +16 −1 Original line number Diff line number Diff line import HomeService from "../services/homeService.js"; import HomeService from '../services/homeService.js'; class HomeController { async getEntities() { Loading @@ -9,6 +9,14 @@ class HomeController { return error; } } async getHomeBackgroundUrl() { try { return await HomeService.getHomeBackgroundUrl(); } catch (error) { console.log(error); return error; } } async createEntity(req) { try { return await HomeService.createEntity(req.body); Loading Loading @@ -37,6 +45,13 @@ class HomeController { console.log(error); } } async changeHomeBackgroundUrl(req) { try { return await HomeService.changeHomeBackgroundUrl(req.body); } catch (error) { console.log(error); } } } export default new HomeController();
index.js +22 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,17 @@ wss.on('connection', (ws) => { ); }); break; case 'getHomeBackgroundUrl': const homeBackgroundUrl = await HomeController.getHomeBackgroundUrl(); wss.clients.forEach((client) => { client.send( JSON.stringify({ event: 'getHomeBackgroundUrl', data: homeBackgroundUrl }) ); }); break; case 'createHomeEntity': const createdHomeEntity = await HomeController.createEntity(req); wss.clients.forEach((client) => { Loading Loading @@ -74,6 +85,17 @@ wss.on('connection', (ws) => { ); }); break; case 'changeHomeBackgroundUrl': await HomeController.changeHomeBackgroundUrl(req); wss.clients.forEach((client) => { client.send( JSON.stringify({ event: 'changeHomeBackgroundUrl', data: { ...req.body } }) ); }); break; } }); });
prisma/schema.prisma +10 −2 Original line number Diff line number Diff line Loading @@ -12,7 +12,6 @@ generator client { datasource db { provider = "postgresql" url = env("DATABASE_URL") directUrl = env("DIRECT_URL") } model User { Loading @@ -35,10 +34,19 @@ model Home_entity { entity_type String title String? text String? @db.Text image_data String? @db.Text text_size String? paragraph_size String? text_position String? image_url String? @db.Text image_width Int? image_height Int? image_position String? image_scale String? table_columns Json? table_data Json? } model Setting { setting_name String @unique setting_value String }
services/homeService.js +23 −5 Original line number Diff line number Diff line Loading @@ -8,8 +8,14 @@ class HomeService { orderBy: [{ entity_order: 'asc' }] }); } async getHomeBackgroundUrl() { return prisma.setting.findFirst({ where: { setting_name: 'homeBackgroundUrl' } }); } async createEntity(body) { console.log('body: ', body); return prisma.home_entity.create({ data: body }); } async editEntity(body) { Loading Loading @@ -38,12 +44,10 @@ class HomeService { orderBy: [{ entity_order: 'asc' }] }); const currentEntity = allEntities.find((entity) => entity.entity_uuid === body.entity_uuid); console.log('currentEntity: ', currentEntity); const nextEntity = body.direction === 'up' ? allEntities.reverse().find((entity) => entity.entity_order < currentEntity.entity_order) : allEntities.find((entity) => entity.entity_order > currentEntity.entity_order); console.log('nextEntity: ', nextEntity); await prisma.home_entity.update({ where: { entity_uuid: currentEntity.entity_uuid Loading @@ -52,7 +56,6 @@ class HomeService { entity_order: nextEntity.entity_order } }); // await Home_entity.upsert({...currentEntity, entity_order: nextEntity.entity_order}); await prisma.home_entity.update({ where: { entity_uuid: nextEntity.entity_uuid Loading @@ -61,9 +64,24 @@ class HomeService { entity_order: currentEntity.entity_order } }); // await Home_entity.upsert({...nextEntity, entity_order: currentEntity.entity_order}); return body; } async changeHomeBackgroundUrl(body) { const homeBackgroundUrl = await prisma.setting.findFirst({ where: { setting_name: 'homeBackgroundUrl' } }); if (homeBackgroundUrl) { return prisma.setting.update({ where: { setting_name: 'homeBackgroundUrl' }, data: { ...body } }); } return prisma.setting.create({ data: { ...body } }); } } export default new HomeService();