/* eslint-disable import/no-unresolved */ // import AWS from 'aws-sdk'; // import { Core_GetSecret_1_0_0 } from '../../../Core/GetSecret/1.0.0'; import { camelCaseResponse } from '../../../CoreHelpers/camelCaseResponse' import { createLog } from '../../../CoreHelpers/logging' import { DB } from '../../../CoreHelpers/types' import validateJWT, { validateXyriiJWT } from '../../../CoreHelpers/validation' import { Response, Body } from './types' import validateBody from './helpers/validation' export async function FunctionName(body: Body, db: DB): Promise { try { // const { prisma, pool } = db // eslint-disable-next-line no-console console.log('body', body) if (!body) throw new Error('No Body') createLog({ shortDescription: 'SERVICE.FunctionName called', body, log: {}, namespace: 'SERVICE', }) validateJWT(body) validateXyriiJWT(body) validateBody(body) // const something = await db.prisma.table_name.findMany({}) // Rules: // // 1. Everything goes into this try catch // // 2. Validate body first // // 3. All functions are put into the helper.ts file // // 4. Helper function throw new Error('response') // // 5. All errors are caught in the catch // const validateBody = validateBody(body) // Open connection to database // SELECT calls: // // Get all the data from database that we need // // Helper functions based on retrieved data // INSERT UPDATE calls: // // Manipulate data // // Insert into database // Other functionality // const MyAwesomeSecret = await Core_GetSecret_1_0_0('SecretName') return camelCaseResponse({ success: true, }) // eslint-disable-next-line no-unreachable } catch (err) { console.error(err) createLog({ shortDescription: 'Error in SERVICE.FunctionName', log: { error: err.message }, type: 'EndpointError', namespace: 'SERVICE', body, }) return { success: false, error: 'Fatal error in SERVICE.FunctionName. Investigate.', message: err.message, } } }