1- import db from "../repository/dashboard-repository" ;
1+ import dashboardRepository from "../repository/dashboard-repository" ;
22import type { ParsedToken } from "../types" ;
33
44//#region query
55const findAll = async ( req : any , res : any , next : any ) => {
66 try {
77 const user : ParsedToken = req . user ;
88 const id = user . userId ;
9- const results = await db . findByUserId ( id ) ;
9+ const results = await dashboardRepository . findByUserId ( id ) ;
1010 res . json ( results ) ;
1111 } catch ( err ) {
1212 next ( err ) ;
@@ -18,7 +18,7 @@ const findById = async (req: any, res: any, next: any) => {
1818 const id = req . params . id ;
1919 const user : ParsedToken = req . user ;
2020 const { data } = req . body ;
21- const result = await db . findByIdWithIncludes ( id ) ;
21+ const result = await dashboardRepository . findByIdWithIncludes ( id ) ;
2222 res . json ( result ) ;
2323 return res . json ( { user, data } ) ;
2424 } catch ( err ) {
@@ -37,7 +37,7 @@ const create = async (req: any, res: any, next: any) => {
3737 ...body ,
3838 } ;
3939 console . log ( chartData ) ;
40- const result = await db . create ( chartData ) ;
40+ const result = await dashboardRepository . create ( chartData ) ;
4141
4242 return res . status ( 201 ) . json ( result ) ;
4343 } catch ( err ) {
@@ -49,7 +49,7 @@ const update = async (req: any, res: any, next: any) => {
4949 try {
5050 const user : ParsedToken = req . user ;
5151 const dashboardId = req . params . id ;
52- const dashboard = await db . findById ( dashboardId ) ;
52+ const dashboard = await dashboardRepository . findById ( dashboardId ) ;
5353 if ( ! dashboard ) {
5454 return res . json ( { message : "Not Found" } ) . status ( 404 ) ;
5555 }
@@ -59,7 +59,7 @@ const update = async (req: any, res: any, next: any) => {
5959 console . log ( "Updating dashboard" , dashboardId ) ;
6060 const dashboardData = req . body ;
6161 console . log ( "Dashboard Data" , dashboardData ) ;
62- const result = await db . update ( dashboardId , dashboardData ) ;
62+ const result = await dashboardRepository . update ( dashboardId , dashboardData ) ;
6363 return res . json ( result ) ;
6464 } catch ( err ) {
6565 next ( err ) ;
@@ -69,14 +69,14 @@ const deleteById = async (req: any, res: any, next: any) => {
6969 try {
7070 const user : ParsedToken = req . user ;
7171 const dashboardId = req . params . id ;
72- const dashboard = await db . findById ( dashboardId ) ;
72+ const dashboard = await dashboardRepository . findById ( dashboardId ) ;
7373 if ( ! dashboard ) {
7474 return res . json ( { message : "Not Found" } ) . status ( 404 ) ;
7575 }
7676 if ( dashboard . userId !== user . userId ) {
7777 return res . json ( { message : "Not Authorized" } ) . status ( 401 ) ;
7878 }
79- const result = await db . deleteById ( dashboardId ) ;
79+ const result = await dashboardRepository . deleteById ( dashboardId ) ;
8080 return res . status ( 204 ) . json ( ) ;
8181 } catch ( err ) {
8282 next ( err ) ;
@@ -146,7 +146,7 @@ const updateSlots = async (req: any, res: any, next: any) => {
146146 try {
147147 const user : ParsedToken = req . user ;
148148 const dashboardId = req . params . id ;
149- const dashboard = await db . findSlots ( dashboardId ) ;
149+ const dashboard = await dashboardRepository . findSlots ( dashboardId ) ;
150150 if ( ! dashboard ) {
151151 return res . json ( { message : "Not Found" } ) . status ( 404 ) ;
152152 }
@@ -167,7 +167,7 @@ const updateSlots = async (req: any, res: any, next: any) => {
167167
168168 console . log ( toCreate , toUpdate ) ;
169169
170- const result = await db . updateSlots ( dashboardId , {
170+ const result = await dashboardRepository . updateSlots ( dashboardId , {
171171 toCreate,
172172 toUpdate,
173173 toDelete,
0 commit comments