Skip to content

Commit

Permalink
feat(core): ✨ swagger multiple enpoint fix
Browse files Browse the repository at this point in the history
swagger multiple  enpoint fix

Ref: #191
  • Loading branch information
PritamIT2023 committed Oct 28, 2024
1 parent cdc9d3d commit f4c6d44
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 563 deletions.
123 changes: 79 additions & 44 deletions package/database/actions.database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ export const databaseActions = {
* @returns
*/
findAndCountAll: async (database: string, model: string, options?: any, transaction?: any ) => {
WrappidLogger.logFunctionStart("databaseActions.findAndCountAll");
if(databaseProvider && Object.keys(databaseProvider).length > 0){
return await databaseProvider[database].models[model].findAndCountAll(options, transaction);
} else {
WrappidLogger.error("WrappidError: databases not setup successfully.");
throw new Error("WrappidError: databases not setup successfully.");
try{
WrappidLogger.logFunctionStart("databaseActions.findAndCountAll");
if(databaseProvider && Object.keys(databaseProvider).length > 0){
return await databaseProvider[database].models[model].findAndCountAll(options, transaction);
} else {
WrappidLogger.error("WrappidError: databases not setup successfully.");
throw new Error("WrappidError: databases not setup successfully.");
}
} catch (error:any) {
WrappidLogger.error("Error: " + error);
throw error;
}
},

Expand All @@ -31,12 +36,17 @@ export const databaseActions = {
* @returns
*/
findAll: async (database: string, model: string, options?: any, transaction?: any) => {
WrappidLogger.logFunctionStart("databaseActions.findAll");
if(databaseProvider && Object.keys(databaseProvider).length > 0){
return await databaseProvider[database].models[model].findAll(options, transaction);
} else {
WrappidLogger.error("WrappidError: databases not setup successfully.");
throw new Error("WrappidError: databases not setup successfully.");
try{
WrappidLogger.logFunctionStart("databaseActions.findAll");
if(databaseProvider && Object.keys(databaseProvider).length > 0){
return await databaseProvider[database].models[model].findAll(options, transaction);
} else {
WrappidLogger.error("WrappidError: databases not setup successfully.");
throw new Error("WrappidError: databases not setup successfully.");
}
} catch (error:any) {
WrappidLogger.error("Error: " + error);
throw error;
}
},

Expand All @@ -50,12 +60,17 @@ export const databaseActions = {
* @returns
*/
delete: async (database: string, model: string, data: any, transaction?: any) => {
WrappidLogger.logFunctionStart("databaseActions.delete");
if(databaseProvider && Object.keys(databaseProvider).length > 0){
return await databaseProvider[database].models[model].destroy(data, transaction);
} else {
WrappidLogger.error("WrappidError: databases not setup successfully.");
throw new Error("WrappidError: databases not setup successfully.");
try{
WrappidLogger.logFunctionStart("databaseActions.delete");
if(databaseProvider && Object.keys(databaseProvider).length > 0){
return await databaseProvider[database].models[model].destroy(data, transaction);
} else {
WrappidLogger.error("WrappidError: databases not setup successfully.");
throw new Error("WrappidError: databases not setup successfully.");
}
} catch (error:any) {
WrappidLogger.error("Error: " + error);
throw error;
}
},

Expand All @@ -77,13 +92,18 @@ export const databaseActions = {
transaction?: any
) => {
WrappidLogger.logFunctionStart("databaseActions.update");
if(databaseProvider && Object.keys(databaseProvider).length > 0){
return await databaseProvider[database].models[model].update(
data, where, transaction
);
} else {
WrappidLogger.error("WrappidError: databases not setup successfully.");
throw new Error("WrappidError: databases not setup successfully.");
try {
if(databaseProvider && Object.keys(databaseProvider).length > 0){
return await databaseProvider[database].models[model].update(
data, where, transaction
);
} else {
WrappidLogger.error("WrappidError: databases not setup successfully.");
throw new Error("WrappidError: databases not setup successfully.");
}
} catch (error:any) {
WrappidLogger.error("Error: " + error);
throw error;
}
},

Expand All @@ -97,14 +117,19 @@ export const databaseActions = {
* @returns
*/
findOne: async (database: string, model: string, data: any, transaction?: any) => {
WrappidLogger.logFunctionStart("databaseActions.findOne");
if(databaseProvider && Object.keys(databaseProvider).length > 0){
try{
WrappidLogger.logFunctionStart("databaseActions.findOne");
if(databaseProvider && Object.keys(databaseProvider).length > 0){
// console.log("::---", data, "---::");
WrappidLogger.info(`::--- ${data} ---::`);
return await databaseProvider[database].models[model].findOne(data, transaction);
} else {
WrappidLogger.error("WrappidError: databases not setup successfully.");
throw new Error("WrappidError: databases not setup successfully.");
WrappidLogger.info(`::--- ${data} ---::`);
return await databaseProvider[database].models[model].findOne(data, transaction);
} else {
WrappidLogger.error("WrappidError: databases not setup successfully.");
throw new Error("WrappidError: databases not setup successfully.");
}
} catch (error:any) {
WrappidLogger.error("Error: " + error);
throw error;
}
},

Expand All @@ -123,12 +148,17 @@ export const databaseActions = {
data: any,
transaction?: any
) => {
WrappidLogger.logFunctionStart("databaseActions.create");
if(databaseProvider && Object.keys(databaseProvider).length > 0){
return await databaseProvider[database].models[model].create(data, transaction);
} else {
WrappidLogger.error("WrappidError: databases not setup successfully.");
throw new Error("WrappidError: databases not setup successfully.");
try{
WrappidLogger.logFunctionStart("databaseActions.create");
if(databaseProvider && Object.keys(databaseProvider).length > 0){
return await databaseProvider[database].models[model].create(data, transaction);
} else {
WrappidLogger.error("WrappidError: databases not setup successfully.");
throw new Error("WrappidError: databases not setup successfully.");
}
} catch (error:any) {
WrappidLogger.error("Error: " + error);
throw error;
}
},

Expand All @@ -143,12 +173,17 @@ export const databaseActions = {
* @returns
*/
findByPk: async (database: string, model: string, primaryKey: number, options?: any, transaction?: any) => {
WrappidLogger.logFunctionStart("databaseActions.findByPk");
if(databaseProvider && Object.keys(databaseProvider).length > 0){
return await databaseProvider[database].models[model].findByPk(primaryKey, options, transaction);
} else {
WrappidLogger.error("WrappidError: databases not setup successfully.");
throw new Error("WrappidError: databases not setup successfully.");
try{
WrappidLogger.logFunctionStart("databaseActions.findByPk");
if(databaseProvider && Object.keys(databaseProvider).length > 0){
return await databaseProvider[database].models[model].findByPk(primaryKey, options, transaction);
} else {
WrappidLogger.error("WrappidError: databases not setup successfully.");
throw new Error("WrappidError: databases not setup successfully.");
}
} catch (error:any) {
WrappidLogger.error("Error: " + error);
throw error;
}
},
};
6 changes: 3 additions & 3 deletions package/modules/_system/controllers.registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ const AppBuilderControllersRegistry = {
//database
getDatabases: databaseController.getDatabases,
getDatabaseTables: databaseController.getDatabaseTables,
getAttributes: databaseController.getAttributes,
getTableAttributes: databaseController.getTableAttributes,
getBusinessEntityColumns: databaseController.getBusinessEntityColumns,

//business controller
getBusinessEntities: businessController.getBusinessEntities,
getEntityData: businessController.getEntityData,
getEntityCount: businessController.getEntityCount,
getIndividualEntityData: businessController.getIndividualEntityData,
getAllEntityData: businessController.getAllEntityData,
noAuthGetAllEntityData: businessController.noAuthGetAllEntityData,
Expand All @@ -39,7 +39,7 @@ const AppBuilderControllersRegistry = {
masterData: [validation(getMasterData), _systemController.masterData],

getModels: [dataController.getModels],
getDatabaseModels: [dataController.getDatabaseModels],
getModelsData: [dataController.getModelsData],
getDatabaseModelRow: [dataController.getDatabaseModelRow],
postDatabaseModel: [dataController.postDatabaseModel],
putUpdateStatus: [dataController.putUpdateStatus],
Expand Down
4 changes: 4 additions & 0 deletions package/modules/_system/controllers/_system.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export const getVersion = async (req: Request, res: Response) => {
export const getSettingMeta = async (req:Request, res:Response) => {
try{
WrappidLogger.logFunctionStart("getSettingMeta");
/**
* @todo
* Provide settingsmeta based on appID
*/
const {status, ...restData} = await getSettingMetaFunc();
res.status(status).json({
...restData
Expand Down
8 changes: 5 additions & 3 deletions package/modules/_system/controllers/business.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ const getBusinessEntities = async (req: any, res: any) => {
* @param res : res value
* @returns
*/
const getEntityData = async (req: any, res: any) => {
WrappidLogger.logFunctionStart("getEntityData");
const getEntityCount = async (req: any, res: any) => {
WrappidLogger.logFunctionStart("getEntityCount");
const entity = req.params.entity;

console.log(`entity=${entity}`);
Expand Down Expand Up @@ -85,6 +85,8 @@ const getEntityData = async (req: any, res: any) => {
error: error?.message || error,
message: "Something went wrong",
});
} finally {
WrappidLogger.logFunctionEnd("getEntityCount");
}
};

Expand Down Expand Up @@ -218,7 +220,7 @@ const noAuthGetAllEntityData = async (req: any, res: any) => {

export {
getAllEntityData, getBusinessEntities,
getEntityData,
getEntityCount,
getIndividualEntityData, noAuthGetAllEntityData
};

6 changes: 4 additions & 2 deletions package/modules/_system/controllers/data.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,18 @@ export const patchDatabaseModel = async (req: any, res: Response) => {
}
};

export const getDatabaseModels = async (req: Request, res: Response) => {
export const getModelsData = async (req: Request, res: Response) => {
try {
WrappidLogger.logFunctionStart("getDatabaseModels");
WrappidLogger.logFunctionStart("getModelsData");
const result = await getDatabaseModelsFunc(req);
const {status, ...resData} = result;
res.status(status).json(resData);
} catch (error:any) {
// console.log("Error:: " error);
WrappidLogger.error(error);
res.status(500).json({message: error.message});
}finally{
WrappidLogger.logFunctionEnd("getModelsData");
}
};

Expand Down
8 changes: 4 additions & 4 deletions package/modules/_system/controllers/database.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ const getDatabaseTables = (req: any, res: any) => {
* @param res : res value
* @returns
*/
const getAttributes = async (req: any, res: any) => {
const getTableAttributes = async (req: any, res: any) => {
try {
WrappidLogger.logFunctionStart("getAttributes");
WrappidLogger.logFunctionStart("getTableAttributes");
const database = req.params.database;
const table = req.params.table;
// eslint-disable-next-line no-unused-vars
Expand Down Expand Up @@ -124,7 +124,7 @@ const getAttributes = async (req: any, res: any) => {
WrappidLogger.error(error);
res.status(500).json({ message: "Error to fetch attributes" });
} finally {
WrappidLogger.logFunctionEnd("getAttributes");
WrappidLogger.logFunctionEnd("getTableAttributes");
}
};

Expand Down Expand Up @@ -165,4 +165,4 @@ const getBusinessEntityColumns = async (req: any, res: any) => {
}
};

export { getAttributes, getBusinessEntityColumns, getDatabaseTables };
export { getTableAttributes, getBusinessEntityColumns, getDatabaseTables };
Loading

0 comments on commit f4c6d44

Please sign in to comment.