import dynamoose from 'dynamoose' ; import { ModelType } from 'dynamoose/dist/General' ; import isRunningInLocalStack from '../utils/isRunningInLocalStack' ; import isRunningLocally from '../utils/isRunningLocally' ; import usersSchema , { User } from './schemas/usersSchema' ; export default ( ) => { if ( isRunningLocally ) { const connectionString = isRunningInLocalStack ? 'http://localstack:4566' : 'http://localhost:4566' ; dynamoose . aws . ddb . local ( connectionString ) ; } const userTable = process . env . USER_TABLE && process . env . USER_TABLE !== '[object Object]' ? process . env . USER_TABLE : 'Users' ; let User ; try { User = dynamoose . model < User > ( userTable , usersSchema , { create : false } ) ; } catch ( error ) { User = dynamoose . model < User > ( userTable ) ; } return { User , dynamoose , } ; } ;