All files / src/config app.config.ts

94.11% Statements 16/17
50% Branches 1/2
100% Functions 2/2
94.11% Lines 16/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56  7x 7x 7x 7x 7x 7x   7x                                             7x   352x     5x 5x 5x     5x 5x 5x   7x                    
import { config } from 'dotenv';
config();
 
// Configs
const appConfig = {
  apiURI: '/api/$v',
  requireVerifyEmail: true,
  updatePasswordRequireVerification: true,
  deleteProfileRequireVerification: true,
  supportEmail: 'support@doctime.com',
  apiVersion: '1.0.0',
  apiName: 'DocTime API',
  appName: 'DocTime',
  jwt: {
    secret: process.env.JWT_SECRET_KEY!,
    refreshSecretKey: process.env.REFRESH_SECRET_KEY!,
    expiresIn: '15d',
  },
  logRootPath: '.logs',
  mfa: {
    otp: {
      expirationPeriod: '5m',
      digits: 6,
      throttle: '1m',
    },
  },
};
 
export default appConfig;
 
export function parseAPIVersion(version: number) {
  return appConfig.apiURI.replace('$v', `v${version}`);
}
 
export function parseStrPeriod(timePeriod: string) {
  const regex = /^(\d+)(ms|s|m|h|d)$/;
  const match = timePeriod.match(regex);
 
  ifI (!match) {
    throw new Error('Invalid time period format');
  }
 
  const value = parseInt(match[1], 10);
  const unit = match[2] as TimeUnit;
 
  return { value, unit };
}
 
export const TimeMap: Record<TimeUnit, string> = {
  ms: 'milliseconds',
  s: 'seconds',
  m: 'minutes',
  h: 'hours',
  d: 'days',
};