11const { sanitize } = require ( "../utils/input.validation" ) ;
22const mongoose = require ( 'mongoose' ) ;
33const Project = require ( "../models/Project" ) ;
4- const { getConnection } = require ( "../utils/connectionManager " ) ;
4+ const { getConnection } = require ( "../utils/connection.manager " ) ;
55const { getCompiledModel } = require ( "../utils/injectModel" ) ;
66
77// Helper: CodeQL ko satisfy karne ke liye ID validate karna zaroori hai
@@ -42,19 +42,19 @@ module.exports.insertData = async (req, res) => {
4242 const safeData = sanitize ( cleanData ) ;
4343
4444 let docSize = 0 ;
45- if ( ! project . isExternal ) {
45+ if ( ! project . resources . db . isExternal ) {
4646 docSize = Buffer . byteLength ( JSON . stringify ( safeData ) ) ;
4747 if ( ( project . databaseUsed || 0 ) + docSize > project . databaseLimit ) {
4848 return res . status ( 403 ) . json ( { error : "Database limit exceeded." } ) ;
4949 }
5050 }
5151
5252 const connection = await getConnection ( project . _id ) ;
53- const Model = getCompiledModel ( connection , collectionConfig , project . _id , project . isExternal ) ;
53+ const Model = getCompiledModel ( connection , collectionConfig , project . _id , project . resources . db . isExternal ) ;
5454
5555 const result = await Model . create ( safeData ) ;
5656
57- if ( ! project . isExternal ) {
57+ if ( ! project . resources . db . isExternal ) {
5858 project . databaseUsed = ( project . databaseUsed || 0 ) + docSize ;
5959 await project . save ( ) ;
6060 }
@@ -75,7 +75,7 @@ module.exports.getAllData = async (req, res) => {
7575 if ( ! collectionConfig ) return res . status ( 404 ) . json ( { error : "Collection not found" } ) ;
7676
7777 const connection = await getConnection ( project . _id ) ;
78- const Model = getCompiledModel ( connection , collectionConfig , project . _id , project . isExternal ) ;
78+ const Model = getCompiledModel ( connection , collectionConfig , project . _id , project . resources . db . isExternal ) ;
7979
8080 const data = await Model . find ( { } ) . limit ( 100 ) . lean ( ) ;
8181 res . json ( data ) ;
@@ -97,7 +97,7 @@ module.exports.getSingleDoc = async (req, res) => {
9797 if ( ! collectionConfig ) return res . status ( 404 ) . json ( { error : "Collection not found" } ) ;
9898
9999 const connection = await getConnection ( project . _id ) ;
100- const Model = getCompiledModel ( connection , collectionConfig , project . _id , project . isExternal ) ;
100+ const Model = getCompiledModel ( connection , collectionConfig , project . _id , project . resources . db . isExternal ) ;
101101
102102 const doc = await Model . findById ( id ) . lean ( ) ;
103103 if ( ! doc ) return res . status ( 404 ) . json ( { error : "Document not found." } ) ;
@@ -121,7 +121,7 @@ module.exports.updateSingleData = async (req, res) => {
121121 if ( ! collectionConfig ) return res . status ( 404 ) . json ( { error : "Collection not found" } ) ;
122122
123123 const connection = await getConnection ( project . _id ) ;
124- const Model = getCompiledModel ( connection , collectionConfig , project . _id , project . isExternal ) ;
124+ const Model = getCompiledModel ( connection , collectionConfig , project . _id , project . resources . db . isExternal ) ;
125125
126126 // Strict Schema Validation
127127 const schemaRules = collectionConfig . model ;
@@ -161,19 +161,19 @@ module.exports.deleteSingleDoc = async (req, res) => {
161161 if ( ! collectionConfig ) return res . status ( 404 ) . json ( { error : "Collection not found" } ) ;
162162
163163 const connection = await getConnection ( project . _id ) ;
164- const Model = getCompiledModel ( connection , collectionConfig , project . _id , project . isExternal ) ;
164+ const Model = getCompiledModel ( connection , collectionConfig , project . _id , project . resources . db . isExternal ) ;
165165
166166 const docToDelete = await Model . findById ( id ) ;
167167 if ( ! docToDelete ) return res . status ( 404 ) . json ( { error : "Document not found." } ) ;
168168
169169 let docSize = 0 ;
170- if ( ! project . isExternal ) {
170+ if ( ! project . resources . db . isExternal ) {
171171 docSize = Buffer . byteLength ( JSON . stringify ( docToDelete ) ) ;
172172 }
173173
174174 await Model . deleteOne ( { _id : id } ) ;
175175
176- if ( ! project . isExternal ) {
176+ if ( ! project . resources . db . isExternal ) {
177177 project . databaseUsed = Math . max ( 0 , ( project . databaseUsed || 0 ) - docSize ) ;
178178 await project . save ( ) ;
179179 }
0 commit comments